Summary
gosaml2 can panic while decrypting a malformed encrypted SAML assertion because it does not validate the ciphertext's nonce or initialization-vector length before slicing it. A remote attacker who can submit a response to an affected service provider may trigger a denial of service without a valid identity-provider signature.
Affected context
The issue affects gosaml2 response validation when an encrypted assertion is processed. In affected implementations, ValidateEncodedResponse() attempts decryption before signature or content validation completes, and EncryptedAssertion.DecryptBytes() may slice decoded ciphertext before checking that it contains the required AES-GCM nonce or AES-CBC initialization vector. A panic may terminate the request goroutine or, depending on the service's panic recovery, the process.
Exploit preconditions
- Attack surface: A service-provider endpoint that accepts SAML responses containing encrypted assertions
- Required access: The ability to send a SAML response; a valid identity-provider signature or relationship is not required. The service provider's public certificate is sufficient to wrap a symmetric key.
- Trigger point: Decryption during
ValidateEncodedResponse(), before signature or content validation completes - Why exploitation is possible: Short or empty decoded ciphertext can reach slicing operations without prior nonce or initialization-vector length checks, causing an unrecovered panic
Why this happens
The underlying bug is insufficient validation of decoded ciphertext before cryptographic processing. DecryptBytes() assumes the input contains a complete AES-GCM nonce or AES-CBC initialization vector and slices it without first establishing that the required bytes are present. Invalid input can therefore cause a runtime bounds panic rather than a controlled validation error. This maps to CWE-20: Improper Input Validation; the panic behavior is also related to CWE-248: Uncaught Exception.
Potential impact
- A crafted response may cause a request-handling goroutine to terminate.
- Depending on panic recovery and service architecture, the failure could interrupt or terminate the service process.
- Repeated requests may reduce service availability.
General mitigation guidance
Defensive patterns include validating decoded ciphertext lengths before slicing or invoking cryptographic operations, and returning controlled errors for malformed input. Treat inbound SAML data as untrusted until all relevant checks succeed, and perform structural validation before decryption or other operations that can panic. Use panic recovery as defense in depth rather than as a substitute for input validation, and limit the privileges and resources available to the service.
How teams detect issues like this
- Use static analysis and code review to find byte-slice operations on decoded or attacker-controlled data that lack preceding length checks.
- Review cryptographic parsing paths for validation that occurs only after decryption or other risky operations.
- Add tests and fuzzing for empty and undersized encrypted assertion values, verifying that malformed inputs return errors rather than panic.
- Apply CI policies that flag unchecked input-derived slicing and ensure request handlers have appropriate panic containment.

