gnodet opened a new pull request, #14203:
URL: https://github.com/apache/maven/pull/14203

   ## Summary
   
   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:
   
   ```xml
   <!-- 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)
   
   ---
   _Hermes Agent (Claude Sonnet) on behalf of Guillaume Nodet_
   


-- 
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]

Reply via email to