安全攻防
evening
CVE-2026-90474:MCPHub 内置 OAuth 2.0 授权服务器存在客户端身份验证绕过
2026-11-16
1 阅读
约10分钟阅读
先知社区
字号:
漏洞扭转 MCPHub ,一个全方位管理多个 MCP 的平台,在 1.0.32 版本中,其内置的 OAuth 授权服务器在授权码授权流程中,情况默认下攻击者可以通过不提供 client_secret 和 code_verifier 来绕过客户端验证。攻击者如果通过某种方式(比如 CSRF)获取了授权码,之前可创建一个客户端向授权服务器发起访问令牌请求,然后获取服务器请求获取资源的令牌去向资源。复现与漏洞讲解MCPHub通过node-oauth2-server模块实现OAuth授权服务器: import OAuth2Server from '@node-oauth/oauth2-server'; OAuth2Server 类的实现: oauth = new OAuth2Server({ [snip] // 当 requireClientSecret 为 false 时,允许无客户端密钥的 PKCE requireClientAuthentication: oauthConfig.requireClientSecret ? {authorization_code: true,fresh_token: true } : {authorization_code: false,refresh_token: false }, }); 这有一段注释信息:如果 requireClientSecret 的值为 false ,则对客户端的验证只需要通过 PKCE 消耗而再验证 client_secret (特别注释信息只能作为参考,具体实现还得验证)。 PKCE 是授权码授权流程中引入的一种客户端校验机制:客户端在发起授权请求前会生成一个高语义随机字符串 code_verifier 作为验证器,并根据某种算法( plain / S256 )计算得到 code_challenge协议在授权请求中将code_challenge和算法( code_challenge_method )发给授权服务器继续在访问令牌计算请求中,客户端需要向授权服务器提供code_verifier收到验证器后,授权客户端提供的code_challenge_method自己一版code_challenge,通过比较之前两个挑战值是否一致来验证客户端身份在PKCE中,攻击者如果无法得到code_verifier对 OAuth 或者 PKCE 不太了解的,可以先看这篇文章。根据注释的验证说法,其实如果 MCPHub 正确应用了 PKCE,那么验不验证 client_secret 并不是无可厚非,但事实并非如此。默认值关于 oauthConfig.requireClientSecret 的默认值,需要去追踪 returnedConfig : const systemConfigDao = getSystemConfigDao(); const systemConfig = 等待 systemConfigDao.get(); const storeConfig = systemConfig?.oauthServer; const oauthConfig = { ...cloneDefaultOAuthServerConfig(), ...storedConfig }; 能发现它会去 mcp_settings.json 文件中获取配置信息, requireClientSecret 的默认值就在里面: "requireClientSecret": false 当然,获取其默认值最方便的方式就是调试,将按键逻辑扒下来(注意相对路径): import { getSystemConfigDao } from '../dao/index.js';从'../constants/oauthServerDefaults.js'导入{cloneDefaultOAuthServerConfig}; const systemConfigDao = getSystemConfigDao(); const systemConfig = 等待 systemConfigDao.get(); const storeConfig = systemConfig?.oauthServer; // 将存储的配置与默认值合并,以便部分配置仍然继承所有默认值 const oauthConfig = { ...cloneDefaultOAuthServerConfig(), ...storedConfig }; console.log('调试完成。'); 使用node.js 调试 TypeScript 代码需要使用 TypeScript 执行 (tsx): 在第九行下断点,然后调试:同样也能得到 requireClientSecret 的默认值为 false 。 (根据三元表达式)这意味着 requireClientAuthentication 的默认值为: {authorization_code: false, refresh_token: false }, 通过 rg 在 node-oauth2-server 模块中搜索 requireClientAuthentication ,得到: > rg 'requireClientAuthentication' .\node_modules\.pnpm\@node-oauth+oauth2-server@5.3.0\ [片段] .\node_modules\.pnpm\@node-oauth+oauth2-server@5.3.0\node_modules\@node-oauth\oauth2-server\lib\handlers\token-handler.js 62: this.requireClientAuthentication = options.requireClientAuthentication || {}; 298: if (Object.keys(this.requireClientAuthentication).length > 0) { 299: return (typeof this.requireClientAuthentication[grantType] !== 'undefined') ? this.requireClientAuthentication[grantType] : true; 能发现 token-handler.js 中似有利用 requireClientAuthentication 作某些判断的逻辑。 this.requireClientAuthentication[grantType] : true; } else { 返回 true; isClientAuthenticationRequired 被用于: const grantType = request.body.grant_type; if (this.isClientAuthenticationRequired(grantType) && !credentials.clientSecret && !isPkce) { throw n
这篇文章对您有帮助吗?
订阅66必读
每日精选科技资讯,直达你的邮箱