CVE-2024-21664: Parsing JSON serialized payload without protected field can lead to segfault

Published Jan 9, 2024
·
Updated

Summary

Calling jws.Parse with a JSON serialized payload where the signature field is present while protected is absent can lead to a nil pointer dereference.

Details

This seems to also affect other functions that calls Parse internally, like jws.Verify.

My understanding of these functions from the docs is that they are supposed to fail gracefully on invalid input and don't require any prior validation.

Based on the stack trace in the PoC, the issue seems to be that the processing done in jws/message.go:UnmarshalJSON() assumes that if a signature field is present, then a protected field is also present. If this is not the case, then the subsequent call to getB64Value(sig.protected) will dereference sig.protected, which is nil.

PoC

Reproducer:

go package poc

import ( "testing"

"github.com/lestrrat-go/jwx/v2/jws" )

func TestPOC(t testing.T) { , = jws.Parse([]byte({"signature": ""})) }

Result:

$ go test --- FAIL: TestPOC (0.00s) panic: runtime error: invalid memory address or nil pointer dereference [recovered] panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x40 pc=0x5fd618]

goroutine 6 [running]: testing.tRunner.func1.2({0x628800, 0x831030}) /usr/local/go/src/testing/testing.go:1545 +0x238 testing.tRunner.func1() /usr/local/go/src/testing/testing.go:1548 +0x397 panic({0x628800?, 0x831030?}) /usr/local/go/src/runtime/panic.go:914 +0x21f github.com/lestrrat-go/jwx/v2/jws.getB64Value({0x0?, 0x0?}) /home/fredrik/go/pkg/mod/github.com/lestrrat-go/jwx/v2@v2.0.18/jws/jws.go:484 +0x18 github.com/lestrrat-go/jwx/v2/jws.(Message).UnmarshalJSON(0xc0000a2140, {0xc0000ec000, 0x11, 0x200}) /home/fredrik/go/pkg/mod/github.com/lestrrat-go/jwx/v2@v2.0.18/jws/message.go:323 +0x4ad encoding/json.(decodeState).object(0xc0000ea028, {0x64fa60?, 0xc0000a2140?, 0x16?}) /usr/local/go/src/encoding/json/decode.go:604 +0x6cc encoding/json.(decodeState).value(0xc0000ea028, {0x64fa60?, 0xc0000a2140?, 0xc00006e630?}) /usr/local/go/src/encoding/json/decode.go:374 +0x3e encoding/json.(decodeState).unmarshal(0xc0000ea028, {0x64fa60?, 0xc0000a2140?}) /usr/local/go/src/encoding/json/decode.go:181 +0x133 encoding/json.(Decoder).Decode(0xc0000ea000, {0x64fa60, 0xc0000a2140}) /usr/local/go/src/encoding/json/stream.go:73 +0x179 github.com/lestrrat-go/jwx/v2/internal/json.Unmarshal({0xc00001a288, 0x11, 0x11}, {0x64fa60, 0xc0000a2140}) /home/fredrik/go/pkg/mod/github.com/lestrrat-go/jwx/v2@v2.0.18/internal/json/json.go:26 +0x97 github.com/lestrrat-go/jwx/v2/jws.parseJSON({0xc00001a288, 0x11, 0x11}) /home/fredrik/go/pkg/mod/github.com/lestrrat-go/jwx/v2@v2.0.18/jws/jws.go:588 +0x50 github.com/lestrrat-go/jwx/v2/jws.Parse({0xc00001a288, 0x11, 0x11}, {0x0?, 0xc00006e760?, 0x48450f?}) /home/fredrik/go/pkg/mod/github.com/lestrrat-go/jwx/v2@v2.0.18/jws/jws.go:525 +0x89 poc.TestPOC(0x0?) /home/fredrik/src/jwxpoc/poctest.go:10 +0x57 testing.tRunner(0xc0000e4340, 0x68ef30) /usr/local/go/src/testing/testing.go:1595 +0xff created by testing.(T).Run in goroutine 1 /usr/local/go/src/testing/testing.go:1648 +0x3ad exit status 2 FAIL poc 0.005s

