Skip to content

authn: refuse repeated keys and invalid UTF-8 when decoding tokens #594

Backlog

Description

@jhrozek

Why. Validator decodes the payload with encoding/json (through golang-jwt), so a repeated member is accepted
and the last value wins. WithStrictDecoding only covers base64 padding. TrustSet.Verify also decodes the
unverified payload to read iss for routing (authn/trustset.go), again last-wins. The protected header is decoded
the same way. encoding/json also replaces invalid UTF-8 with U+FFFD instead of refusing it.

Two parsers that read different values from the same signed bytes are a risk. Consumers that classify a caller from
the shape of its claims, or that today refuse repeated keys, can't move onto authn until it does the same.

Reproduce: sign a token whose payload has "sub":"a" and then "sub":"b". Validate accepts it with
Subject == "b".

What. Refuse, with ReasonMalformed, a token whose header or payload repeats a member name at any depth, or
contains invalid UTF-8. Decode once for routing and for verification, or decode both the same strict way. This is
the default, with no option: a signed token with repeated keys is never legitimate.

Done when. Tests cover a repeated top-level key, a repeated nested key, a repeated header member, a repeated
iss through TrustSet.Verify, and a raw invalid UTF-8 byte in a string claim.

Activity

  1. added
    needs-triage
    on Dec 2, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    needs-triage

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions