cstamas opened a new pull request, #2374:
URL: https://github.com/apache/maven-resolver/pull/2374

   Two fixes for how HTTP transports handle credentials.
   
   ### 1. URL transport: never offer credentials to another origin
   
   On a 401, the URL transporter retries with Basic credentials. When 
`HTTP_ORIGIN_SCOPED_HEADERS` was disabled, it also did that for a 
**cross-origin redirect target**, sending the repository's username and 
password to another host.
   
   Credentials are authentication, not configured headers. Apache (host-scoped 
credentials provider), JDK (scoped authenticator) and Jetty (URI-scoped 
authentication store) already keep them on the repository origin regardless of 
that setting. The URL transporter now does too: the 401 retry with credentials 
happens only when the target is the repository origin.
   
   **Test:** the shared 
`testGet_Redirect_OriginScopedAuthenticationNotReplayed` in 
`HttpTransporterTest` now runs with origin-scoped headers on and off, on all 
four transports. With origin scoping off, it failed only for URL before this 
fix.
   
   ### 2. Apache transport: clear authentication contexts when construction 
fails
   
   The first `AuthenticationContext` lookup (SSL context and hostname verifier, 
in `ConnMgrConfig`) fills the context with **all** authentication data, 
including decrypted secrets such as the password (`SecretAuthentication` puts a 
decrypted `char[]` copy that only `AuthenticationContext.close()` zeroes). If 
the constructor failed after that, for example on an unsupported 
`aether.transport.apache.retryHandler.name`, the transporter was never created, 
so it was never closed and the decrypted secrets stayed in memory. JDK, Jetty 
and URL open their contexts with try-with-resources, so they are not affected.
   
   **Fix:** a new `ApacheTransporter.create(...)` factory method opens both 
contexts, passes them to the (now private) constructor, and closes them if 
construction throws. The factory calls `create(...)`. This avoids re-indenting 
the ~170-line constructor.
   
   **Test:** 
`ApacheTransporterTest#testAuthenticationContextClearedWhenConstructionFails`. 
A custom `Authentication` puts fresh `char[]` copies like 
`SecretAuthentication` does, the constructor fails, and the test checks that 
every copy is zeroed. It failed before this fix.
   
   ---
   
   To make clear that you license your contribution under
   the [Apache License Version 2.0, January 
2004](https://www.apache.org/licenses/LICENSE-2.0)
   check one of the following:
   
   - [x] I hereby declare this contribution to be licensed under the [Apache 
License Version 2.0, January 2004](https://www.apache.org/licenses/LICENSE-2.0)
   - [ ] I hereby declare that I have filed an [Apache Individual Contributor 
License Agreement](https://www.apache.org/licenses/icla.pdf).
   


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