Auth0::Algorithm is not loaded by `require "auth0"`, so ID token validation raises NameError

Offen Anfängerfreundlich
#844 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Maintainer antworten meist innerhalb von 1 Tag

Dieses Issue hat noch niemand übernommen.

Bewertung

Schwierigkeit
2/5
Geschätzter Aufwand
1-3 Stunden
Anfängerfreundlichkeit
83/100
Issue-Typ
Bug
Klarheit
Klar beschrieben
Aktivitätsstatus
Aktiv
Tech-Stack
ruby
Bereich
authentication

Rechercherichtung

Lies lib/auth0/mixins/validation.rb, lib/auth0/api/authentication_endpoints.rb und den require-Pfad auf oberster Ebene, um zu sehen, wie Auth0::Algorithm geladen wird. Füge einen Regressionstest hinzu, der die Bibliothek nur mit require "auth0" lädt und die Validierung eines ID-Tokens ausführt. Erledigt ist die Aufgabe, wenn die Algorithmuskonstante verfügbar ist und das erfundene Token den erwarteten Fehler Auth0::InvalidIdToken auslöst.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Beschreibung

Description

In v6.7.0, require "auth0" does not load auth0/algorithm, so Auth0::Algorithm is undefined. Auth0::Mixins::Validation::IdTokenValidator refers to Auth0::Algorithm::RS256 and Auth0::Algorithm::HS256 (lib/auth0/mixins/validation.rb), and validate_id_token uses Auth0::Algorithm::RS256 as its default (lib/auth0/api/authentication_endpoints.rb). Validating an ID token therefore raises a NameError, unless the application requires auth0/algorithm itself.

EXAMPLES.md documents algorithm: Auth0::Algorithm::RS256.jwks_url(...) and Auth0::Algorithm::HS256.secret(...), which do not work after a plain require "auth0" either.

Reproduction
require "auth0"

defined?(Auth0::Algorithm)
# => nil

alg = Auth0::Mixins::Validation::Algorithm::RS256.jwks_url("https://samples.auth0.com/.well-known/jwks.json")
validator = Auth0::Mixins::Validation::IdTokenValidator.new(
  algorithm: alg, leeway: 60, issuer: "https://samples.auth0.com/", audience: "x"
)
validator.validate("eyJhbGciOiJSUzI1NiIsImtpZCI6ImsxIn0.e30.c2ln")
# => NameError: uninitialized constant Auth0::Algorithm

require "auth0/algorithm"
validator.validate("eyJhbGciOiJSUzI1NiIsImtpZCI6ImsxIn0.e30.c2ln")
# => Auth0::InvalidIdToken (the expected error for this made-up token)
Cause

v5's lib/auth0.rb contained require 'auth0/algorithm'. The v6 rewrite (e7c21e79) did not carry the require over, and nothing else requires lib/auth0/algorithm.rb.

Suggested fix

Require auth0/algorithm where the validation mixin is loaded (for example from lib/auth0/mixins.rb or lib/auth0/auth_client.rb), and add a test that validates an ID token after only requiring auth0.

Environment
  • auth0 gem v6.7.0 (repository at 18167468), Ruby 3.3.14
Vorherrschende Sprache
Ruby
Sterne
205
Forks
144
Ø Merge
1 T. 13 Std.
Gemergte PRs (30 T.)
9

Entwicklungsumgebung

Erste Schritte

  1. Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
  3. Forken Sie das Repository und arbeiten Sie in einem Branch.
  4. Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.

Mehr aus auth0/ruby-auth0

Alle Issues in auth0/ruby-auth0

Ähnliche Issues

Weitere Issues zu Ruby

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.