Skip to content

Commit

Permalink
Merge pull request #1205 from kermitt2/alert-autofix-41
Browse files Browse the repository at this point in the history
Fix code scanning alert no. 41: Resolving XML external entity in user-controlled data
  • Loading branch information
lfoppiano authored Dec 19, 2024
2 parents f372f99 + c3008ec commit 09b28cd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -118,8 +118,11 @@ public String descriptionRetrieval(String patentNumber) throws IOException,
spf.setFeature("http://xml.org/sax/features/validation", false);
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
spf.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
//get a new instance of parser
XMLReader reader = spf.newSAXParser().getXMLReader();
reader.setFeature("http://xml.org/sax/features/external-general-entities", false);
reader.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
reader.setEntityResolver(new EntityResolver() {
public InputSource resolveEntity(String publicId, String systemId) {
return new InputSource(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,11 @@ public void run() {
public Response resultTraining(String token) {
Response response = null;
try {
// Validate the token to prevent directory traversal
if (token.contains("..") || token.contains("/") || token.contains("\\")) {
throw new GrobidServiceException("Invalid token", Status.BAD_REQUEST);
}

// access report file under token subdirectory
File home = GrobidProperties.getInstance().getGrobidHomePath();
String tokenPath = home.getAbsolutePath() + "/training-history/" + token;
Expand Down

0 comments on commit 09b28cd

Please sign in to comment.