Impact

The vulnerability can be used to crash / DOS a system doing JWS verification.

Other sources

jwx is a Go module implementing various JWx (JWA/JWE/JWK/JWS/JWT, otherwise known as JOSE) technologies. Calling jws.Parse with a JSON serialized payload where the signature field is present while protected is absent can lead to a nil pointer dereference. The vulnerability can be used to crash/DOS a system doing JWS verification. This vulnerability has been patched in version 2.0.19.

— NVD

jwx is a Go module implementing various JWx (JWA/JWE/JWK/JWS/JWT, otherwise known as JOSE) technologies. Calling jws.Parse with a JSON serialized payload where the signature field is present while protected is absent can lead to a nil pointer dereference. The vulnerability can be used to crash/DOS a system doing JWS verification. This vulnerability has been patched in versions 2.0.19 and 1.2.28.

— NVD

Affected Software

3 affected componentsFixes available
lestrrat-go jwx<2.0.19
go/github.com/lestrrat-go/jwx>=1.0.8<1.2.28
1.2.28
go/github.com/lestrrat-go/jwx/v2<2.0.19
2.0.19

Remediation

Recommended actions to resolve this vulnerability, in priority order.

  1. Upgrade

    Upgrade go/github.com/lestrrat-go/jwx to a version that resolves this vulnerability.

    Fixed in 1.2.28
  2. Upgrade

    Upgrade go/github.com/lestrrat-go/jwx/v2 to a version that resolves this vulnerability.

    Fixed in 2.0.19
  3. Upgrade

    Upgrade github.com/lestrrat-go/jwx/v2 to a version that resolves this vulnerability.

    Fixed in 2.0.19
  4. Upgrade

    Upgrade github.com/lestrrat-go/jwx/v2 to a version that resolves this vulnerability.

    Fixed in 1.2.28

Event History

Jan 9, 2024
Advisory Published
via GitHub·04:18 PM
CVE Published
via MITRE·07:18 PM
Data Sourced
via MITRE·07:18 PM
DescriptionSeverityWeakness
Data Sourced
via NVD·08:15 PM
RemedyDescriptionSeverityWeaknessAffected Software

Frequently Asked Questions

1

What is the severity of CVE-2024-21664?

CVE-2024-21664 has a severity rating that indicates a potential denial of service vulnerability due to nil pointer dereference.

2

How do I fix CVE-2024-21664?

To remediate CVE-2024-21664, upgrade to lestrrat-go jwx version 2.0.19 or go/github.com/lestrrat-go/jwx version 1.2.28.

3

What products are affected by CVE-2024-21664?

CVE-2024-21664 affects lestrrat-go jwx versions lower than 2.0.19 and go/github.com/lestrrat-go/jwx versions between 1.0.8 and 1.2.28.

4

What might happen if I don’t address CVE-2024-21664?

Failure to address CVE-2024-21664 could lead to application crashes or unexpected behavior when processing certain JSON payloads.

5

Which functions are impacted by CVE-2024-21664?

CVE-2024-21664 primarily affects the jws.Parse function and any functions that internally call Parse, such as jws.Verify.

Contact

SecAlerts Pty Ltd.
132 Wickham Terrace
Fortitude Valley,
QLD 4006, Australia
info@secalerts.co
By using SecAlerts services, you agree to our services end-user license agreement. This website is safeguarded by reCAPTCHA and governed by the Google Privacy Policy and Terms of Service. All names, logos, and brands of products are owned by their respective owners, and any usage of these names, logos, and brands for identification purposes only does not imply endorsement. If you possess any content that requires removal, please get in touch with us.
© 2026 SecAlerts Pty Ltd.
ABN: 70 645 966 203, ACN: 645 966 203