Skip to content

feat: wire configuration/httpHeaders into Authentication for token auth (no schema bump) - #14203

Open
gnodet wants to merge 1 commit into
apache:maven-3.10.xfrom
gnodet:feat/httpheaders-decrypt
Open

gnodet wants to merge 1 commit into
apache:maven-3.10.xfrom
gnodet:feat/httpheaders-decrypt

Conversation

@gnodet

@gnodet gnodet commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

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 into AuthenticationBuilder token headers, so that bearer tokens and custom HTTP authentication headers stored in settings.xml are:

  • Decrypted by DefaultSettingsDecrypter (same as <password> and <passphrase>)
  • Origin-scoped by the Resolver's addBearerToken/addTokenHeader path, so tokens are never sent to cross-origin redirects
  • RFC 9110 validated by HttpTransporterUtils.isValidTokenHeaderName before being added to the Authentication

No settings schema change is needed. This reuses the existing, documented <configuration><httpHeaders> path that users already know:

<!-- Bearer token (Authorization: Bearer <token>) -->
<server>
  <id>internal</id>
  <configuration>
    <httpHeaders>
      <property>
        <name>Authorization</name>
        <value>Bearer {encrypted-with-mvn-encrypt-password}</value>
      </property>
    </httpHeaders>
  </configuration>
</server>

<!-- Custom token header (e.g. GitLab) -->
<server>
  <id>gitlab</id>
  <configuration>
    <httpHeaders>
      <property>
        <name>Private-Token</name>
        <value>{encrypted-with-mvn-encrypt-password}</value>
      </property>
    </httpHeaders>
  </configuration>
</server>

Root Cause

The existing <configuration><httpHeaders> path had three gaps for token authentication:

  1. No decryption — values were taken as raw XML strings, so {...} encrypted tokens were sent as-is
  2. No origin binding — headers went into ConfigurationProperties.HTTP_HEADERS (a session config map), which the transports send without the Authentication layer's cross-origin protection
  3. No validation — invalid header names (Proxy-, Sec-, etc.) were silently accepted

Fix

  • DefaultSettingsDecrypter: decrypt <configuration><httpHeaders><property><value> entries in-place alongside <password> and <passphrase>
  • DefaultRepositorySystemSessionFactory: move authSelector.add() to after the <configuration> block, and wire valid token headers into authBuilder via addBearerToken (for Authorization: Bearer …) or addTokenHeader (for any other RFC 9110-valid name)
  • Bump resolver to 2.0.27 for AuthenticationBuilder.addBearerToken/addTokenHeader and HttpTransporterUtils.isValidTokenHeaderName

Headers that fail isValidTokenHeaderName are silently left in HTTP_HEADERS only (backward-compatible), not added to Authentication.

Tests

  • DefaultSettingsDecrypterTest: 3 new cases — encrypted value is decrypted, plain value passes through, server without httpHeaders is unaffected
  • DefaultRepositorySystemSessionFactoryTest: all 8 existing tests pass

Depends on: apache/maven-resolver#2372 (merged, in resolver 2.0.27-SNAPSHOT; switch resolverVersion to 2.0.27 once released)

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
gnodet requested review from cstamas and rmannibucau December 1, 2026 06:11
@gnodet gnodet added bug Something isn't working forward-port-to-master security Security issue or fix. Report undisclosed vulnerabilities to security@apache.org, not here. forward-port-to-4.0.x Forward-port this fix from maven-3.10.x to maven-4.0.x labels Dec 1, 2026
@gnodet
gnodet marked this pull request as ready for review December 1, 2026 06:16

@gnodet-bot gnodet-bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 rmannibucau left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 ")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

@cstamas

cstamas commented Dec 1, 2026 •

Copy link
Copy Markdown
Member

My problem with this solution is exactly what I tried to explain in previous PR: assume a use case, where user wants to:

  • add token based auth
  • and customize HTTP headers, and add something like "Workstation: Tuco" that flies out with every HTTP request workstation does.

The httpHeaders feature were done to "customize HTTP headers" in mind, and not to "do auth only". I tried to argue, that by re-purposing existing (old, since Maven2) feature to do only auth is a breaking change for me. This PR makes it this, or that, exclusive or.

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).

@rmannibucau

Copy link
Copy Markdown
Contributor

@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.

@cstamas

cstamas commented Dec 1, 2026

Copy link
Copy Markdown
Member

@rmannibucau I'm afraid it does.

isValidTokenHeaderName doesn't decide whether a header is sensitive. It only checks that the name is a valid RFC 9110 token and isn't a header the HTTP clients or the connection manage themselves (Host, Content-Length, Proxy-Authorization, Sec-*, ...). Workstation, X-Build-Id, X-Request-Source and so on all pass. So every ordinary httpHeaders entry becomes a token header, i.e. authentication, and nothing is "routed" between sensitive and non-sensitive.

Here is what that means in Resolver 2.0.27:

  1. Token headers replace configured headers with the same name (HttpTransporterUtils#putTokenHeaders). The entry is still in HTTP_HEADERS, but what the transport sends is the token header.
  2. Token headers are always origin-scoped as every secret, and ignore aether.transport.http.originScopedHeaders. All four HTTP transports (Apache, JDK, Jetty, URL) do this, and the shared HttpTransporterTest checks it with scoping both on and off. This is on purpose: auth material must never leave the origin.
  3. Token values are validated strictly. They must not be blank and may contain only visible ASCII, spaces and tabs. A value that fails this (empty, or non-ASCII like Workstation: Tücö) now makes transporter creation fail with "Missing or invalid HTTP token value", which breaks the build for a header that has nothing to do with auth.

Take my example again: a user wants token auth to the repository, and Workstation: Tuco on every HTTP request the workstation makes, including redirect hops to a CDN or another host. Resolver supports this today, because auth and headers are controlled separately:

  • authentication (username/password, and now token headers via AuthenticationBuilder#addTokenHeader/addBearerToken) always stays on the repository origin;
  • configured headers (aether.transport.http.headers) follow aether.transport.http.originScopedHeaders, which is true by default since 2.0.25. The user sets it to false to have them sent everywhere.

With this PR, Maven feeds both from the same <httpHeaders> element, so that user can't have both anymore. Workstation: Tuco silently becomes origin-only auth material, and originScopedHeaders=false no longer has any effect on it. That's the either/or I meant, and it breaks the original (Maven 2) purpose of <httpHeaders>: customizing HTTP headers.

@cstamas

cstamas commented Dec 1, 2026

Copy link
Copy Markdown
Member

In other words, from Maven perspective, configured httpHeaders always went everywhere, since Maven 2.0, 2.1, 3.0, 3.1, 3.6, 3.8 and even in 3.9. And now, in Maven 3.10.2 you call this feature a "bug" and call it a mistake. While out there, I am sure, are people relying on it, and they want still to have them go "everywhere".

@cstamas

cstamas commented Dec 1, 2026

Copy link
Copy Markdown
Member

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.

@rmannibucau

Copy link
Copy Markdown
Contributor

@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.

auth material must never leave the origin

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?

gnodet pushed a commit to gnodet/maven that referenced this pull request Dec 2, 2026
…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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working security Security issue or fix. Report undisclosed vulnerabilities to security@apache.org, not here.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants