gnodet-bot commented on code in PR #14205:
URL: https://github.com/apache/maven/pull/14205#discussion_r4750889273
##########
impl/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java:
##########
@@ -312,9 +312,19 @@ public SessionBuilder
newRepositorySessionBuilder(MavenExecutionRequest request)
if (properties != null && properties.length > 0) {
headers = new HashMap<>();
for (PlexusConfiguration property : properties) {
- headers.put(
- property.getChild("name").getValue(),
- property.getChild("value").getValue());
+ String name = property.getChild("name").getValue();
+ String value =
property.getChild("value").getValue();
+ headers.put(name, value);
+ // Wire token headers into Authentication so the
resolver enforces
+ // origin-scoping, preemptive sending, and RFC
9110 validation.
+ // Values were already decrypted by
DefaultSettingsBuilder.
+ if (name != null && value != null &&
HttpTransporterUtils.isValidTokenHeaderName(name)) {
Review Comment:
⚠️ **Missing test coverage**: the new auth-wiring path
(`addBearerToken`/`addTokenHeader`) is not exercised by any test in this PR.
The existing `httpConfigurationWithHttpHeadersTest` only asserts the
`HTTP_HEADERS` config map — it does not verify that the resulting
`Authentication` object contains the token header data.
Please add test cases for:
1. `Authorization: Bearer <token>` → verify `authBuilder` produces an auth
with bearer token
2. A custom header (e.g. `Private-Token`) → verify `addTokenHeader` path
3. A non-token header (e.g. `X-Custom: value` with a name that passes
`isValidTokenHeaderName`) → verify auth wiring
Pre-fix test validation: since there is no test in this PR verifying the new
behavior, it is not possible to confirm the fix is exercised by a
previously-failing test.
##########
impl/maven-core/src/main/java/org/apache/maven/internal/aether/DefaultRepositorySystemSessionFactory.java:
##########
@@ -312,9 +312,19 @@ public SessionBuilder
newRepositorySessionBuilder(MavenExecutionRequest request)
if (properties != null && properties.length > 0) {
headers = new HashMap<>();
for (PlexusConfiguration property : properties) {
- headers.put(
- property.getChild("name").getValue(),
- property.getChild("value").getValue());
+ String name = property.getChild("name").getValue();
+ String value =
property.getChild("value").getValue();
+ headers.put(name, value);
+ // Wire token headers into Authentication so the
resolver enforces
+ // origin-scoping, preemptive sending, and RFC
9110 validation.
+ // Values were already decrypted by
DefaultSettingsBuilder.
+ if (name != null && value != null &&
HttpTransporterUtils.isValidTokenHeaderName(name)) {
+ if ("Authorization".equalsIgnoreCase(name) &&
value.startsWith("Bearer ")) {
+
authBuilder.addBearerToken(value.substring("Bearer ".length()));
+ } else {
+ authBuilder.addTokenHeader(name, value);
Review Comment:
⚠️ **Uncaught `IllegalArgumentException` on duplicate headers**:
`AuthenticationBuilder.addBearerToken`/`addTokenHeader` both delegate to
`tokenValueKey()` which throws `IllegalArgumentException` if the same header
name is added twice (case-insensitive match):
```java
if (tokenHeaders.stream().anyMatch(header::equalsIgnoreCase)) {
throw new IllegalArgumentException("Token for HTTP header " + header + "
already added");
}
```
A settings.xml with two `Authorization` properties (or one `Authorization:
Bearer x` and one `Authorization: Token y`) triggers this exception uncaught,
crashing Maven startup with a stack trace. The fix should wrap the auth-builder
calls in a try/catch and emit a user-friendly build warning:
```suggestion
if (name != null && value != null &&
HttpTransporterUtils.isValidTokenHeaderName(name)) {
try {
if
("Authorization".equalsIgnoreCase(name) && value.startsWith("Bearer ")) {
authBuilder.addBearerToken(value.substring("Bearer ".length()));
} else {
authBuilder.addTokenHeader(name,
value);
}
} catch (IllegalArgumentException e) {
logger.warn("Skipping duplicate token
header '{}' for server '{}': {}", name, server.getId(), e.getMessage());
}
}
```
##########
pom.xml:
##########
@@ -159,7 +159,7 @@ under the License.
<plexusInterpolationVersion>1.30.0</plexusInterpolationVersion>
<plexusTestingVersion>2.2.0</plexusTestingVersion>
<plexusXmlVersion>4.2.1</plexusXmlVersion>
- <resolverVersion>2.0.26</resolverVersion>
+ <resolverVersion>2.0.27-SNAPSHOT</resolverVersion>
Review Comment:
💡 `2.0.27-SNAPSHOT` cannot ship in a Maven release. Update to `2.0.27` once
`apache/maven-resolver#2372` is released (the resolver PR was merged 2026-11-30
so the release should follow shortly).
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]