Skip to content

(api-gateway) preserve PathPrefix when replacePrefixMatch is unset#23390

Merged
sujay-hashicorp merged 1 commit intomainfrom
sujay/fix/httproute-prefix-rewrite
Mar 30, 2026
Merged

(api-gateway) preserve PathPrefix when replacePrefixMatch is unset#23390
sujay-hashicorp merged 1 commit intomainfrom
sujay/fix/httproute-prefix-rewrite

Conversation

@sujay-hashicorp
Copy link
Copy Markdown
Contributor

Description

This change fixes the HTTPRoute PathPrefix regression where Envoy strips the matched prefix even when no rewrite is configured.

The regression came from the regex rewrite workaround added for replacePrefixMatch: "/". That logic also treated an empty/unset PrefixRewrite as a signal to strip the matched prefix, which changed the default behavior for plain PathPrefix routes.

With this change:

  • PrefixRewrite == "/" still uses the regex workaround introduced for the // issue
  • PrefixRewrite == "" does not emit any rewrite
  • other non-empty rewrite values still use normal PrefixRewrite

This restores the original behavior for routes that only use PathPrefix: the full incoming request path is forwarded upstream unchanged.

Testing & Reproduction steps

Reproduction:

  1. Configure an API Gateway HTTPRoute with a PathPrefix match such as /admin
  2. Do not configure replacePrefixMatch / URLRewrite
  3. Send a request like /admin/master/console
  4. Before this change, the generated route emits regexRewrite and the upstream receives /master/console
  5. After this change, no rewrite is emitted and the upstream receives /admin/master/console

Manual/behavior verification:

  1. Confirm routes with no rewrite configured no longer emit regexRewrite
  2. Confirm routes with PrefixRewrite == "/" still emit the regex-based rewrite workaround
  3. Confirm routes with other non-empty rewrite values still emit standard PrefixRewrite

Tests run:

  • GOFLAGS=-mod=mod go test ./agent/xds -count=1 -run TestUserRewriteLogic
  • GOFLAGS=-mod=mod go test ./agent/xds -count=1 -run TestAllResourcesFromSnapshot

Relevant test updates:

  • updated xDS rewrite logic unit test
  • updated route goldens to remove unintended default regexRewrite output

Links

PR Checklist

  • updated test coverage
  • external facing docs updated
  • appropriate backport labels added
  • not a security concern

PCI review checklist

  • I have documented a clear reason for, and description of, the change I am making.

  • If applicable, I've documented a plan to revert these changes if they require more than reverting the pull request.

    Revert plan: revert this PR to restore the previous rewrite behavior.

  • If applicable, I've documented the impact of any changes to security controls.

    This change does not modify security controls.

@sujay-hashicorp sujay-hashicorp added pr/no-changelog PR does not need a corresponding .changelog entry backport/all Apply backports for all active releases per .release/versions.hcl labels Mar 25, 2026
@github-actions github-actions bot added the theme/envoy/xds Related to Envoy support label Mar 25, 2026
@sujay-hashicorp sujay-hashicorp force-pushed the sujay/fix/httproute-prefix-rewrite branch from 50123cf to 39c50a4 Compare March 25, 2026 19:55
@sujay-hashicorp sujay-hashicorp force-pushed the sujay/fix/httproute-prefix-rewrite branch from 39c50a4 to a61f1ad Compare March 25, 2026 20:04
@sujay-hashicorp sujay-hashicorp marked this pull request as ready for review March 25, 2026 20:30
@sujay-hashicorp sujay-hashicorp requested review from a team as code owners March 25, 2026 20:30
@sujay-hashicorp sujay-hashicorp merged commit 3a70987 into main Mar 30, 2026
98 checks passed
@hc-github-team-consul-core hc-github-team-consul-core added backport/1.22 Changes are backported to 1.22 backport/ent/1.18 Changes are backported to 1.18 ent backport/ent/1.21 changes are backported to 1.21 ent labels Mar 30, 2026
@hc-github-team-consul-core
Copy link
Copy Markdown
Collaborator

📣 Hi @sujay-hashicorp! a backport is missing for this PR [23390] for versions [1.18,1.21] please perform the backport manually and add the following snippet to your backport PR description:

<details>
	<summary> Overview of commits </summary>
		- <<backport commit 1>>
		- <<backport commit 2>>
		...
</details>

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backport/all Apply backports for all active releases per .release/versions.hcl backport/ent/1.18 Changes are backported to 1.18 ent backport/ent/1.21 changes are backported to 1.21 ent backport/1.22 Changes are backported to 1.22 pr/no-changelog PR does not need a corresponding .changelog entry theme/envoy/xds Related to Envoy support

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants