Repository navigation
fix: refuse an assertion whose decryption overflows the stack - #20
Merged
marevol merged 1 commit intoNov 16, 2026
Conversation
The plaintext of an EncryptedAssertion is put into the DOM by the XML security library when the element is decrypted, and anyone can encrypt for the certificate of a service provider. parseXML limits the nesting depth of what it parses, so a plaintext nested more than 100 levels deep is refused when the decrypted assertion is read back. A plaintext nested far deeper overflowed the stack inside the decryption itself, and the StackOverflowError left the library through catch (Exception). Catch StackOverflowError next to Exception in decryptElement and decryptUsingHsm. The element stays encrypted, and the response is refused like any other whose decryption failed.
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 #19 (the base is that branch; retarget to
mainonce #19 is merged).Summary
#18 limits the nesting depth of every document
Util.parseXMLreads. The plaintext of anEncryptedAssertionis a second way into the DOM: the XML security library puts it there when the element is decrypted, and anyone can encrypt for the certificate of a service provider.parseXMLinSamlResponse#decryptAssertion. This pull request adds the missing test for that.parseXMLcan look at it, and theStackOverflowErrorleft the library throughcatch (Exception).Util.decryptElementandUtil.decryptUsingHsmnow catchStackOverflowErrornext toException. The element stays encrypted, and the response is refused like any other whose decryption failed (ValidationException: noAssertionelement found).Catching an
Erroris deliberate and limited to this one call. The depth cannot be known before the decryption, because it is the decrypted text that is deep.Not covered: the
EncryptedIDof an assertion and of aLogoutRequestis decrypted through the same two methods, so it gets the catch, but its plaintext is not read back throughparseXML. A plaintext nested deep enough to be unwanted but not deep enough to overflow the decryption is therefore not limited there. That was not tested.Test
AuthnResponseTest#testEncryptedAssertionNestedTooDeeplyIsRefused: a helper encrypts an assertion for the service provider certificate. At depth 50 the response is accepted (control), at 300 the constructor throwsXMLParsingException, and at 50,000 it throws aSAMLExceptioninstead of overflowing the stack. Without the catch the last case fails withStackOverflowError.coremodule's 431 tests and thetoolkitmodule's 93 tests pass.