Ash Authentication令牌撤销逻辑漏洞分析与修复指南

本文详细分析Ash Authentication身份验证库中令牌撤销检查逻辑的漏洞,影响范围包括魔法链接、密码重置等功能,提供具体的修复方案和工作绕过方法。

漏洞概述

CVE-2025-25202 是一个在 Ash Authentication 库中发现的中等严重性漏洞,影响版本为 4.1.0 至 4.4.8。该漏洞涉及通过 mix ash_authentication.install 生成的令牌撤销检查逻辑存在缺陷。

影响范围

使用新版 igniter 安装程序(自 AshAuthentication v4.1.0 起)引导的应用程序,并且使用了以下功能的用户会受到影响:

  • 魔法链接策略
  • 密码重置功能
  • 确认功能
  • 手动撤销令牌

未使用新安装程序的用户完全不受影响。

具体影响

  • 魔法链接策略用户:魔法链接令牌在过期前可重复使用,而不是立即撤销(默认有效期为10分钟)
  • 密码重置用户:密码重置令牌在过期前可重复使用,而不是立即撤销(默认有效期为3天)
  • 确认附加组件用户:确认令牌在过期前可重复使用,而不是立即撤销(默认有效期为3天)

修复方案

该漏洞已在 4.4.9 版本中修复,升级时会显示编译时警告并提供修复说明。

自动修复命令:

1
mix igniter.upgrade ash_authentication

手动修复命令:

1
mix ash_authentication.upgrade 4.4.8 4.4.9

代码修复示例

1
2
3
4
5
6
7
action :revoked?, :boolean do
  description "Returns true if a revocation token is found for the provided token"
  argument :token, :string, sensitive?: true
  argument :jti, :string, sensitive?: true
  
  run AshAuthentication.TokenResource.IsRevoked
end

需要移除 allow_nil?: false 参数,并确保操作返回 :boolean 类型。

临时解决方案

删除令牌资源中生成的 :revoked? 通用操作,这将使其使用 AshAuthentication 内部一直正确的实现。

技术细节

漏洞核心在于 :revoked? 操作的 :jti:token 选项未正确处理 nil 值,且未正确返回布尔类型,导致已撤销的令牌仍能被验证为有效。

参考信息

comments powered by Disqus
使用 Hugo 构建
主题 StackJimmy 设计