Skip to content

Cover redirect Authorization header behavior (closes #149)#325

Closed
naorpeled wants to merge 1 commit into
jeremydaly:mainfrom
naorpeled:fix/issue-149-redirect-auth-header
Closed

Cover redirect Authorization header behavior (closes #149)#325
naorpeled wants to merge 1 commit into
jeremydaly:mainfrom
naorpeled:fix/issue-149-redirect-auth-header

Conversation

@naorpeled

Copy link
Copy Markdown
Collaborator

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).
  • lambda-api never copies the incoming request's Authorization header onto the response.

The reported failure — the Authorization header being forwarded to an S3 signed URL — is caused by the HTTP client re-sending the original Authorization header when it follows the 3xx redirect to the signed URL. S3 rejects requests that combine an Authorization header 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

  • Regression tests (__tests__/responses.unit.js) locking in the correct behavior:
    • removeHeader('authorization') strips a response-level Authorization header before a redirect.
    • The incoming request's Authorization header is never leaked into the redirect response.
  • README note in the redirect() section explaining the client-side cause and the recommended workarounds (drop Authorization on cross-origin redirects, or return a getLink() URL in the body instead of redirecting).

Testing

npx jest __tests__/responses.unit.js — 28/28 passing.

🤖 Generated with Claude Code

…#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>
@naorpeled naorpeled closed this Jun 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Redirect and Remove Authorization Header

1 participant