Skip to content

fix(event-handler): keep Expires cookies and ALB headers intact - #5875

Merged
svozza merged 2 commits into
mainfrom
fix/event-handler-cookie-expires-alb-headers
Nov 1, 2026
Merged

svozza merged 2 commits into
mainfrom
fix/event-handler-cookie-expires-alb-headers

Conversation

@dreamorosi

Copy link
Copy Markdown
Contributor

Summary

Set-Cookie values were split on every comma, so a cookie with an Expires date reached the client as two broken cookies on API Gateway REST, HTTP API and ALB. On ALB, response headers were split between headers and multiValueHeaders, but ALB reads only one of the two, so some headers were always lost in either target group mode. This PR fixes both without changing any response that works today. The remaining changes from #5674 stay there for the next major version.

Changes

  • Split a Set-Cookie value only on a comma that starts another cookie (SET_COOKIE_SEPARATOR_REGEX), so Expires dates stay intact while a=1, b=2 still becomes two cookies, for REST, ALB and HTTP API results
  • Add an optional multiValueHeaders option to webResponseToProxyResult. Router.resolve() sets it from whether the incoming ALB event has multiValueHeaders. Every header then goes, unchanged, into the one field ALB reads. Without the option, the output is unchanged for direct callers
  • With multi-value headers off, keep more than one cookie in multiValueHeaders as before, since ALB can't return several cookies in that mode, and document that multi-value headers must be enabled on the target group to set more than one cookie
  • Make createTestALBEvent match a real ALB event without multi-value headers, add createTestALBMultiValueEvent, and add round-trip tests for both cookie fixes and both ALB modes, plus a test that the converter's output is unchanged when the option isn't passed

Verified on AWS (ALB in eu-west-1, Node.js 24):

  • The event contains multiValueHeaders exactly when the target group has multi-value headers enabled. The other field is absent, not empty.
  • ALB reads only the matching response field and ignores the other one completely.
  • With this change, /expires returns one Set-Cookie header with the full date, cache-control: no-store, private and content-type both arrive, and CORS preflight headers arrive, in both modes. Two cookies arrive with multi-value headers on. With them off, ALB returns no cookies, the same as on main.

Issue number: closes #5874


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Disclaimer: We value your time and bandwidth. As such, any pull requests created on non-triaged issues might not be successful.

Set-Cookie values were split on every comma, so a cookie with an Expires date
reached the client as two broken cookies on API Gateway REST, HTTP API and
ALB. Split only on a comma that starts another cookie, so cookies joined into
one value are still separated.

On ALB, headers were split between headers and multiValueHeaders, but ALB
reads only one of the two depending on the target group's multi-value headers
setting, so some headers were always lost. The router now detects the mode
from the incoming event and returns every header in the field ALB reads.
Direct callers of webResponseToProxyResult keep the previous output unless
they pass the new multiValueHeaders option.

Fixes #5874
@svozza
svozza merged commit 92d62c1 into main Nov 1, 2026
41 checks passed
@svozza
svozza deleted the fix/event-handler-cookie-expires-alb-headers branch November 1, 2026 18:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/L PRs between 100-499 LOC

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: HTTP event handler splits cookies with an Expires date and loses ALB headers

2 participants