mirror of
https://github.com/github/codeql.git
synced 2025-12-19 02:13:17 +01:00
Merge pull request #4799 from joefarebrother/xxe-fp
Java: Fix false positive in the XXE query
This commit is contained in:
4
java/change-notes/2020-12-09-xxe-fp-fix.md
Normal file
4
java/change-notes/2020-12-09-xxe-fp-fix.md
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
lgtm,codescanning
|
||||||
|
* The query "Resolving XML external entity in user-controlled data" (`java/xxe`) has been improved to report fewer false positives when a `SAXParserFactory` is configured safely.
|
||||||
|
|
||||||
|
|
||||||
@@ -481,6 +481,10 @@ class SAXParserFactoryConfig extends ParserConfig {
|
|||||||
class SafeSAXParserFactory extends VarAccess {
|
class SafeSAXParserFactory extends VarAccess {
|
||||||
SafeSAXParserFactory() {
|
SafeSAXParserFactory() {
|
||||||
exists(Variable v | v = this.getVariable() |
|
exists(Variable v | v = this.getVariable() |
|
||||||
|
exists(SAXParserFactoryConfig config | config.getQualifier() = v.getAnAccess() |
|
||||||
|
config.enables(singleSafeConfig())
|
||||||
|
)
|
||||||
|
or
|
||||||
exists(SAXParserFactoryConfig config | config.getQualifier() = v.getAnAccess() |
|
exists(SAXParserFactoryConfig config | config.getQualifier() = v.getAnAccess() |
|
||||||
config
|
config
|
||||||
.disables(any(ConstantStringExpr s |
|
.disables(any(ConstantStringExpr s |
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import java.net.Socket;
|
|||||||
|
|
||||||
import javax.xml.parsers.SAXParser;
|
import javax.xml.parsers.SAXParser;
|
||||||
import javax.xml.parsers.SAXParserFactory;
|
import javax.xml.parsers.SAXParserFactory;
|
||||||
|
import javax.xml.XMLConstants;
|
||||||
import org.xml.sax.helpers.DefaultHandler;
|
import org.xml.sax.helpers.DefaultHandler;
|
||||||
|
|
||||||
public class SAXParserTests {
|
public class SAXParserTests {
|
||||||
@@ -72,4 +72,12 @@ public class SAXParserTests {
|
|||||||
SAXParser parser = factory.newSAXParser();
|
SAXParser parser = factory.newSAXParser();
|
||||||
parser.parse(sock.getInputStream(), new DefaultHandler()); //unsafe
|
parser.parse(sock.getInputStream(), new DefaultHandler()); //unsafe
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void safeParser2(Socket sock) throws Exception {
|
||||||
|
SAXParserFactory factory = SAXParserFactory.newInstance();
|
||||||
|
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
||||||
|
factory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
||||||
|
SAXParser parser = factory.newSAXParser();
|
||||||
|
parser.parse(sock.getInputStream(), new DefaultHandler()); //safe
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user