Skip to content

CLP-18389: make ImmediateResponseWriter.AppendHeader append in Envoy - #90

Merged
cainelli merged 1 commit into
mainfrom
CLP-18389
Nov 16, 2026
Merged

cainelli merged 1 commit into
mainfrom
CLP-18389

Conversation

@zeusdeux

Copy link
Copy Markdown
Contributor

ImmediateResponseWriter.AppendHeader did not append. When a filter added the same header more than once to an immediate response, for example two set-cookie headers on a redirect, Envoy kept only the last one.

Why: AppendHeader set only append_action to APPEND_IF_EXISTS_OR_ADD on the HeaderValueOption. That is the enum's zero value, so in proto3 it is never sent and Envoy cannot tell it apart from "not set". Envoy's ext_proc then falls back to the deprecated append field, which the HeaderMutation docs say "defaults to false when used in this message", and false means overwrite. So every header but the last with that name was dropped.

CommonResponseWriter already handles this by also setting the deprecated Append field to true for APPEND_IF_EXISTS_OR_ADD. ImmediateResponseWriter now does the same. SetHeader is unchanged and still overwrites.

How it was found: the China data consent redirect in ingress-sidecar sends a 302 with two set-cookie headers, one setting gyg_cn_data_consent_version and one expiring gyg_cn_data_consent. Its integration test, which runs through a real Envoy (istio proxyv2 1.31.0), only saw the second cookie. In production, users who consented would have had no version cookie and would have been sent back to the consent page in a loop. ingress-sidecar works around this for now with withEnvoyAppend in internal/pkg/filters/redirects/redirects.go, which can be removed once it uses a version of this module with this fix.

The new test checks that AppendHeader sets Append to true and that SetHeader leaves it unset. The nolint:staticcheck lines are needed because Append is deprecated, but it is still the only way to make Envoy's ext_proc append.

ImmediateResponseWriter.AppendHeader did not append. When a filter added
the same header more than once to an immediate response, for example two
set-cookie headers on a redirect, Envoy kept only the last one.

Why: AppendHeader set only append_action to APPEND_IF_EXISTS_OR_ADD on
the HeaderValueOption. That is the enum's zero value, so in proto3 it is
never sent and Envoy cannot tell it apart from "not set". Envoy's
ext_proc then falls back to the deprecated append field, which the
HeaderMutation docs say "defaults to false when used in this message",
and false means overwrite. So every header but the last with that name
was dropped.

CommonResponseWriter already handles this by also setting the deprecated
Append field to true for APPEND_IF_EXISTS_OR_ADD. ImmediateResponseWriter
now does the same. SetHeader is unchanged and still overwrites.

How it was found: the China data consent redirect in ingress-sidecar
sends a 302 with two set-cookie headers, one setting
gyg_cn_data_consent_version and one expiring gyg_cn_data_consent. Its
integration test, which runs through a real Envoy (istio proxyv2
1.31.0), only saw the second cookie. In production, users who consented
would have had no version cookie and would have been sent back to the
consent page in a loop. ingress-sidecar works around this for now with
withEnvoyAppend in internal/pkg/filters/redirects/redirects.go, which
can be removed once it uses a version of this module with this fix.

The new test checks that AppendHeader sets Append to true and that
SetHeader leaves it unset. The nolint:staticcheck lines are needed
because Append is deprecated, but it is still the only way to make
Envoy's ext_proc append.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Nov 12, 2026

Copy link
Copy Markdown

Important

  • Trigger review

This repository does not receive automatic reviews because it has fewer than 10 stars.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Central TS config (base), Organization UI (inherited); Enforced overrides: Organization
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 74d2b14b-8248-4f3d-9762-261a677d5994
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

@gyg-pr-tool
gyg-pr-tool Bot requested a review from cainelli November 12, 2026 10:18
@cainelli
cainelli merged commit 7dfbad0 into main Nov 16, 2026
7 checks passed
@cainelli
cainelli deleted the CLP-18389 branch November 16, 2026 12:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants