Strip "authorization" header before proxying to s3#1222
Conversation
Including "Authorization" header when making S3 proxy can result in an exception if using presignedUrl as aws detect 2 possible auth mechanisms. This strips from outgoing proxy request only, allowing the current auth header to be used for validation
Use TransformResponseAsync with cancellation token as existing method is obsolete. Use .Append() rather than .Add() for safety
Previous code hardcoded this to true. The behaviour is unchanged as yarp currently only returns true. This method currently runs synchronously to await doesn't alter any behaviour but avoids issues in the future if we update Yarp and behaviour changes
|
Note As discussed internally with @tomcrane and @JackLewis-digirati , will merge this without review due to team annual leave. Confirming I used Claude Opus 4.8 for review, which didn't note any issues. Will drop review below as it confirms changes made to Yarp
|
What does this change?
Fixes #1219
Main change is stripping "Authorization" header before proxying to S3. Inclusion of this was breaking streaming when using presignedUrls as s3 detected 2 authmechanisms.
This strips the header from the outgoing proxy request - yarp will copy all headers then we strip out "authorization", this will still handle incoming auth header for restricted content.
Made a small tweak to Yarp PathRewriteTransformer as part of change, no behaviour change. Initially this was to fix warnings but then noticed that a possible change in how yarp works could alter behaviour. The change was
TransformResponseAsyncand store the response, rather than always returningtrue.TransformResponseAsyncoverload that accepts cancellation token, rather than current overload as that's obsolete.The "Optionally handle this to not expose the full s3 error." step in issue was not tackled here, we can look to do this in future if required.