JWT::EncodedToken accepts tokens with more than three segments

Chiusa
#779 0 commenti 1 reazione 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Una pull request collegata è già stata integrata.

  • #782 di @anakinj — integrata

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
30/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
ruby

Direzione di ricerca

Start in lib/jwt/encoded_token.rb, where EncodedToken#initialize splits the token with jwt.split('.') and keeps only the first three parts, then compare it with JWT::Decode#validate_segment_count!. Pull request #782 is already open against this issue, so check it before starting. Done means EncodedToken raises JWT::MalformedTokenError for tokens with extra segments while tokens with an empty detached payload still verify.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

bug

JWT.decode rejects tokens with extra segments, but JWT::EncodedToken ignores anything after the third one. A valid token with junk appended therefore verifies.

This isn't a forgery, because the signature still has to match, but the two APIs disagree on what a valid token is, and the token string is malleable.

rsa = OpenSSL::PKey::RSA.generate(2048)
token = "#{JWT.encode({ 'sub' => 'x' }, rsa, 'RS256')}.extra"

JWT::EncodedToken.new(token).verify_signature!(algorithm: 'RS256', key: rsa.public_key)
# => nil (accepted)

JWT.decode(token, rsa.public_key, true, algorithm: 'RS256')
# => JWT::MalformedTokenError: Not enough or too many segments

Reproduced on 3.3.1. lib/jwt/encoded_token.rb is unchanged on main.

Cause: EncodedToken#initialize uses jwt.split('.') and keeps the first three parts. The segment count check only exists in JWT::Decode#validate_segment_count!.

Suggestion: Raise JWT::MalformedTokenError for tokens with too many segments when using EncodedToken, without breaking tokens that have an empty detached payload.

Posted by Claude on behalf of @anakinj.

Lingua principale
Ruby
Stelle
3.7k
Fork
381
Merge medio
17h 10m
PR unite (30g)
11

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di jwt/ruby-jwt

Tutte le issue di jwt/ruby-jwt

Issue simili

Altre issue su Ruby

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.