Cover redirect Authorization header behavior (closes #149)#325
Closed
naorpeled wants to merge 1 commit into
Closed
Cover redirect Authorization header behavior (closes #149)#325naorpeled wants to merge 1 commit into
naorpeled wants to merge 1 commit into
Conversation
…#149) Adds regression tests confirming lambda-api's correct behavior around redirects and the Authorization header: - removeHeader('authorization') strips a response-level Authorization header before a redirect - the incoming request's Authorization header is never leaked into the redirect response The reported failure (Authorization forwarded to an S3 signed URL) is HTTP-client behavior on the follow-up request to the 3xx Location, which lambda-api cannot control. Documents this in the README redirect section. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #149 ("Redirect and Remove Authorization Header").
Investigation showed there is no library bug:
res.removeHeader('authorization')correctly removes a header from the response (lib/response.js:109).Authorizationheader onto the response.The reported failure — the
Authorizationheader being forwarded to an S3 signed URL — is caused by the HTTP client re-sending the originalAuthorizationheader when it follows the3xxredirect to the signed URL. S3 rejects requests that combine anAuthorizationheader with query-string signing. Because that happens on the client's follow-up request after lambda-api has already responded, it cannot be stripped server-side.Changes
__tests__/responses.unit.js) locking in the correct behavior:removeHeader('authorization')strips a response-levelAuthorizationheader before a redirect.Authorizationheader is never leaked into the redirect response.redirect()section explaining the client-side cause and the recommended workarounds (dropAuthorizationon cross-origin redirects, or return agetLink()URL in the body instead of redirecting).Testing
npx jest __tests__/responses.unit.js— 28/28 passing.🤖 Generated with Claude Code