Skip to content

Commit

Permalink
openvidu-server: mandatory alphanumeric recording names
Browse files Browse the repository at this point in the history
  • Loading branch information
pabloFuente committed Sep 3, 2020
1 parent 5da1a82 commit ec03629
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
Expand Up @@ -144,7 +144,7 @@ public ResponseEntity<?> getSessionId(@RequestBody(required = false) Map<?, ?> p
if (customSessionId != null && !customSessionId.isEmpty()) {
if (!sessionManager.formatChecker.isValidCustomSessionId(customSessionId)) {
return this.generateErrorResponse(
"Parameter \"customSessionId\" is wrong. Must be an alphanumeric string",
"Parameter 'customSessionId' is wrong. Must be an alphanumeric string [a-zA-Z0-9_-]",
"/api/sessions", HttpStatus.BAD_REQUEST);
}
builder = builder.customSessionId(customSessionId);
Expand Down Expand Up @@ -485,28 +485,36 @@ public ResponseEntity<?> startRecordingSession(@RequestBody Map<?, ?> params) {
HttpStatus.BAD_REQUEST);
}

if (name != null && !name.isEmpty()) {
if (!sessionManager.formatChecker.isValidRecordingName(name)) {
return this.generateErrorResponse(
"Parameter 'name' is wrong. Must be an alphanumeric string [a-zA-Z0-9_-]", "/api/sessions",
HttpStatus.BAD_REQUEST);
}
}

OutputMode finalOutputMode = OutputMode.COMPOSED;
RecordingLayout recordingLayout = null;
if (outputModeString != null && !outputModeString.isEmpty()) {
try {
finalOutputMode = OutputMode.valueOf(outputModeString);
} catch (Exception e) {
return this.generateErrorResponse("Type error in some parameter", "/api/recordings/start",
return this.generateErrorResponse("Type error in parameter 'outputMode'", "/api/recordings/start",
HttpStatus.BAD_REQUEST);
}
}
if (RecordingUtils.IS_COMPOSED(finalOutputMode)) {
if (resolution != null && !sessionManager.formatChecker.isAcceptableRecordingResolution(resolution)) {
return this.generateErrorResponse(
"Wrong \"resolution\" parameter. Acceptable values from 100 to 1999 for both width and height",
"Wrong 'resolution' parameter. Acceptable values from 100 to 1999 for both width and height",
"/api/recordings/start", HttpStatus.UNPROCESSABLE_ENTITY);
}
if (recordingLayoutString != null && !recordingLayoutString.isEmpty()) {
try {
recordingLayout = RecordingLayout.valueOf(recordingLayoutString);
} catch (Exception e) {
return this.generateErrorResponse("Type error in some parameter", "/api/recordings/start",
HttpStatus.BAD_REQUEST);
return this.generateErrorResponse("Type error in parameter 'recordingLayout'",
"/api/recordings/start", HttpStatus.BAD_REQUEST);
}
}
}
Expand Down
Expand Up @@ -30,8 +30,15 @@ public boolean isServerMetadataFormatCorrect(String metadata) {
}

public boolean isValidCustomSessionId(String customSessionId) {
// Alphanumeric string
return customSessionId.matches("[a-zA-Z0-9_-]+");
return isValidAlphanumeric(customSessionId);
}

public boolean isValidRecordingName(String recodingName) {
return isValidAlphanumeric(recodingName);
}

private boolean isValidAlphanumeric(String str) {
return str.matches("[a-zA-Z0-9_-]+");
}

}

0 comments on commit ec03629

Please sign in to comment.