Skip to content

Reject JWS with an unprotected critical b64 header#210

Merged
mcpherrinm merged 5 commits intomainfrom
mattm-disallow-unprotected-b64
Oct 3, 2025
Merged

Reject JWS with an unprotected critical b64 header#210
mcpherrinm merged 5 commits intomainfrom
mattm-disallow-unprotected-b64

Conversation

@mcpherrinm
Copy link
Copy Markdown
Collaborator

@mcpherrinm mcpherrinm commented Oct 2, 2025

The only critical header that go-jose supports is b64 from RFC7797.

go-jose correctly only respects that header if it appears in a protected header. go-jose correctly rejects unknown critical headers.

However, go-jose does not reject a JWS which contains a critical b64 unprotected header.

I don't believe this has any security impact, as the only place this is exposed is via the Signature header members which expose unprotected headers, and so a library user is already aware they are not to be trusted. The 'critical' behavior (of not base64-encoding the value, defined in RFC7797) is not influenced here.

Return a new ErrUnsupportedCriticalHeader error exported as a constant.

Reported by: Muhammad Noman Ilyas @AL-Cybision

The only critical header that go-jose supports is b64 from RFC7797.

go-jose correctly only respects that header if it appears in a protected
header. go-jose correctly rejects unknown critical headers.

However, go-jose does not reject a JWS which contains a critical b64
unprotected header.

I don't believe this has any security impact, as the only place this is exposed
is via the Signature header members which expose unprotected headers, and so a
library user is already aware they are not to be trusted. The 'critical'
behavior (of not base64-encoding the value, defined in RFC7797) is not
influenced here.
@mcpherrinm mcpherrinm requested a review from jsha October 2, 2025 21:05
@mcpherrinm mcpherrinm marked this pull request as ready for review October 2, 2025 21:11
@mcpherrinm mcpherrinm requested a review from Copilot October 2, 2025 21:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR improves security validation for JSON Web Signature (JWS) by rejecting JWS tokens that contain critical headers in unprotected headers, specifically addressing the case where the critical b64 header appears in an unprotected context.

Key changes:

  • Adds validation to reject critical headers in unprotected headers
  • Refactors critical header validation logic with a new helper method
  • Introduces a new error type for unsupported critical headers

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
shared.go Adds new error constant and helper method for validating critical headers
signing.go Updates signature verification to check critical headers in both protected and unprotected contexts
signing_test.go Adds test case for rejecting JWS with unprotected critical b64 header
crypter.go Refactors encryption validation to use the new critical header validation method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread shared.go
Comment thread shared.go
Comment thread signing.go Outdated
Instead of passing an empty set to checkSupportedCritical, add a dedicated
method for checking there are no critical headers present.
@mcpherrinm mcpherrinm requested a review from jsha October 2, 2025 22:25
Copy link
Copy Markdown
Collaborator

@jsha jsha left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, one formatting nit.

Comment thread signing.go Outdated
Comment thread signing.go Outdated
mcpherrinm and others added 2 commits October 2, 2025 18:31
Co-authored-by: Jacob Hoffman-Andrews <github@hoffman-andrews.com>
Co-authored-by: Jacob Hoffman-Andrews <github@hoffman-andrews.com>
@mcpherrinm mcpherrinm requested a review from jsha October 2, 2025 22:32
@mcpherrinm
Copy link
Copy Markdown
Collaborator Author

Thanks! I'm going to leave this open til tomorrow morning for any extra feedback, at which point I'll merge and cut a new release.

@AL-Cybision
Copy link
Copy Markdown

@mcpherrinm Thanks for the quick response and clear assessment. Your rationale for not treating this as a security issue is reasonable, and I appreciate the follow‑up changes to explicitly reject critical headers in unprotected sections , tightening validation and fixing the bug—this improves robustness and spec compliance.
Best regards,

@mcpherrinm mcpherrinm merged commit 5348b9a into main Oct 3, 2025
8 checks passed
@mcpherrinm mcpherrinm deleted the mattm-disallow-unprotected-b64 branch October 3, 2025 18:59
Comment thread signing.go
Comment thread signing.go
// Protected Header."
err = signature.header.checkNoCritical()
if err != nil {
continue outer
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FYI: this might not be covered. #211

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants