Merge pull request #19487 from antobinary/ports-05

fix(sec): validate URL for external upload of presentation (port from 2.7)
This commit is contained in:
Anton Georgiev 2024-01-23 10:39:44 -05:00 committed by GitHub
commit 75b57baec7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -14,6 +14,9 @@ import javax.validation.Validation;
import javax.validation.Validator;
import javax.validation.ValidatorFactory;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.*;
@ -76,6 +79,11 @@ public class ValidationService {
if(request == null) {
violations.put("validationError", "Request not recognized");
} else if(params.containsKey("presentationUploadExternalUrl")) {
String urlToValidate = params.get("presentationUploadExternalUrl")[0];
if(!this.isValidURL(urlToValidate)) {
violations.put("validationError", "Param 'presentationUploadExternalUrl' is not a valid URL");
}
} else {
request.populateFromParamsMap(params);
violations = performValidation(request);
@ -84,6 +92,15 @@ public class ValidationService {
return violations;
}
boolean isValidURL(String url) {
try {
new URL(url).toURI();
return true;
} catch (MalformedURLException | URISyntaxException e) {
return false;
}
}
private Request initializeRequest(ApiCall apiCall, Map<String, String[]> params, String queryString) {
Request request = null;
Checksum checksum;