Ash授权绕过漏洞分析(CVE-2025-48044)
漏洞概述
Ash框架在绕过策略条件评估为真但授权检查失败时存在授权绕过漏洞。当满足以下条件时,具有绕过策略的资源可以在没有适当授权的情况下被访问:
- 绕过条件评估为真
- 绕过授权检查失败
- 存在其他策略但其条件不匹配
技术细节
漏洞代码位置
漏洞位于 lib/ash/policy/policy.ex:69:
1
2
3
4
5
|
{%{bypass?: true}, cond_expr, complete_expr}, {one_condition_matches, all_policies_match} ->
{
b(cond_expr or one_condition_matches), # <- 错误:仅使用条件
b(complete_expr or all_policies_match)
}
|
漏洞原理
最终的授权决策是:one_condition_matches AND all_policies_match
当绕过条件为真但绕过策略失败,且后续策略具有不匹配的条件时:
one_condition_matches = cond_expr(绕过条件)= true(错误 - 应检查绕过是否实际授权)
all_policies_match = (complete_expr OR NOT cond_expr) 对于每个策略
对于不匹配的策略:(false OR NOT false) = true(策略不适用)
最终结果:true AND true = true(错误授权)
绕过条件单独满足"至少一个策略适用",即使绕过未能授权。
修复方案
将第69行的 cond_expr 替换为 complete_expr:
1
2
3
4
5
|
{%{bypass?: true}, _cond_expr, complete_expr}, {one_condition_matches, all_policies_match} ->
{
b(complete_expr or one_condition_matches), # <- 已修复
b(complete_expr or all_policies_match)
}
|
第52行也应更新以保持一致性:
1
2
3
4
5
|
{%{bypass?: true}, _cond_expr, complete_expr}, {one_condition_matches, true} ->
{
b(complete_expr or one_condition_matches), # <- 为保持一致性
complete_expr
}
|
漏洞验证
策略配置示例
1
2
3
4
5
6
7
8
9
|
policies do
bypass always() do
authorize_if actor_attribute_equals(:is_admin, true)
end
policy action_type(:read) do
authorize_if always()
end
end
|
非管理员用户可以执行创建操作(本应被拒绝)。
测试用例
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
test "bypass policy bug" do
policies = [
%Ash.Policy.Policy{
bypass?: true,
condition: [{Ash.Policy.Check.Static, result: true}], # 条件 = true
policies: [
%Ash.Policy.Check{
type: :authorize_if,
check: {Ash.Policy.Check.Static, result: false}, # 策略 = false
check_module: Ash.Policy.Check.Static,
check_opts: [result: false]
}
]
},
%Ash.Policy.Policy{
bypass?: false,
condition: [{Ash.Policy.Check.Static, result: false}],
policies: [
%Ash.Policy.Check{
type: :authorize_if,
check: {Ash.Policy.Check.Static, result: true},
check_module: Ash.Policy.Check.Static,
check_opts: [result: true]
}
]
}
]
expression = Ash.Policy.Policy.expression(policies, %{})
assert expression == false
# 期望:false(拒绝)
# 主分支实际结果:true(错误授权)
end
|
参考信息
安全评分
- 严重等级:高
- CVSS总体评分:8.6/10
- EPSS评分:0.09%(第26百分位)
弱点分类
- CWE-863:不正确的授权
- 产品在参与者尝试访问资源或执行操作时执行授权检查,但未能正确执行检查。这允许攻击者绕过预期的访问限制。