Skip to content

Commit ce0ccbc

Browse files
scyt01bobbylight
authored andcommitted
Security Fix: Potential XXE Vulnerability in load function
1 parent 9bdc656 commit ce0ccbc

File tree

1 file changed

+9
-3
lines changed
  • RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea

1 file changed

+9
-3
lines changed

RSyntaxTextArea/src/main/java/org/fife/ui/rsyntaxtextarea/Theme.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -609,9 +609,15 @@ public void fatalError(SAXParseException e) throws SAXException {
609609
throw e;
610610
}
611611

612-
public static void load(Theme theme, InputStream in) throws IOException {
612+
public static void load(Theme theme, InputStream in) throws IOException {
613613
SAXParserFactory spf = SAXParserFactory.newInstance();
614614
spf.setValidating(true);
615+
616+
// Disable external entity resolution to prevent XXE attacks
617+
spf.setFeature("http://xml.org/sax/features/external-general-entities", false);
618+
spf.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
619+
spf.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
620+
615621
try {
616622
SAXParser parser = spf.newSAXParser();
617623
XMLReader reader = parser.getXMLReader();
@@ -624,8 +630,8 @@ public static void load(Theme theme, InputStream in) throws IOException {
624630
InputSource is = new InputSource(in);
625631
is.setEncoding("UTF-8");
626632
reader.parse(is);
627-
} catch (/*SAX|ParserConfiguration*/Exception se) {
628-
throw new IOException(se.toString());
633+
} catch (SAXException | ParserConfigurationException se) {
634+
throw new IOException("Error parsing XML: " + se.getMessage(), se);
629635
}
630636
}
631637

0 commit comments

Comments
 (0)