github.com/golang-jwt/jwt/v5 v5.2.2: Delegated JWT login accepts tokens with no `exp` (a regression), so a login link without an expiry opens a session forever

Open Beginner friendly
#5,370 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
2/5
Estimated time
1-3 hours
Newbie friendliness
65/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
go

Research direction

Start in model/session/delegated.go at CheckDelegatedJWT (lines 42-60) and confirm how pkg/crypto/jwt.go calls jwt.ParseWithClaims without jwt.WithExpirationRequired(). Make the missing-exp case reject alongside the expired case, then add a no-ExpiresAt case to model/session/delegated_test.go that must fail. Update docs/delegated-auth.md to state exp is mandatory and short. Done when the new test passes and the docs say so.

Written by the indexing model from the issue text.

Description

ai-driven-qa bug claude Minor

Severity: Minor — a limited or confusing misbehaviour, of a secondary feature or in an edge case.

  • Severity: medium. A control the code originally enforced (a delegated token must carry an exp in the future) was silently dropped. A token that lacks exp gives a full password-less, 2FA-less session on the instance named in its name claim, with no time limit. There are two preconditions. First, the external portal mints tokens without exp, and the integration guide does not tell it to set one. Second, the attacker gets hold of one such link: it travels in the query string, so it can end up in proxy or access logs, browser history or Referer headers. Tokens cannot be forged, so this is not high.
  • CVSS 3.1: CVSS:3.1/AV:N/AC:H/PR:N/UI:R/S:U/C:H/I:H/A:N — 6.8
  • Found by: claude
  • Where: linagora/cozy-stack model/session/delegated.go:52
  • Introduced by: sha=5741ccdee9dc54776f5b2b036e72aeddce962d5e pr=3177 confidence=likely — "Use github.com/golang-jwt/jwt (#3177)", 2021-11-29. The original code (320c91f6, "Add delegated jwt", 2019-01-30) used jwt-go's StandardClaims and checked if claims.ExpiresAt < time.Now().Unix(). A missing exp decoded to 0 and was rejected, so exp was required in effect. The migration switched to RegisteredClaims, where ExpiresAt is a *NumericDate, and rewrote the check as ExpiresAt != nil && ExpiresAt.Before(time.Now()). That rewrite turned a missing exp from "rejected" into "accepted". The move to v5 (9d2a7564, 2023-10-10) only changed the import, and cozy-stack still passes no jwt.WithExpirationRequired().
  • Weakness: in web/auth/auth.go:262-267, GET /auth/login?jwt=<token> (unauthenticated) calls session.CheckDelegatedJWT(instance, token). On success it calls SetCookieForNewSession(c, session.NormalRun, ""). CheckDelegatedJWT (model/session/delegated.go:42-60) does three things:
    keyFunc := func(token *jwt.Token) (interface{}, error) {
        return base64.StdEncoding.DecodeString(JWTSecret.(string))
    }
    err := crypto.ParseJWT(token, keyFunc, &claims)
    ...
    if claims.RegisteredClaims.ExpiresAt != nil && claims.RegisteredClaims.ExpiresAt.Before(time.Now()) {
        return errors.New("Token has expired")
    }
    if claims.Name != instance.Domain { ... }
    return nil
    
    crypto.ParseJWT calls jwt.ParseWithClaims with no parser options. In the library, Validator.Validate calls v.verifyExpiresAt(claims, now, v.requireExp) (validator.go:105). When the claim is absent, that returns errorIfRequired(required, "exp") (validator.go:174), which is nil because requireExp is false. The project-side check is then skipped too, because ExpiresAt == nil. Nothing else bounds the token: iat is not checked, there is no jti or one-time-use store, and aud/iss are not checked. The only binding is the custom name claim, which must equal the instance domain. The integration guide (docs/delegated-auth.md:21-22) only says to "create a JWT, with the parameter name as the instance domain", so a portal that follows it leaves exp out. The unit tests (model/session/delegated_test.go) only cover tokens with a future or past exp, never a missing one.
    Confirmed by Joern on the library CPG. requireExp is set only at parser_option.go:65 (WithExpirationRequired), and verifyExpiresAt is called only from Validator.Validate (validator.go:105). So without that option, a missing exp is accepted. The cozy-stack half is not in the databases. It was read by hand: ParseJWT at pkg/crypto/jwt.go:22-36, the handler at web/auth/auth.go:262, and the git history above.
  • Impact: anyone holding a delegated login URL whose token has no exp gets a new full session on that user's instance, as many times as they like and for as long as the context's jwt_secret is not rotated. That session covers files, contacts, settings and the flows reachable from a logged-in session, with no password and no 2FA. Even when exp is set, a link can be replayed any number of times within its lifetime. Exposure: every context with authentication.<context>.jwt_secret configured. None of the listed Linagora projects mints these tokens (a search for login?jwt= / jwt_secret across them found only unrelated uses). The issuers are external portals run by the integrator.
  • Remediation: restore the original rule in CheckDelegatedJWT:
    if claims.RegisteredClaims.ExpiresAt == nil || claims.RegisteredClaims.ExpiresAt.Before(time.Now()) {
        return errors.New("Token has expired")
    }
    
    An alternative is to parse with jwt.WithExpirationRequired(), which would mean letting crypto.ParseJWT take ...jwt.ParserOption. As hardening, also cap the lifetime: reject an iat older than a few minutes, or an exp - iat above a few minutes. Make links single-use by requiring a jti and keeping it in the cache until exp. Update docs/delegated-auth.md to say that exp (and iat/jti, if you adopt them) is mandatory and short. Add a delegated_test.go case with no ExpiresAt that must fail. Siblings checked: model/rag/broker.go:128 already requires ExpiresAt != nil. The permission.Claims tokens use their own iat-based Expired() in model/permission/claims.go, so no other site has the same != nil && pattern.

Finding SEV-1 (medium) of the twake-qa deep dependency review of cozy-stack: github.com/golang-jwt/jwt/v5 v5.2.2 (golang-jwt/jwt at v5.2.2); full report: deep-dependency-reviews/20261122-204318-eed494-github-com-golang-jwt-jwt-v5.md.


Found by automated QA (twake-qa, claude -p + deep dependency review) on 0951d184286d, severity: minor, browsers: none, first seen 2026-11-22.

Dominant language
Go
Stars
1.3k
Forks
147
Avg merge
1d 19h
Merged PRs (30d)
146

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from linagora/cozy-stack

All issues in linagora/cozy-stack

Similar issues

More Go issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.