Skip to content

[maven-3.10.x] Support token authentication (bearer and custom token headers) for settings servers - #14173

Open
cstamas wants to merge 7 commits into
maven-3.10.xfrom
maven-3.10.x-bearer-token
Open

cstamas wants to merge 7 commits into
maven-3.10.xfrom
maven-3.10.x-bearer-token

Conversation

@cstamas

@cstamas cstamas commented Nov 28, 2026 •

Copy link
Copy Markdown
Member

Maven Resolver 2.0.27 adds token header authentication (apache/maven-resolver#2372): a repository Authentication can carry any number of HTTP token headers, each a header name plus the full header value. HTTP transports (except Wagon) send them preemptively, and only to the repository origin (scheme, host, port). This PR exposes them in settings.xml:

<!-- Authorization: Bearer <token>; username and password are ignored -->
<server>
  <id>internal</id>
  <token>...</token>
</server>

<!-- sent as is in the named header, e.g. GitLab Private-Token, Job-Token or Deploy-Token -->
<server>
  <id>gitlab</id>
  <tokenHeaders>
    <tokenHeader>
      <name>Private-Token</name>
      <value>...</value>
    </tokenHeader>
  </tokenHeaders>
</server>

<!-- several headers, e.g. Cloudflare Access service tokens -->
<server>
  <id>cloudflare</id>
  <tokenHeaders>
    <tokenHeader>
      <name>CF-Access-Client-Id</name>
      <value>...</value>
    </tokenHeader>
    <tokenHeader>
      <name>CF-Access-Client-Secret</name>
      <value>...</value>
    </tokenHeader>
  </tokenHeaders>
</server>

This replaces the GitLab-documented <configuration><httpHeaders> route. Its values are not decrypted, and they are not bound to the repository origin: headers are keyed by repository id only, so a POM repository with the same id on another host would receive the token.

Changes:

  • Settings model 1.4.0 (1.3.0 already shipped in 3.10.0) adds to <server>:

    • token: a bearer token, sent as Authorization: Bearer <token>;
    • tokenHeaders: a list of tokenHeader (name, value), each sent as is.

    An Authorization token takes precedence over username and password; any other header is sent along with them. The sample conf/settings.xml now uses the 1.4.0 namespace (it was still on 1.2.0) and shows both forms.

  • DefaultSettingsDecrypter decrypts token and every token header value like the password. The session factory warns when one is left encrypted.

  • DefaultRepositorySystemSessionFactory maps token to AuthenticationBuilder.addBearerToken(token) and each token header to addTokenHeader(name, value). It first checks each one with the Resolver's own rules (HttpTransporterUtils.isValidTokenHeaderName / isValidTokenValue), so a header the transports would reject or silently drop fails the build up front. Those rules cover RFC 9110 field names, transport-controlled headers such as Host, and the Proxy-* and Sec-* names that the JDK clients drop. The error names the server and the header, never the token. Empty values are not sent.

  • Older plugin path: the maven-artifact Authentication gets tokenHeaders (header name to full header value). They are read back from the resolver via HTTP_TOKEN_HEADERS / HTTP_TOKEN_VALUE_PREFIX + name. MavenRepositorySystem, LegacyRepositorySystem and RepositoryUtils.toAuthentication carry all of them, so plugins converting ArtifactRepository ↔ RemoteRepository keep every token. The rebuild uses addTokenHeader, so a bearer token does not become Bearer Bearer ….

  • DefaultSettingsValidator checks only the structure of the token settings. It does not copy the Resolver's header rules, so they are not synced by hand on every Resolver change, and maven-settings-builder stays Resolver-free.

    • Errors:
      • a token header without a name;
      • the same header twice in any letter case, including <token> together with an Authorization token header.
    • Warnings:
      • a token header without a value;
      • a username or password set while a token is sent as Authorization, since they are then ignored. A custom header such as Private-Token goes along with Basic auth.
  • The Wagon transport is left as is and ignores the tokens.

Changed since the first review: the single <tokenHeader> naming the header for <token> is replaced by the <tokenHeaders> list. <token> is now bearer-only. This follows the resolver change to multiple token headers per repository. The header name and value rules are no longer copied into the settings validator; maven-core applies the Resolver's own checks.

Depends on: apache/maven-resolver#2372, which also includes #2373 (no Basic auth without a username, needed for a token-only server). resolverVersion is set to 2.0.27-SNAPSHOT, so CI cannot build this until the resolver change is deployed. Switch to 2.0.27 once it is released.

Release note: settings-1.4.0.xsd must be published to maven.apache.org/xsd.

Site documentation: apache/maven-site#1853 documents the token settings in the settings reference and the deployment security, encryption and HTTP settings guides. It does not publish the XSD.

Tests: new cases in DefaultSettingsDecrypterTest, DefaultSettingsValidatorTest, DefaultRepositorySystemSessionFactoryTest and LegacyRepositorySystemTest. The session factory test also checks that the Resolver rules are applied: Proxy-*, Sec-* and Host names and invalid values are rejected without the token in the message, X-Proxy-Token, Proxyish and X-Sec-Token pass, and empty values are skipped. The session factory test round-trips three cases from settings to the session, onto an ArtifactRepository, and back through toRepo:

  • a bearer token;
  • a Private-Token header;
  • a bearer token together with two Cloudflare Access headers.

mvn verify passes locally on the touched modules and their dependencies (1129 tests) against a locally installed resolver snapshot.

Maven Resolver 2.0.27 adds bearer token authentication: HTTP transports
(except Wagon) send it preemptively as an Authorization: Bearer header,
and it takes precedence over username and password.

A <server> in settings.xml can now declare it:

  <server>
    <id>internal</id>
    <bearerToken>...</bearerToken>
  </server>

- settings model 1.4.0 gets the new bearerToken field; the sample
  settings.xml now uses the 1.4.0 namespace
- the token is decrypted like the password and passphrase, and a token
  left encrypted is warned about
- the token is handed to the resolver session authentication
- the legacy ArtifactRepository Authentication carries the token, so
  older plugins that convert repositories back and forth keep it
- the settings validator warns when a token is set together with a
  username or password, as those are ignored

The Wagon transport is left as is and ignores the token.
@cstamas cstamas added the enhancement New feature or request label Nov 28, 2026
@cstamas cstamas added this to the 3.10.3 milestone Nov 28, 2026

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

Overall this is a solid, well-structured enhancement. Bearer token support is correctly threaded through all five layers (settings model → decrypter → session factory → legacy compat → artifact bridge), and the integration test covers the full round-trip including the reverse path through RepositoryUtils.toRepo(). Two minor observations below.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread pom.xml
<cipherVersion>2.0</cipherVersion>
<jxpathVersion>1.4.0</jxpathVersion>
<resolverVersion>2.0.26</resolverVersion>
<resolverVersion>2.0.27-SNAPSHOT</resolverVersion>

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.

🔖 Tracking note: resolverVersion is set to 2.0.27-SNAPSHOT, pending merge/release of apache/maven-resolver#2372 (currently open). This must be updated to the final 2.0.27 release before this PR can be merged.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Acknowledged. This tracks apache/maven-resolver#2372, and resolverVersion will be switched to 2.0.27 once it is released, before merge. Note that #2372 now also carries the token-header rework this PR builds on since 912af7a.

Some repositories expect the token in a header other than
Authorization: Bearer, for example GitLab with Private-Token, Job-Token
or Deploy-Token. Maven Resolver 2.0.27 models this as a token header
(header name plus full header value) carried in the authentication, so
it stays bound to the repository origin and is never sent elsewhere,
unlike a <configuration><httpHeaders> entry.

The server <bearerToken> (settings model 1.4.0, not released yet) is
replaced by <token> and an optional <tokenHeader>:

  <server>
    <id>gitlab</id>
    <token>...</token>
    <tokenHeader>Private-Token</tokenHeader>
  </server>

Without <tokenHeader> the token is sent as Authorization: Bearer and
username and password are ignored; any other header is sent as is,
together with them.

- the legacy ArtifactRepository Authentication carries token and
  tokenHeader as the resolver hands them back, and is rebuilt with
  addTokenHeader so a bearer token does not turn into "Bearer Bearer"
- the settings validator rejects header names the HTTP transports would
  refuse (not an RFC 9110 field name, or a transport-controlled header),
  warns about a tokenHeader without a token, and warns about username or
  password only when the token is sent as Authorization
@cstamas cstamas changed the title [maven-3.10.x] Support bearer token authentication for settings servers [maven-3.10.x] Support token header authentication (bearer, GitLab tokens) for settings servers Nov 28, 2026

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

Following up on my earlier review — the previous suggestion about testing the all-three-set case (token + username + password) is fully addressed by the new testValidateServerAuthorizationTokenWithUsernameIsWarnedAbout test, and the resolverVersion SNAPSHOT tracking note (the other open thread) still stands pending the resolver release.

The generalization from bearerToken to token/tokenHeader is clean and correct end-to-end:

  • The Bearer Bearer double-prefix guard in RepositoryUtils.toAuthentication() is handled correctly: when reading back from the session, the header is Authorization and the value is already Bearer tok3n, so addTokenHeader("Authorization", "Bearer tok3n") is used directly — no double-prefix. Verified by the new bearerTokenReachesSessionAndLegacyRepositoryPath assertions.
  • The validateToken() method correctly validates RFC 9110 field names, blocks transport-controlled headers, skips placeholder values, and applies the Authorization-specific warning only when the token replaces username/password on the wire.
  • All five layers (settings model → decrypter → session factory → legacy compat → artifact bridge) are consistently updated, including the tokenHeader not being decrypted (correct — it's a header name, not a secret).

LGTM.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

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

Re-review status (SHA 912af7af vs prior 5dd4321):

# Prior Finding Status
1 resolverVersion set to 2.0.27-SNAPSHOT — must be a final release before merge ⚠️ Still open — pom.xml not touched by new commit. apache/maven-resolver#2372 is still open and 2.0.27 is still a draft release.
2 Add all-three-set test case (token + username + password) ✅ Addressed — validateToken("token", "authorization", "user", "pwd") on line 337 covers this. Thread outdated due to file rewrite.

The new commit is a well-executed generalization: bearerToken → token + tokenHeader, correctly threaded through all five layers (settings MDO → decrypter → session factory → legacy compat → artifact bridge). The addBearerToken / addTokenHeader dispatch in both DefaultRepositorySystemSessionFactory and RepositoryUtils.toAuthentication() correctly prevents the Bearer Bearer ... double-prefix on the round-trip path, as verified by the test comment on line 219. The validateToken() method is thorough: RFC 9110 header-name validation, forbidden transport-controlled headers, ${-placeholder pass-through, and the nuanced distinction that only Authorization-bound tokens conflict with username/password while custom headers (e.g. Private-Token) coexist with them. No new issues found in the incremental diff.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

…r test

Review feedback: the bearer token case with both username and password set
was only implied by the other assertions.

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

let's try to not duplicate what we already enable to configure (also think resolver PR is overkilled in that aspect)

AuthenticationBuilder authBuilder = new AuthenticationBuilder();
authBuilder.addUsername(server.getUsername()).addPassword(server.getPassword());
authBuilder.addPrivateKey(server.getPrivateKey(), server.getPassphrase());
if (server.getTokenHeader() == null || server.getTokenHeader().isEmpty()) {

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.

empty is a valid use case IMHO

|
<server>
<id>tokenServer</id>
<token>token</token>

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.

why making it specific, we already have

                  <property>
                        <name>Authorization</name>
                        <value>Bearer xxxx</value>
                    </property>

in httpHeaders which avoids to have two inconsistent cases using token (bearer and a do what you want as schema case)

so literally we are just aliasing what is already there in terms of configuration so I would remove that

@cstamas

cstamas commented Nov 29, 2026 •

Copy link
Copy Markdown
Member Author

This isn't an alias nor duplication. <configuration><httpHeaders> differs in three ways that matter for a credential:

  1. Values aren't decrypted, so the token has to sit in settings.xml in plaintext. <token> is decrypted like <password>.
  2. It's keyed only by repository id. <token> is sent preemptively and only to the repository origin.
  3. It's a raw header bag. Maven can't validate it or warn about conflicts with username/password nor assume they are secrets or not.

Bearer tokens are credentials, and credentials belong in <server> auth, not in generic transport config. httpHeaders stays as is for non-auth headers. If there's a concrete case where the two conflict, I'm happy to document precedence.

In fact, what you ask for is to "legalize" a hack users did (as circumvention) to treat http headers as secret. But some others use it for "marker" or anything else. With your saying, we should treat them as "secret" and "marker" use case would be gone (so it would be this or that). I personally would never promote hacks as "valid solution", they were a "known circumvention", and we should provide real support for required things, like this PR does.

The model moved to 1.4.0 for token and tokenHeader, but the site still linked the 1.2.0 XSD.
@Bukama

Bukama commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

I think the support of a new auth method is a new feature instead of a bugfix?

@rmannibucau

Copy link
Copy Markdown
Contributor

@cstamas this is pure duplication for me, let me explain with your points:

Values aren't decrypted, so the token has to sit in settings.xml in plaintext. is decrypted like .

Well it is supported in maven 4 and not the hardest part to port to maven 3

It's keyed only by repository id. is sent preemptively and only to the repository origin.

Same applies to headers (and the proxy behavior too) so worth making happening for httpheaders as well

It's a raw header bag. Maven can't validate it or warn about conflicts with username/password nor assume they are secrets or not.

About conflicts it is the same for the new token so no difference there, also about secret you assume tokens are secret. While this is generally true, it is not always the case which is exactly the same as headers.
Also note that you are breaking (compatibility wise) the schema so you can add a secret=true attribute, breaks as much.

Overall the point is with as much efforts you do better since you enhance an existing and used features instead of creating a new one.
Dont forget it is always trivial to do something new but maintaing what exists always requires some more effort but we are lucky it is low there.

Side note: I think a neat compromise for the secret can be a config property - 90% of resolver configuration is not wired in maven except with properties anyway - which does list header names to hide and we set the dozen of well known values as default, will make it working for everyone for free when upgrading which is way better than making people having to maintain multiple settings (local and CI for ex) for some time and/or not having the feature at all.

So with a bit more thought I think this is the opposite of where we want to go.

@gnodet

gnodet commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

@rmannibucau's point about enhancing httpHeaders instead is worth pursuing — but as a complement, not a replacement.

The <token> path in this PR and the httpHeaders workaround are genuinely not equivalent: the two key security properties missing from httpHeaders are encryption (the token is plaintext in settings.xml) and origin-scoping (the header is sent to any repository matching the server <id>, regardless of host). Those aren't minor gaps for a credential.

That said, I think you're both right about one thing: if we were to retrofit httpHeaders with decryption + origin-scoping, we'd fix the CVE for everyone who's already using that workaround, with zero migration required. That's genuinely valuable, and it's separate from this PR.

My view: merge this PR — it's the semantically correct place for token credentials, it's well-implemented, and it unblocks users who want first-class support. Then open a follow-up to give httpHeaders the same security treatment (decryption, origin scoping). The two don't conflict: <token> for auth credentials, httpHeaders for non-auth headers — with both being secure.

The alternative (block this PR and retrofit httpHeaders first) means shipping nothing while the workaround stays broken.

@rmannibucau

Copy link
Copy Markdown
Contributor

@gnodet but don't we duplicate a feature then? since httpheaders superseeds almost everything there we shouldnt duplicate ways to do and focus on a solid solution only IMHO. maybe worth a thread on the list 🤔

@gnodet

gnodet commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

httpHeaders cannot supersede <token> for two concrete reasons that matter for a CVE fix:

  1. It doesn't decrypt values — the secret sits in plaintext in settings.xml.
  2. It doesn't scope to the repository origin — the header is sent to any repo matching the server <id>, regardless of host.

Those are exactly the properties that make httpHeaders a workaround rather than a solution. Fixing them in httpHeaders is a valid follow-up, but it's additive work — it doesn't make this PR redundant.

On the list thread: I'm fine with that if there's a genuine design question open. But the question here seems settled: credentials belong in <server>, transport config belongs in <configuration>. That's not a new principle.

@rmannibucau

Copy link
Copy Markdown
Contributor

@gnodet

It doesn't decrypt value

it does in maven 4 and we can make it happening easily in maven 3 so I don't see it as a good point to create a new feature and force everybody to migrate

It doesn't scope to the repository origin — the header is sent to any repo matching the server , regardless of host.

Literally as much as the new token, the fix you mention is not about token or not - this part is pure frontend, so this must be fixed anyway in all cases

so to summarize: we have several fixes this PR does only for a new configuration we must do for httpHeaders whatever we implement, so better to have a single configuration option with a general benefit for everybody rather than a new breaking implementation IMHO

So I still don't see a valid point to go that new path which doesnt enable anything new assuming we do the same code for what already exists since years - it is debt fix not a new feature to be concrete

@gnodet

gnodet commented Nov 30, 2026

Copy link
Copy Markdown
Contributor

Good points, and I think we're closer to agreement than it appears.

On decryption — you're right, that's doable in Maven 3 as well, happy to concede that.

On origin-scoping, though, I'd push back a little. <token> is scoped to the repository origin (scheme + host + port) at the resolver level, while httpHeaders is currently keyed only by server <id>. If a POM from a third party declares a repository with the same <id> pointing to a different host, it receives the header — which is the credential leak case. Fixing that for httpHeaders would require the same resolver-level changes this PR builds on, so it's not really "free" either way.

That said, I do agree that we should also improve httpHeaders for users who are already using it — nobody should be forced to migrate. I'd just frame it as a follow-up rather than a blocker: this PR adds the right path for new users, and a follow-up secures the existing one. Both are worth doing.

Would you be open to that framing? Happy to help with the httpHeaders improvement as a follow-up if it moves things forward.

@rmannibucau

Copy link
Copy Markdown
Contributor

Fixing that for httpHeaders would require the same resolver-level changes this PR builds on, so it's not really "free" either way.

Agree on that but we must do it anyway and once done the token proposal is way less relevant than it is right now.

I'd just frame it as a follow-up rather than a blocker: this PR adds the right path for new users, and a follow-up secures the existing one. Both are worth doing.

Hmm, I'm not sure I do agree there. Assume we did it for httpheaders - since we must do it, what does this PR brings? nothing valuable since you can already do everything with a natural semantic and configuration with httpheaders right? So why adding it to make it superseeded just after?

@cstamas

cstamas commented Nov 30, 2026 •

Copy link
Copy Markdown
Member Author

Personally:

  • I would not backport any more Maven 4 features to Maven 3.10
  • we do not force anyone to switch, we just provide a semantically clearer way to set up tokens; this PR does not alter HTTP headers in any way
  • Romain proposal is the breaking one IMO, as headers can go "anywhere" (markers use case) while now you want to limit headers to origin only; this PR allows proper token auth while keeping http headers to "go everywhere" (marker use case)
  • httpHeaders were never ever meant for what you imply Romain. Here is original blog from Brett announcing them https://brettporter.wordpress.com/2009/06/16/configuring-maven-http-connections/ What you stick to is a circumventions our users came up with, as there was no clear support for feature.

All in all, I refuse to treat httpHeaders as secret, as it would be a breaking change. They are not secret and never were secret. Token is the right place for secrets, it goes into auth context just like password and everything else is.

Also, controls for HTTP headers were already done:
https://github.com/apache/maven-resolver/blob/master/maven-resolver-api/src/main/java/org/eclipse/aether/ConfigurationProperties.java#L251-L269

And (carefully) read Javadoc of it.

FYI, I find this nitpicking very counter-productive, real waste of everyone's cycles here.

@rmannibucau

Copy link
Copy Markdown
Contributor

@cstamas some statements are wrong IMHO

we do not force anyone to switch

you do since you make token more correct from an impl perspective and the only option since you dont fix httpheaders impl

Romain proposal is the breaking one IMO, as headers can go "anywhere" (markers use case) while now you want to limit headers to origin only

agree it breaks as most fix of this kind so like everytime we'll get the fix and a toggle to disable it but we cant make it better doing the proper fix

httpHeaders were never ever meant for what you imply Romain

true or wrong I think we shouldn't care must, 1. they are used like that since years and 2. they are semantically and from a schema perspective way more correct than token proposal which is limiting, specific and potentially semantically wrong.

All in all, I refuse to treat httpHeaders as secret, as it would be a breaking change. They are not secret and never were secret. Token is the right place for secrets, it goes into auth context just like password and everything else is.

this one is 100% wrong, just have a look to gitlab doc for ex. You didn't want it to be secrets -> likely, it always hadbeen secrets -> likely. So personally I'll be on the end user side and not defend a trivial implementation choice over end user experience - and once again it is not hard to do.

Also, controls for HTTP headers were already done

Not sure the point, this is not cause we did something wrong that we can't fix it (same origin point).
This PR changes everything we must change to make it right so I dont see why you keep stepping back 🤔

FYI, I find this nitpicking very counter-productive, real waste of everyone's cycles here.

it is not nitpicking, you loose time and I prefer it versus making hundreds or thousands of projects loosing time for a forced migration we are not able to justify technically.

Settings servers now carry the bearer token in <token> (sent as
"Authorization: Bearer <token>") and any number of other token headers in
<tokenHeaders><tokenHeader><name/><value/></tokenHeader></tokenHeaders>,
for example Private-Token for GitLab, or CF-Access-Client-Id and
CF-Access-Client-Secret for Cloudflare Access. Token header values are
decrypted like passwords.

Follows the Resolver token API (apache/maven-resolver#2372): tokens are
read back from the authentication context via http.token.headers and
http.token.value.<Name>, and the legacy Authentication carries all token
headers so nothing is lost on round trip. The settings validator also
rejects Sec-* header names, which HttpURLConnection silently drops.
@cstamas cstamas changed the title [maven-3.10.x] Support token header authentication (bearer, GitLab tokens) for settings servers [maven-3.10.x] Support token authentication (bearer and custom token headers) for settings servers Nov 30, 2026

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

Following up on my earlier review — the multi-header redesign introduced in the latest commit is well-engineered.

Status of previous findings:

  • 🔖 resolverVersion set to 2.0.27-SNAPSHOT — still open (see inline comment below)

New commit assessment (d6be4588 — "Support multiple token headers per server, align with Resolver token API"):

  • Validation is thorough: RFC 9110 field-name regex blocks commas (safe for the comma-separated HTTP_TOKEN_HEADERS protocol), Sec-* check is case-insensitive (regionMatches(true, ...)), forbidden headers are lowercased before lookup — all correct.
  • Decryption covers both <token> and each <tokenHeader>/<value>, with clone isolation verified by the new DefaultSettingsDecrypterTest.
  • Round-trip tests cover single bearer, single custom header (GitLab), and multiple headers (Cloudflare) through settings → session → ArtifactRepository → RemoteRepository. The Bearer Bearer double-prefix guard is preserved.
  • Settings model versioning is correct: new elements gated at 1.4.0+, Modello bumped to 1.4.0, shipped settings.xml namespace updated.

No new code issues. The only remaining blocker is the SNAPSHOT dependency.

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread pom.xml
<jxpathVersion>1.4.0</jxpathVersion>
<resolverVersion>2.0.26</resolverVersion>
<resolverVersion>2.0.27-SNAPSHOT</resolverVersion>
<slf4jVersion>2.0.20</slf4jVersion>

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.

🔖 Tracking note (re-raised): resolverVersion is still set to 2.0.27-SNAPSHOT. Resolver PR #2372 is still open, and the maven-resolver-2.0.27 release on repository.apache.org/Maven Central is a draft — not yet available. The new APIs used by this PR (AuthenticationBuilder.addBearerToken(), addTokenHeader(), AuthenticationContext.HTTP_TOKEN_HEADERS, HTTP_TOKEN_VALUE_PREFIX) do not exist in the released 2.0.26, so this PR will not compile against any published Resolver artifact. Must wait for 2.0.27 to be released before merging.

The settings validator duplicated the Resolver HTTP transport rules for
token header names and values (RFC 9110 field name, transport-controlled
headers, Sec-*), and had to be synced on every Resolver change; the
Resolver now also rejects Proxy-* names. maven-settings-builder has no
Resolver dependency and keeps only the structural checks: missing name,
duplicate header (any letter case, including the token as Authorization),
missing value, and an Authorization token next to username or password.

DefaultRepositorySystemSessionFactory now checks each token and token
header with HttpTransporterUtils.isValidTokenHeaderName/isValidTokenValue
when it builds the repository authentication, and fails with an error
naming the server and the header, never the token. Empty values are not
sent, as the validator warns.

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

Following up on my earlier review — the validation refactoring in the latest commit (3bb9172c) is clean and well-tested.

New commit assessment ("Validate token headers with the Resolver rules instead of a copy"):

  • Removing the duplicate validation from DefaultSettingsValidator and delegating semantic checks (RFC 9110 field names, Proxy-*, Sec-*, forbidden headers, value encoding) to DefaultRepositorySystemSessionFactory.addTokens() via HttpTransporterUtils.isValidTokenHeaderName / isValidTokenValue is the right design. DRY, and sync-free: future Resolver changes (e.g., adding Proxy-* prefix rejection) are automatically picked up.
  • HttpTransporterUtils.isValidTokenHeaderName(null) returns false (the resolver method starts with name != null && ...), and isValidTokenValue(null) similarly returns false. Null safety is maintained in addTokens().
  • The DefaultSettingsValidator still catches null/empty names early with StringUtils.isEmpty(name) → ERROR, so the addTokens() path is a secondary defence. Both layers are consistent.
  • The duplicate-name condition refactoring (else if (!name.contains("${") && !names.add(...))) is semantically correct — a valid unique name causes names.add to return true, making the outer condition false → no violation; a duplicate name causes false → condition true → violation.
  • The new tests in DefaultRepositorySystemSessionFactoryTest cover empty-value suppression, Proxy-/Sec-/Host/format rejection, and value encoding for both header values and bearer tokens, including the secret-must-not-appear check in assertInvalidTokens.
  • DefaultSettingsValidatorTest is correctly trimmed: the test renamed to testValidateServerTokenHeaderNameIsRequired now only asserts structural checks (empty/null name), not semantic ones. testValidateServerTokenValue is fully removed as the value validation has moved.

Still open (re-raised from prior review): resolverVersion is 2.0.27-SNAPSHOT (see inline comment below).

This review was generated by an AI agent, Hermès on behalf of @gnodet.

Comment thread pom.xml
<cipherVersion>2.0</cipherVersion>
<jxpathVersion>1.4.0</jxpathVersion>
<resolverVersion>2.0.26</resolverVersion>
<resolverVersion>2.0.27-SNAPSHOT</resolverVersion>

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.

🔖 Tracking note (re-raised): resolverVersion is still 2.0.27-SNAPSHOT. Resolver PR apache/maven-resolver#2372 ("Add HTTP token header authentication (bearer, custom and multiple headers) to HTTP transports") is still open — 2.0.27 has not been released to Maven Central. This PR cannot be merged until the resolver release is final and this property is updated to the released version.

cstamas added a commit to apache/maven-site that referenced this pull request Nov 30, 2026
Follows apache/maven#14173 and #14179: <token> is a bearer token only,
and any number of other token headers go in
<tokenHeaders><tokenHeader><name/><value/></tokenHeader></tokenHeaders>
(GitLab Private-Token, Cloudflare Access client id and secret, ...).
Token header values can be encrypted like a password, and the documented
errors now include Proxy-* and Sec-* names and duplicate headers.

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

Introducing a new settings schema element in a micro release (3.10.x) seems risky — settings written with the new <token>/<tokenHeader> elements would be silently ignored or fail to parse on 3.9.x and earlier 3.10.x, breaking forward-compatibility expectations users have for a micro release.

#14203 is an alternative that achieves the same goals (encrypted, origin-scoped token authentication) without a schema change, by wiring the existing <configuration><httpHeaders> path into the resolver's AuthenticationBuilder. The tradeoff is a slightly more verbose user-side config, but no new XML elements in the settings schema.

Worth discussing which approach is more appropriate for a micro release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants