openvidu-server: limit OPENVIDU_SECRET format to [a-zA-Z0-9_-]

pull/553/head
pabloFuente 2020-10-17 20:22:51 +02:00
parent 4a7a2808b6
commit 99cd6d2f9c
1 changed files with 13 additions and 1 deletions

View File

@ -483,7 +483,8 @@ public class OpenviduConfig {
coturnRedisConnectTimeout = getValue("COTURN_REDIS_CONNECT_TIMEOUT"); coturnRedisConnectTimeout = getValue("COTURN_REDIS_CONNECT_TIMEOUT");
openviduSecret = asNonEmptyString("OPENVIDU_SECRET"); openviduSecret = asNonEmptyAlphanumericString("OPENVIDU_SECRET",
"Cannot be empty and must contain only alphanumeric characters [a-zA-Z0-9], hypens (\"-\") and underscores (\"_\")");
openviduCdr = asBoolean("OPENVIDU_CDR"); openviduCdr = asBoolean("OPENVIDU_CDR");
openviduCdrPath = openviduCdr ? asWritableFileSystemPath("OPENVIDU_CDR_PATH") openviduCdrPath = openviduCdr ? asWritableFileSystemPath("OPENVIDU_CDR_PATH")
@ -741,6 +742,17 @@ public class OpenviduConfig {
} }
} }
protected String asNonEmptyAlphanumericString(String property, String errorMessage) {
final String REGEX = "^[a-zA-Z0-9_-]+$";
String stringValue = getValue(property);
if (stringValue != null && !stringValue.isEmpty() && stringValue.matches(REGEX)) {
return stringValue;
} else {
addError(property, errorMessage);
return null;
}
}
protected String asOptionalString(String property) { protected String asOptionalString(String property) {
return getValue(property); return getValue(property);
} }