OAuth2(授权代码授权类型)的重定向 URI 中是否应存在动态查询参数

Should dynamic query parameters be present in the Redirection URI for an OAuth2 (Autorization Code Grant Type)

诸如 Okta sponsored site 之类的来源(参见 "Per-Request Customization" 部分)提到授权请求的 redirect_uri 参数不应该有动态查询部分(例如:用于会话匹配使用).

引用:

The server should reject any authorization requests with redirect URLs that are not an exact match of a registered URL.

我们的 OAuth AZ 提供商是 BIG-IP F5。我们正在设置,他们似乎也符合上述观点。

我们的客户端是在别处搭建的web应用,他们好像没有遵循上面的规则。 这是授权端点的完整表示(已编辑): https://ourownF5host.ca/f5-oauth2/v1/authorize?client_id=theIDofOurClient&redirect_uri=https%3A%2F%2FourClientAppHostname%2FClientRessource%2FRessource%3FSessionId%3D76eab448-52d1-4adb-8eba-e9ec1b9432a3&state=2HY-MLB0ST34wQUPCyHM-A&scope=RessourceData&response_type=code

他们使用的 redirect_uri 格式类似于(为了简单起见,我不在这里进行 urlencode):redirect_uri=https://ourClientAppHostname/ClientRessource/Ressource?SessionId=SOMELONGSESSIONID,SOMELONGSSESSIONID 值不同每次通话。

我们将 DEEP 挖掘到 RFC6749 (OAuth2) 中,并在第 3.1.2.2 节中找到:

The authorization server SHOULD require the client to provide the
complete redirection URI (the client MAY use the "state" request
parameter to achieve per-request customization). If requiring the
registration of the complete redirection URI is not possible, the
authorization server SHOULD require the registration of the URI
scheme, authority, and path (allowing the client to dynamically vary
only the query component of the redirection URI when requesting
authorization).

我的理解是,第一个来源 Okta 和 F5 只接受上述规则的第一部分,并且要求完全注册重定向 uri,没有任何动态部分。

我是否可以肯定他们(Okta 和 F5)不遵守摘录的第二部分,理由是他们应该“允许客户端动态变化 请求时仅重定向 URI 的查询组件 授权" ?

或者,是否有 RFC6749 的官方 correction/evolution 保证两家公司的设计立场?

TL;DR:

不,出于安全原因,重定向 uri 必须是静态的。如果客户端需要在授权请求和异步响应之间保持 state,请使用 OAuth 2.0 state 参数。

长版 :

RFC6749(最初的 OAuth 2.0 规范)已于 2012 年发布,从那时起 OAuth 安全格局发生了很大变化。

RFC6819, an OAuth 2.0 security review from 2013 已经提到拒绝动态制作的重定向 uris 是防止 XSS 和客户端模拟攻击的好方法。

OpenID Connect,从 2014 年开始,具有身份验证功能的 OAuth 2.0 的常用扩展已经考虑到该建议,并要求对所有重定向 uris 进行精确的字符串匹配。

The current draft recommendation for OAuth 2.0 Best Security Practice 通过强制执行 redirect_uris 预注册并强制 AS 在验证请求中传递的 redirect_uri 时使用简单的字符串比较来确认这一点。所以不能使用动态 redirect_uri。

你的客户肯定是在使用 redirect_uri 作为授权请求和响应之间的“状态保持器”,通过在 redirect_uri. OAuth2.0为此有一个专门的授权请求参数,即“state”。客户应该使用它。当 AS 发出响应时,它将在 redirect_uri 的参数中附加该状态,因此客户端将能够在响应中找回该状态。

正确的授权请求应该是:

https://youras/authorize?client_id=your_client_id&response_type=code&state=SOMELONGSTATE&redirect_uri=https%3A%2F%2Fsomehost% 2故障回调

响应将如下所示: https:///somehost/authcallback?state=SOMELONGSTATE&code=anazcode

这样 redirect_uri 是静态的,所以一个简单的字符串比较就足以在 AS 端验证该 uri。任何比简单字符串比较更复杂的算法都存在安全漏洞。

这里似乎混淆了两件事:URL 你指的是:

 https://somehost/authcallback?state=SOMELONGSTATE&scope=someobjecttype&response_type=code

建议您混淆了客户端的重定向 URI(又名回调 URL,如 URL 中的路径名所建议)与授权服务器的授权端点。

只有授权端点会采用建议的参数,并且可能包含例如动态 state 值。客户端的重定向 URI 不会包含例如响应类型。

可以将 redirect_uri 参数添加到授权请求中,然后必须按照您描述的方式进行匹配。确认匹配后,授权服务器将重定向回重定向 URI,添加 codestate 参数。

更新(问题改变后):

OAuth 2.0 RFC6749 允许动态 (SessionId) 参数,但它不被认为是最佳实践。但是,如果您的客户端是 OpenID Connect 客户端,则这是不允许的,因为 OpenID Connect 规范(OAuth 2.0 的 "profile")锁定了与 "exact" 匹配的重定向 URI,在这种情况下,您将拥有配置所有可能的 SessionId。