Skip to content

Potential fix for code scanning alert no. 150: Resolving XML external entity in user-controlled data#3

Draft
alvinsmith-eroad wants to merge 1 commit intomasterfrom
alert-autofix-150
Draft

Potential fix for code scanning alert no. 150: Resolving XML external entity in user-controlled data#3
alvinsmith-eroad wants to merge 1 commit intomasterfrom
alert-autofix-150

Conversation

@alvinsmith-eroad
Copy link
Copy Markdown

Potential fix for https://github.com/eroad/keycloak/security/code-scanning/150

To fully mitigate XXE vulnerabilities when parsing untrusted XML with StAX, you must disable both external entity resolution and DTD support. The code already sets XMLInputFactory.IS_SUPPORTING_EXTERNAL_ENTITIES to false, but it does not set XMLInputFactory.SUPPORT_DTD to false. The best fix is to add the following line after the other property settings in the getXMLEventReader method in StaxParserUtil.java:

xmlInputFactory.setProperty(XMLInputFactory.SUPPORT_DTD, Boolean.FALSE);

This ensures that DTDs are not processed at all, closing the XXE vector. No changes to imports or method signatures are required, as XMLInputFactory.SUPPORT_DTD is already available.


Suggested fixes powered by Copilot Autofix. Review carefully before merging.

… entity in user-controlled data

Please excuse this unsolicited pull request. I wanted to share it as Copilot identified what appears to be a fine solution.

However, I defer to the team's judgment. Feel free to either merge or close it.

Co-authored-by: Copilot Autofix powered by AI <62310815+github-advanced-security[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant