Repository navigation
fix: refuse a document whose elements are nested too deeply - #18
Merged
marevol merged 1 commit intoNov 16, 2026
Merged
Conversation
A SAML message is parsed before its signature or schema is checked, and the DOM is then walked recursively (Element#normalize in the Response and LogoutRequest constructors, importNode, the canonicalization of a signature). A document nested thousands of levels deep fits in a short deflated request, and it ended in a StackOverflowError that catch (Exception) does not see, so it left the library. Util.parseXML now walks the parsed tree without recursion and throws XMLParsingException for a document nested more than 100 levels deep. A SAML message is a few dozen levels deep at most. loadXML answers such a document with null, as it does for any other document it cannot parse.
This was referenced Nov 15, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Stacked on #17 (the base is that branch; retarget to
mainonce #17 is merged).Summary
A SAML message is parsed before its signature or its schema is checked, and the DOM is then walked recursively:
Element#normalizein theSamlResponseandLogoutRequestconstructors,importNode, and the canonicalization of a signature. The JDK parser has no depth limit by default, and a document nested thousands of levels deep fits in a short deflated request, so the walk ended in aStackOverflowError.catch (Exception)does not see anError, so it left the library.Util.parseXMLnow walks the parsed tree without recursion and throwsXMLParsingExceptionfor a document nested more than 100 levels deep. A SAML message is a few dozen levels deep at most.Util.loadXMLanswers such a document withnull, as it does for any other document it cannot parse. The check is done on the parsed tree rather than through a parser property, so it does not depend on which XML parser the application puts on the class path.Test
UtilsTest#testLoadXMLRefusesDeeplyNestedElements: depth 100 is accepted, 101 and 50,000 are refused, and 5,000 siblings are not counted as nesting.UtilsTest#testParseXMLReportsDeeplyNestedElements: the refusal is anXMLParsingException.LogoutRequestTest#testDeeplyNestedRequestIsRefusedWithoutAnError: a deflated request under 1,000 characters with 20,000 nested elements no longer overflows the stack; the request is invalid. Without the change this test fails withStackOverflowError.coremodule's 428 tests pass.