错误的“Accept”头在发送给OIDC提供者的请求中。

huangapple go评论43阅读模式
英文:

Malformed "Accept" header sent in requests to OIDC Provider

问题

我们在Magnolia CMS中使用Pac4j v5.7.0来实现SSO模块。

在请求OIDC提供程序的配置元数据(Content-type: application/json文档)时,Magnolia发送以下Accept标头:

text/html, image/gif, image/jpeg, *; q=.2, /; q=.2

这违反了规范的两个方面:

  1. 违反了https://www.rfc-editor.org/rfc/rfc9110.html#name-accept中的内容类型 *
  2. 违反了https://www.rfc-editor.org/rfc/rfc9110.html#quality.values中的q值为.2

这导致遵守规范的服务器返回406(内容协商)错误,Magnolia未收到请求的OIDC配置元数据。

我们追踪下来发现,Pac4J似乎使用标准的java.net.URLConnection,不幸的是,我们看到的Accept标头是它的默认值。
在执行简单操作时发送的内容如下:new URL("http://localhost:8888").connect()

GET / HTTP/1.1
User-Agent: Java/17.0.6
Host: 127.0.0.1:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive

不幸的是,正如我们在https://github.com/pac4j/pac4j/blob/master/pac4j-core/src/main/java/org/pac4j/core/resource/SpringResourceHelper.java#L52-L56中看到的,Pac4J在打开连接并发送请求之前没有设置或更改任何默认标头。

如果以上分析是正确的,这意味着Pac4J正在违反HTTP标准,并将无法与遵守内容协商“协议”的任何OIDC服务器联系。

快速查看提交历史告诉我这可能是相当近期的事情... 他们最近引入了SpringResourceLoader/Helper类,可能是唯一负责这个问题的(3个月前)-> https://github.com/pac4j/pac4j/commit/bebd578596b11916b531c5e7da7ed4ba3d75c479

对于5.7.0版本,所有事情发生在这些行之间:https://github.com/pac4j/pac4j/blob/5.7.x/pac4j-oidc/src/main/java/org/pac4j/oidc/config/OidcConfiguration.java#L175-L195

谢谢!

英文:

We use Pac4j v5.7.0 in Magnolia CMS for our SSO module.

When requesting the configuration metadata of an OIDC Provider (a Content-type: application/json document), Magnolia sends the following Accept header:

text/html, image/gif, image/jpeg, *; q=.2, /; q=.2

This breaks the spec in two ways:

  1. Breaks https://www.rfc-editor.org/rfc/rfc9110.html#name-accept with the content-type *
  2. Breaks https://www.rfc-editor.org/rfc/rfc9110.html#quality.values with the q value of .2

This results in complying servers returning a 406 (content negotiation) error and Magnolia not getting returned the requested OIDC configuration metadata.

We traced it down and found Pac4J seems to be using standard java.net.URLConnection and unfortunately the Accept header we are seeing is the default for it.
Here is what it is sent when doing a simple: new URL("http://localhost:8888").connect()

<kbd>
GET / HTTP/1.1
User-Agent: Java/17.0.6
Host: 127.0.0.1:8888
Accept: text/html, image/gif, image/jpeg, *; q=.2, /; q=.2
Connection: keep-alive
</kbd>

And unfortunately, as we can see in https://github.com/pac4j/pac4j/blob/master/pac4j-core/src/main/java/org/pac4j/core/resource/SpringResourceHelper.java#L52-L56, Pac4J is not setting or changing any of the default headers before opening the connection and sending the request.

If the above analysis is correct, it means that Pac4J is breaking the HTTP standards and will be unable to contact any OIDC server respecting Content Negotiation "protocol".

A quick look at the commit history tells me that it may be quite recent... They introduced the SpringResourceLoader/Helper classes that may be responsible for that only recently (3 months ago) -> https://github.com/pac4j/pac4j/commit/bebd578596b11916b531c5e7da7ed4ba3d75c479

For 5.7.0 everything happens between these lines: https://github.com/pac4j/pac4j/blob/5.7.x/pac4j-oidc/src/main/java/org/pac4j/oidc/config/OidcConfiguration.java#L175-L195

Thanks in advance

Rich G

Expecting the response header to conform to standards

答案1

得分: 3

我猜你在v5.7中遇到了问题,尽管你引用了v6的提交。该提交已在未来的v6版本(尚未GA发布)中引入,用于替换DefaultResourceRetriever(来自Nimbus库)为SpringResourceHelper(在pac4j-core中),以便能够从任何Spring资源(resource:,classpath:,file:,http:)中(重新)加载元数据。

在两种情况下,它们都依赖于URLConnection,因此它们可能有相同的问题。

我刚刚提交了:https://github.com/pac4j/pac4j/commit/3a21347069b0de186a4269d058ac60988d587c73

你能否使用5.7.1-SNAPSHOT版本(在Sonatype快照仓库中)重新测试一下?谢谢

英文:

I guess you have a problem in v5.7 although you referenced a commit from v6.

The commit has been introduced in the future v6 (not yet GA released) to replace the DefaultResourceRetriever (from the Nimbus library) by the SpringResourceHelper (in the pac4j-core) to be able to (re)load the metadata from any Spring resource (resource:, classpath:, file:, http:).

In both cases, they rely on URLConnection so they should have the same problem.

I just committed: https://github.com/pac4j/pac4j/commit/3a21347069b0de186a4269d058ac60988d587c73

Can you test again with the 5.7.1-SNAPSHOT version (in the Sonatype snapshots repository)? Thanks

huangapple
  • 本文由 发表于 2023年4月6日 22:46:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75950858.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定