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

未关闭 适合新手
#844 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
83/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
ruby

调研方向

阅读 lib/auth0/mixins/validation.rb、lib/auth0/api/authentication_endpoints.rb 和顶层 require 路径,了解 Auth0::Algorithm 是如何加载的。添加一个回归测试,仅使用 require "auth0" 加载库并执行 ID token 验证。完成标准是算法常量可用,且伪造的 token 会触发预期的 Auth0::InvalidIdToken 错误。

由索引模型根据 Issue 内容生成。

描述

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
主要语言
Ruby
星标
205
派生
144
平均合并
1 天 13 小时
30 天内合并 PR
9

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

auth0/ruby-auth0 的其他 Issue

查看 auth0/ruby-auth0 的全部 Issue

相似的 Issue

更多 Ruby Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。