Repository navigation
Conversation
Decrypt and origin-scope HTTP headers stored in <configuration><httpHeaders> so that bearer tokens and custom token headers work without a settings schema bump. DefaultSettingsDecrypter now decrypts <property><value> entries inside <configuration><httpHeaders>, just like <password> and <passphrase>. DefaultRepositorySystemSessionFactory wires headers with valid RFC 9110 names into AuthenticationBuilder via addBearerToken (for 'Authorization: Bearer ...') or addTokenHeader (for other names), giving them the resolver's origin-scoping and preemptive-send semantics. Headers that fail isValidTokenHeaderName stay in HTTP_HEADERS only, preserving backward compatibility. Depends on resolver 2.0.27 for addBearerToken/addTokenHeader/isValidTokenHeaderName.
gnodet-bot
left a comment
There was a problem hiding this comment.
Two findings on the token auth wiring.
Missing warnIfNotDecrypted for HTTP header values: The existing password/passphrase decryption paths call warnIfNotDecrypted to alert users when the master password is missing and decryption silently fails. The new httpHeaders decryption path in DefaultSettingsDecrypter does not have an equivalent guard — if decryption fails and returns the encrypted-looking ciphertext verbatim, the token header is sent as-is with no feedback to the user. The Severity.ERROR problem in the decrypter catches the exception case but misses the case where the security dispatcher returns a silently-unchanged value. Consider comparing pre/post decryption values and warning when they differ while no problem was reported.
Missing integration test for session factory wiring: DefaultSettingsDecrypterTest covers the decrypter well, but there is no test that constructs a server with httpHeaders, calls newRepositorySessionBuilder, and verifies the resulting Authentication object contains the expected bearer token or token header. The wiring logic (the addBearerToken/addTokenHeader calls and the moved authSelector.add(...)) is currently only covered by integration tests. A focused unit test would catch regressions in the wiring independently.
Note: resolverVersion is bumped to 2.0.27-SNAPSHOT. This is intentional for development but must be resolved to a release before this PR is merged.
This review was generated by an AI agent, Hermès on behalf of @gnodet.
rmannibucau
left a comment
There was a problem hiding this comment.
like the direction, i'd just change the header key name to set it as a token and maybe make it configurable based on a @Config or something we can pass as system property in MAVEN_OPTS easily 👍
| // origin-scoping, preemptive sending, and RFC 9110 validation. | ||
| // Values were already decrypted by DefaultSettingsDecrypter. | ||
| if (name != null && value != null && HttpTransporterUtils.isValidTokenHeaderName(name)) { | ||
| if ("Authorization".equalsIgnoreCase(name) && value.startsWith("Bearer ")) { |
There was a problem hiding this comment.
we need a configurable list of these (i'd say just header name) since there are a lot of patterns and not all are bearer so maybe something like:
Authorization
PRIVATE-TOKEN
JOB-TOKEN
Circle-Token
X-Buildkite-Token
X-Gitlab-Token
X-API-Key
API-Key
apikey
api_key
X-API-Token
Ocp-Apim-Subscription-Key
X-Goog-Api-Key
X-Auth-Token
X-AUTH-TOKEN
X-Auth-Key
X-Access-Token
X-Forwarded-Access-Token
X-Token
Access-Token
Private-Token
Client-Token
Client-Secret
X-Client-Secret
X-Client-Key
DPoP
X-Jenkins-Crumb
X-Original-Authorization
|
My problem with this solution is exactly what I tried to explain in previous PR: assume a use case, where user wants to:
The I will not oppose this PR, but IMO this is worse than doing XSD change, as Maven was prepared for XSD changes (as we see, even 3.9 parses 1.3.0 settings, and this decision was on purpose), while here, we would silently break users of non-auth use case (the original intent of the Maven2 feature). |
|
@cstamas this PR doesnt do what you claim, it keeps httpHeaders setting httpHeaders, it just uses you resolver changes to flag some as sensitive and treating them as such. The cross server header forwarding was a bug from day 0 this can fix as side effect which is great, but it keep a routing sensitive/not sensitive. So sounds like the best of best worlds to me. |
|
@rmannibucau I'm afraid it does.
Here is what that means in Resolver 2.0.27:
Take my example again: a user wants token auth to the repository, and
With this PR, Maven feeds both from the same |
|
In other words, from Maven perspective, configured |
|
To recap: I consider this PR wrong, but, as I said, I am not blocking anything, lets author and others decide. OTOH, @rmannibucau you continuously demonstrate your lack of understanding and/or knowledge of several fundamental principles in Maven, or, you just base every your claim on your "muscle Maven memory" (see LRM PR too). And I agree, this and other PR discussion is really a waste IMO. |
|
@cstamas this is not a misunderstanding but a consideration of the end users - this is where we do differ, I don't care of what we thought but I care of what people do and why we loved what we proposed. Ack sometimes it means violating original design and I'm happy to do that if it helps end users.
this is a no brainer but other headers should have the same thing by default and potentially can be enabled to leave. you will note that there is some cases this is wrong, when you do use proxy related headers not configurable in settings proxies - 💩 happens. Now, on your feedback - where I agree - it just sounds my comment should be taken into account to handle the addXToken call and else do headers.put as before and we'll be good, no? |
…th (apache#14203) Port of apache#14203 (maven-3.10.x) to master. Wire `<configuration><httpHeaders>` entries into `AuthenticationBuilder` token headers, so bearer tokens and custom HTTP authentication headers stored in `settings.xml` are: - Origin-scoped by the Resolver's `addBearerToken`/`addTokenHeader` path - RFC 9110 validated by `HttpTransporterUtils.isValidTokenHeaderName` - Moved `authSelector.add()` to after the headers loop so token headers are included in the built Authentication object No decryption change needed here: `DefaultSettingsBuilder` already decrypts all `configuration` XmlNode values via its `DecryptingSettingsTransformer`, which walks the DOM tree recursively. Requires maven-resolver 2.0.27-SNAPSHOT for `isValidTokenHeaderName`, `addBearerToken`, and `addTokenHeader`.
Summary
Alternative to #14173 that achieves the same goal — encrypted, origin-scoped token authentication in
settings.xml— without introducing a new settings schema.Wire
<configuration><httpHeaders>entries intoAuthenticationBuildertoken headers, so that bearer tokens and custom HTTP authentication headers stored insettings.xmlare:DefaultSettingsDecrypter(same as<password>and<passphrase>)addBearerToken/addTokenHeaderpath, so tokens are never sent to cross-origin redirectsHttpTransporterUtils.isValidTokenHeaderNamebefore being added to theAuthenticationNo settings schema change is needed. This reuses the existing, documented
<configuration><httpHeaders>path that users already know:Root Cause
The existing
<configuration><httpHeaders>path had three gaps for token authentication:{...}encrypted tokens were sent as-isConfigurationProperties.HTTP_HEADERS(a session config map), which the transports send without theAuthenticationlayer's cross-origin protectionFix
DefaultSettingsDecrypter: decrypt<configuration><httpHeaders><property><value>entries in-place alongside<password>and<passphrase>DefaultRepositorySystemSessionFactory: moveauthSelector.add()to after the<configuration>block, and wire valid token headers intoauthBuilderviaaddBearerToken(forAuthorization: Bearer …) oraddTokenHeader(for any other RFC 9110-valid name)AuthenticationBuilder.addBearerToken/addTokenHeaderandHttpTransporterUtils.isValidTokenHeaderNameHeaders that fail
isValidTokenHeaderNameare silently left inHTTP_HEADERSonly (backward-compatible), not added toAuthentication.Tests
DefaultSettingsDecrypterTest: 3 new cases — encrypted value is decrypted, plain value passes through, server without httpHeaders is unaffectedDefaultRepositorySystemSessionFactoryTest: all 8 existing tests passDepends on: apache/maven-resolver#2372 (merged, in resolver 2.0.27-SNAPSHOT; switch
resolverVersionto2.0.27once released)