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

[hcaaOlXR] Protect from Billion Laughs #205

Merged
merged 1 commit into from
Oct 5, 2022
Merged

[hcaaOlXR] Protect from Billion Laughs #205

merged 1 commit into from
Oct 5, 2022

Conversation

AzuObs
Copy link
Contributor

@AzuObs AzuObs commented Oct 5, 2022

Protects fully against XXE and Billion Laugh attacks by following the following recommendations:

Comment on lines 478 to 479
assertTrue(except instanceof SAXParseException);
assertEquals("DOCTYPE is disallowed when the feature \"http://apache.org/xml/features/disallow-doctype-decl\" set to true.", except.getMessage());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we be surfacing errors in the underlying library?

Copy link
Collaborator

@ncordon ncordon left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, just a small comment, but I'm happy to merge as is

@@ -69,6 +69,7 @@ public class Xml {
private static final XMLInputFactory FACTORY = XMLInputFactory.newFactory();
static {
FACTORY.setProperty(XMLInputFactory.IS_COALESCING, true);
FACTORY.setProperty(XMLInputFactory.SUPPORT_DTD, false);
FACTORY.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a Java expert, but what is the difference between this implementation and what OWASP snippet looks like: xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

also , what about this one:
// This causes XMLStreamException to be thrown if external DTDs are accessed. xmlInputFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");.
I guess it is not needed , because right above we set SUPPORT_DTD to false?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not a Java expert, but what is the difference between this implementation and what OWASP snippet looks like: xmlInputFactory.setProperty("javax.xml.stream.isSupportingExternalEntities", false);

FACTORY.setProperty(XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES, false); is the same as the line above. It's just using the Enum object rather than writing it out as a String.

also , what about this one:
// This causes XMLStreamException to be thrown if external DTDs are accessed.
xmlInputFactory.setProperty(XMLConstants.ACCESS_EXTERNAL_DTD, "");.
I guess it is not needed , because right above we set SUPPORT_DTD to false?

I think the OWASP article was for an older version of Java perhaps, where the StAX parser returned was using this configuration. The default parser Java is giving us does not use the setting.

The setting is not entirely needed however as it simply throws an exception whenever the parser encounters a <!DOCTYPE>. Currently what our implementation is doing is that it simply ignores the <!DOCTYPE> and will throw an error if it encounters an unknown entity (eg one that was declared the in DOCTYPE)

This is not a bad thing really as it makes my change a bit more backwards compatible while still being safe.

It's also perfectly aligned with the LeftShift (eg competitor to Snyk and Veracode) recommendation which is to implement exactly what I've done. It's mostly aligned with the OWASP article but only because I suspect the OWASP article is quite old and doesn't fully work anymore.

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for looking into this!! Let's merge :)

@AzuObs AzuObs merged commit cde5341 into dev Oct 5, 2022
@AzuObs AzuObs deleted the dev_xxe branch October 5, 2022 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.1 bug Something isn't working team-cypher-surface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants