Skip to content

oidc: verify signature before parsing token#465

Merged
ericchiang merged 1 commit intocoreos:v2from
ericchiang:validate-before-parse
Aug 2, 2025
Merged

oidc: verify signature before parsing token#465
ericchiang merged 1 commit intocoreos:v2from
ericchiang:validate-before-parse

Conversation

@ericchiang
Copy link
Copy Markdown
Collaborator

This change updates the verification logic of this library to always verify the signature of the token before validating the payload. See associated issue.

#464

This change updates the verification logic of this library to always
verify the signature of the token before validating the payload. See
associated issue.

coreos#464
@ericchiang ericchiang force-pushed the validate-before-parse branch from 4236a71 to a4308ca Compare August 2, 2025 16:30
@ericchiang ericchiang merged commit 752fcad into coreos:v2 Aug 2, 2025
2 checks passed
@ericchiang ericchiang deleted the validate-before-parse branch August 2, 2025 16:31
Comment thread verify.go
return nil, fmt.Errorf("oidc: id token signed with unsupported algorithm, expected %q got %q", supportedSigAlgs, sig.Header.Algorithm)
}

payload, err := v.keySet.VerifySignature(ctx, rawIDToken)
Copy link
Copy Markdown

@liggitt liggitt Jan 13, 2026

Choose a reason for hiding this comment

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

how did moving this first help the DOS? this still calls:

VerifySignature → jose.ParseSigned → parseSignedCompact

which still calls parts := strings.Split(input, ".")

If this was trying to catch spurious tokens with lots of . characters, something like the count check in https://go.dev/cl/652155 would seem more effective

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Hey! The v3 version of this package depends on a go-jose version that doesn't do that.

github.com/go-jose/go-jose/v4 v4.1.3

https://github.com/go-jose/go-jose/blob/v4.1.3/jws.go#L367

For v2, maybe we should do our own check before this to throw out invalid ID tokens early

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

For v2, maybe we should do our own check before this to throw out invalid ID tokens early

Yeah, that's exactly what I'd recommend

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

(also, sorry for the random 6-month-later drive-by ... I just got here while reviewing kubernetes/kubernetes#136162 (comment))

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Lol, no worries. Appreciate you actually checking my work.

Sent the change and tagged a release:

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.

2 participants