Repository navigation
router: checked path rewrite utility and rewrite overrides - #47841
Merged
Merged
Conversation
agrawroh
requested review from
mathetake,
mattklein123 and
wbpcode
as code owners
September 29, 2026 04:11
|
CC @envoyproxy/api-shepherds: Your approval is needed for changes made to |
Moves generateNewPath and rewritePathByPrefixOrRegex out of config_impl.cc into a shared path_rewrite_utility that returns nullopt instead of asserting on a strip longer than the path and caps the result at a byte bound, so the redirect, formatter and path rewriter callers can never underflow the reserve size or throw on an oversized rewrite. Uses the utility for the dynamic modules route specifier so a module can rewrite the request path. Adds a set_prefix_rewrite callback and a RouteOverride regex_rewrite, both computed once against the current path and capped at a new max_rewritten_path_bytes, and exposes set_prefix_rewrite through the Rust SDK. Signed-off-by: Rohit Agrawal <rohit.agrawal@databricks.com>
agrawroh
force-pushed
the
der-pr4-path-rewrite-utility
branch
from
September 29, 2026 06:52
aec6293 to
15005d6
Compare
Member
Author
|
/retest |
âĶpath-rewrite-utility
mathetake
approved these changes
Sep 29, 2026
agrawroh
enabled auto-merge (squash)
September 29, 2026 18:26
chentianheng604
added a commit
to chentianheng604/envoy
that referenced
this pull request
Oct 12, 2026
In envoyproxy#47841, path rewrites were updated to check that the request path starts with the matched path before rewriting (rewritePathByPrefixOrRegex), silently dropping the rewrite if the prefix does not match. For redirect routes using path_match_policy (UriTemplateMatcher), rewritePathHeader passes the literal URI template pattern as the matched path. Because concrete request paths match the pattern rather than the literal template string, the prefix check always fails and redirect prefix rewrites silently do nothing at runtime. Forwarding routes already reject configuring prefix_rewrite together with a matcher extension (path_matcher_ != nullptr) during config ingestion. Redirect routes previously lacked this check. Add the missing validation check to RouteEntryImplBase for redirect routes: reject redirect.prefix_rewrite when path_matcher_ != nullptr with absl::InvalidArgumentError("Cannot use redirect.prefix_rewrite with path_match_policy"). Guard this validation check behind the reloadable runtime feature envoy.reloadable_features.disallow_redirect_prefix_rewrite_with_path_match_policy (enabled by default) to prevent breaking existing xDS configurations unexpectedly. Signed-off-by: Tianheng Chen <tianhengchen@google.com>
chentianheng604
added a commit
to chentianheng604/envoy
that referenced
this pull request
Oct 12, 2026
In envoyproxy#47841, path rewrites were updated to check that the request path starts with the matched path before rewriting (rewritePathByPrefixOrRegex), silently dropping the rewrite if the prefix does not match. For redirect routes using path_match_policy (UriTemplateMatcher), the literal URI template pattern is passed as the matched prefix. Because concrete request paths match the pattern rather than the literal template string, the prefix check always fails and redirect prefix rewrites silently do nothing at runtime. Forwarding routes already reject configuring prefix_rewrite together with a matcher extension during config ingestion. Redirect routes previously lacked this check. Add the missing validation check for redirect routes, rejecting configurations combining redirect.prefix_rewrite with path_match_policy during config ingestion. Guard this validation check behind the reloadable runtime feature envoy.reloadable_features.disallow_redirect_prefix_rewrite_with_path_match_policy (enabled by default) to prevent breaking existing xDS configurations unexpectedly. Signed-off-by: Tianheng Chen <tianhengchen@google.com>
chentianheng604
added a commit
to chentianheng604/envoy
that referenced
this pull request
Oct 12, 2026
In envoyproxy#47841, path rewrites were updated to check that the request path starts with the matched path before rewriting (rewritePathByPrefixOrRegex), silently dropping the rewrite if the prefix does not match. For redirect routes using path_match_policy (UriTemplateMatcher), the literal URI template pattern is passed as the matched prefix. Because concrete request paths match the pattern rather than the literal template string, the prefix check always fails and redirect prefix rewrites silently do nothing at runtime. Forwarding routes already reject configuring prefix_rewrite together with a matcher extension during config ingestion. Redirect routes previously lacked this check. Add the missing validation check for redirect routes, rejecting configurations combining redirect.prefix_rewrite with path_match_policy during config ingestion. Guard this validation check behind the reloadable runtime feature envoy.reloadable_features.disallow_redirect_prefix_rewrite_with_path_match_policy (enabled by default) to prevent breaking existing xDS configurations unexpectedly. Signed-off-by: Tianheng Chen <tianhengchen@google.com>
chentianheng604
added a commit
to chentianheng604/envoy
that referenced
this pull request
Oct 12, 2026
In envoyproxy#47841, path rewrites were updated to check that the request path starts with the matched path before rewriting (rewritePathByPrefixOrRegex), silently dropping the rewrite if the prefix does not match. For redirect routes using path_match_policy (UriTemplateMatcher), the literal URI template pattern is passed as the matched prefix. Because concrete request paths match the pattern rather than the literal template string, the prefix check always fails and redirect prefix rewrites silently do nothing at runtime. Forwarding routes already reject configuring prefix_rewrite together with a matcher extension during config ingestion. Redirect routes previously lacked this check. Add the missing validation check for redirect routes, rejecting configurations combining redirect.prefix_rewrite with path_match_policy during config ingestion. Guard this validation check behind the reloadable runtime feature envoy.reloadable_features.disallow_redirect_prefix_rewrite_with_path_match_policy (enabled by default) to prevent breaking existing xDS configurations unexpectedly. Signed-off-by: Tianheng Chen <tianhengchen@google.com>
yanavlasov
pushed a commit
that referenced
this pull request
Oct 13, 2026
Configuring a `prefix_rewrite` requires an identifiable prefix to strip and replace. Matcher extensions (`path_match_policy`, such as `UriTemplateMatcher`) match complete paths or structured patterns rather than simple prefixes, making them fundamentally incompatible with prefix rewriting. Envoy already enforces this constraint for forwarding routes: [`RouteEntryImplBase`](https://github.com/envoyproxy/envoy/blob/main/source/common/router/config_impl.cc#L769-L773) explicitly rejects `prefix_rewrite` at config ingestion time whenever a matcher extension is configured (`path_matcher_ != nullptr`). However, redirect routes (`RedirectAction`) previously missed this validation check. Historically, this gap led to runtime crashes: [`UriTemplateMatcherRouteEntryImpl::rewritePathHeader`](https://github.com/envoyproxy/envoy/blob/main/source/common/router/config_impl.cc#L1453-L1456) passed the literal template pattern as a pseudo-prefix to the redirect finalizer, causing debug assertion failures or path corruption. While [#47841](#47841) introduced a defensive runtime prefix check in [`rewritePathByPrefixOrRegex`](https://github.com/envoyproxy/envoy/blob/main/source/common/router/path_rewrite_utility.cc#L35-L39) to prevent crashes, pairing these fields remains an invalid configuration that silently fails to rewrite redirects at runtime. This change closes the validation gap by bringing redirect routes into alignment with forwarding routes: `RouteEntryImplBase` now rejects route configurations that combine `redirect.prefix_rewrite` with `path_match_policy` during config ingestion. Risk Level: Low Testing: Unit test Docs Changes: No Release Notes: Added Runtime guard: envoy.reloadable_features.disallow_redirect_prefix_rewrite_with_path_match_policy Signed-off-by: Tianheng Chen <tianhengchen@google.com>
chentianheng604
added a commit
to chentianheng604/envoy
that referenced
this pull request
Oct 19, 2026
âĶenvoyproxy#47831)" Reverts the route configuration ingestion check introduced in envoyproxy#47831 that rejected combining redirect.prefix_rewrite with path_match_policy, as existing route configurations in production still use this combination and fail config ingestion when this check is enabled. Reverting this ingestion-time rejection is safe because envoyproxy#47841 already added a defensive runtime prefix check in rewritePathByPrefixOrRegex (`source/common/router/path_rewrite_utility.cc`) that verifies the request path starts with the matched prefix before rewriting. When UriTemplateMatcherRouteEntryImpl::rewritePathHeader passes the literal URI template pattern as a pseudo-prefix during a redirect, the prefix check safely skips the rewrite as a no-op instead of triggering debug assertion failures or corrupting the redirect path. The runtime guard envoy.reloadable_features.disallow_redirect_prefix_rewrite_with_path_match_policy is retained in runtime_features.cc as a no-op so runtime configurations referencing the v1.40.0 flag continue to load without error until the flag goes through standard deprecation. Risk Level: Low Testing: Existing unit tests Docs Changes: No Release Notes: Added Signed-off-by: Tianheng Chen <tianhengchen@google.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.
Description
This PR adds a shared checked path rewrite utility for the redirect, formatter and path rewriter callers, and a prefix rewrite callback and a regex rewrite override for the dynamic modules route specifier.
Commit Message: router: checked path rewrite utility and rewrite overrides
Risk Level: Low
Testing: Added Tests
Docs Changes: Added
Release Notes: Added