37 lines
788 B
Plaintext
37 lines
788 B
Plaintext
== How to fix it in SAX
|
|
|
|
=== Code examples
|
|
|
|
include::../../common/fix/code-rationale.adoc[]
|
|
|
|
==== Noncompliant code example
|
|
|
|
[source,java,diff-id=31,diff-type=noncompliant]
|
|
----
|
|
import org.xml.sax.XMLReader;
|
|
import org.xml.sax.helpers.XMLReaderFactory;
|
|
|
|
public void decode() {
|
|
XMLReader reader = XMLReaderFactory.createXMLReader(); // Noncompliant
|
|
}
|
|
----
|
|
|
|
==== Compliant solution
|
|
|
|
Set `disallow-doctype-decl` to `true`.
|
|
|
|
[source,java,diff-id=31,diff-type=compliant]
|
|
----
|
|
import org.xml.sax.XMLReader;
|
|
import org.xml.sax.helpers.XMLReaderFactory;
|
|
|
|
public void decode() {
|
|
XMLReader reader = XMLReaderFactory.createXMLReader();
|
|
reader.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
|
|
}
|
|
----
|
|
|
|
=== How does this work?
|
|
|
|
include::../../common/fix/xxe.adoc[]
|