Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merge Develop into Release #3348

Merged
merged 1 commit into from
Apr 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions java/lang/security/xmlinputfactory-external-entities-enabled.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
package example;

import javax.xml.stream.XMLInputFactory;
import static javax.xml.stream.XMLInputFactory.SUPPORT_DTD;

class GoodXMLInputFactory {
public GoodXMLInputFactory() {
Expand All @@ -16,10 +17,31 @@ public GoodXMLInputFactory() {
}
}

class GoodXMLInputFactory1 {
public GoodXMLInputFactory1() {
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();

// See
// https://github.com/OWASP/CheatSheetSeries/blob/master/cheatsheets/XML_External_Entity_Prevention_Cheat_Sheet.md#xmlinputfactory-a-stax-parser
// ok:xmlinputfactory-external-entities-enabled
xmlInputFactory.setProperty(SUPPORT_DTD, false);
}
}

class BadXMLInputFactory {
public BadXMLInputFactory() {
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
// ruleid:xmlinputfactory-external-entities-enabled
xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", true);
}
}

class BadXMLInputFactory1 {
public BadXMLInputFactory1() {
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
// ruleid:xmlinputfactory-external-entities-enabled
xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, true);
}
}


Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ rules:
to XML external entity
attacks. Disable external entities by setting "javax.xml.stream.isSupportingExternalEntities"
to false.
pattern: $XMLFACTORY.setProperty("javax.xml.stream.isSupportingExternalEntities", true);
patterns:
- pattern-either:
- pattern: (javax.xml.stream.XMLInputFactory $XMLFACTORY).setProperty("javax.xml.stream.isSupportingExternalEntities", true);
- pattern: (javax.xml.stream.XMLInputFactory $XMLFACTORY).setProperty(javax.xml.stream.XMLInputFactory.SUPPORT_DTD, true);
languages:
- java
20 changes: 14 additions & 6 deletions java/lang/security/xmlinputfactory-possible-xxe.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
package example;

import javax.xml.stream.XMLInputFactory;
import static java.xml.stream.XMLFactoryInput.IS_SUPPORTING_EXTERNAL_ENTITIES;
import static javax.xml.stream.XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES;

class GoodXMLInputFactory {
public void Blah() {
public void blah() {
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();

// See
Expand All @@ -18,7 +18,7 @@ public void Blah() {
}

class GoodConstXMLInputFactory {
public void Blah() {
public GoodConstXMLInputFactory() {
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();

// See
Expand All @@ -29,16 +29,24 @@ public void Blah() {
}
}

class BadXMLInputFactory {
public Blah() {
class BadXMLInputFactory1 {
public BadXMLInputFactory1() {
// ruleid:xmlinputfactory-possible-xxe
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", true);
}
}

class BadXMLInputFactory2 {
public BadXMLInputFactory2() {
// ruleid:xmlinputfactory-possible-xxe
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
xmlInputFactory.setProperty(IS_SUPPORTING_EXTERNAL_ENTITIES, true);
}
}

class MaybeBadXMLInputFactory {
public Blah() {
public void foobar() {
// ruleid:xmlinputfactory-possible-xxe
final XMLInputFactory xmlInputFactory = XMLInputFactory.newFactory();
}
Expand Down
10 changes: 5 additions & 5 deletions java/lang/security/xmlinputfactory-possible-xxe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,19 +34,19 @@ rules:
to false.
patterns:
- pattern-not-inside: |
$RETURNTYPE $METHOD(...) {
$METHOD(...) {
...
$XMLFACTORY.setProperty("javax.xml.stream.isSupportingExternalEntities", false);
...
}
- pattern-not-inside: |
$RETURNTYPE $METHOD(...) {
$METHOD(...) {
...
$XMLFACTORY.setProperty(java.xml.stream.XMLFactoryInput.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
$XMLFACTORY.setProperty(javax.xml.stream.XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);
...
}
- pattern-either:
- pattern: $XMLFACTORY = $W.newFactory(...);
- pattern: $XMLFACTORY = new XMLInputFactory(...);
- pattern: javax.xml.stream.XMLInputFactory.newFactory(...)
- pattern: new XMLInputFactory(...)
languages:
- java
Loading