Skip to content

Support string-list JWT claims such as aud in meta_claims - #114

Merged
ggicci merged 1 commit into
ggicci:mainfrom
steffenbusch:meta-claims-aud-string-list
Jun 30, 2026
Merged

ggicci merged 1 commit into
ggicci:mainfrom
steffenbusch:meta-claims-aud-string-list

Conversation

@steffenbusch

Copy link
Copy Markdown
Contributor

Summary

Fix meta_claims population for JWT claims that are decoded as []string, most notably the registered aud claim.

caddy-jwt currently stringifies array-like metadata only when the claim value is []interface{}. This works for many private claims, but it does not work for registered claims such as aud, because the underlying JWT library decodes them as []string.

As a result, configurations such as:

jwtauth {
    audience_whitelist "aud1"
    meta_claims "aud"
}

successfully validate the audience, but {http.auth.user.aud} remains empty.

Root Cause

The JWT library treats aud as a standard claim and decodes it into a dedicated string-list type, which is exposed to caddy-jwt as []string.

caddy-jwt currently supports:

  • string
  • bool
  • json.Number
  • time.Time
  • []interface{}
  • fmt.Stringer

but not []string.

This causes meta_claims "aud" to resolve to an empty string instead of a comma-separated value.

Changes

  • Add []string support to stringify()
  • Add a regression test proving that meta_claims "aud" is populated correctly
  • Extend the existing stringify() unit test to cover []string

Example

Given a token containing:

{
  "aud": ["aud1", "aud2", "aud3"]
}

and this config:

jwtauth {
    meta_claims "aud"
}

the placeholder {http.auth.user.aud} now resolves to aud1,aud2,aud3.

Backward Compatibility

This is backward-compatible. It only adds support for an additional value type that was previously dropped during stringification.

@ggicci
ggicci merged commit bb37ce2 into ggicci:main Jun 30, 2026
1 check passed
@ggicci

ggicci commented Jun 30, 2026

Copy link
Copy Markdown
Owner

Thank you @steffenbusch for the contribution!

@steffenbusch
steffenbusch deleted the meta-claims-aud-string-list branch July 3, 2026 19:41
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