Skip to content

Commit 1ef5634

Browse files
authored
router: remove preserve_query_string_in_path_redirects (#15335)
Fixes #14648 Risk Level: Low Testing: Existing tests Docs Changes: N/A Release Notes: Added Platform Specific Features: N/A Fixes #14648 Signed-off-by: Matt Klein <mklein@lyft.com>
1 parent 18453fa commit 1ef5634

File tree

7 files changed

+22
-105
lines changed

7 files changed

+22
-105
lines changed

docs/root/version_history/current.rst

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ Removed Config or Runtime
9797
* http: removed legacy date header overwriting logic and runtime guard `envoy.reloadable_features.preserve_upstream_date deprecation`.
9898
* listener: removed legacy runtime guard `envoy.reloadable_features.listener_in_place_filterchain_update`.
9999
* router: removed `envoy.reloadable_features.consume_all_retry_headers` and legacy code path.
100+
* router: removed `envoy.reloadable_features.preserve_query_string_in_path_redirects` and legacy code path.
100101

101102
New Features
102103
------------

source/common/router/config_impl.cc

+21-37
Original file line numberDiff line numberDiff line change
@@ -334,8 +334,6 @@ RouteEntryImplBase::RouteEntryImplBase(const VirtualHostImpl& vhost,
334334
: ""),
335335
path_redirect_(route.redirect().path_redirect()),
336336
path_redirect_has_query_(path_redirect_.find('?') != absl::string_view::npos),
337-
enable_preserve_query_in_path_redirects_(Runtime::runtimeFeatureEnabled(
338-
"envoy.reloadable_features.preserve_query_string_in_path_redirects")),
339337
https_redirect_(route.redirect().https_redirect()),
340338
using_new_timeouts_(route.route().has_max_stream_duration()),
341339
prefix_rewrite_redirect_(route.redirect().prefix_rewrite()),
@@ -475,7 +473,7 @@ RouteEntryImplBase::RouteEntryImplBase(const VirtualHostImpl& vhost,
475473
regex_rewrite_redirect_substitution_ = rewrite_spec.substitution();
476474
}
477475

478-
if (enable_preserve_query_in_path_redirects_ && path_redirect_has_query_ && strip_query_) {
476+
if (path_redirect_has_query_ && strip_query_) {
479477
ENVOY_LOG(warn,
480478
"`strip_query` is set to true, but `path_redirect` contains query string and it will "
481479
"not be stripped: {}",
@@ -759,44 +757,30 @@ std::string RouteEntryImplBase::newPath(const Http::RequestHeaderMap& headers) c
759757
}
760758

761759
std::string final_path_value;
762-
if (enable_preserve_query_in_path_redirects_) {
763-
if (!path_redirect_.empty()) {
764-
// The path_redirect query string, if any, takes precedence over the request's query string,
765-
// and it will not be stripped regardless of `strip_query`.
766-
if (path_redirect_has_query_) {
767-
final_path = path_redirect_.c_str();
768-
} else {
769-
const absl::string_view current_path = headers.getPathValue();
770-
const size_t path_end = current_path.find('?');
771-
const bool current_path_has_query = path_end != absl::string_view::npos;
772-
if (current_path_has_query) {
773-
final_path_value = path_redirect_;
774-
final_path_value.append(current_path.data() + path_end, current_path.length() - path_end);
775-
final_path = final_path_value;
776-
} else {
777-
final_path = path_redirect_.c_str();
778-
}
779-
}
760+
if (!path_redirect_.empty()) {
761+
// The path_redirect query string, if any, takes precedence over the request's query string,
762+
// and it will not be stripped regardless of `strip_query`.
763+
if (path_redirect_has_query_) {
764+
final_path = path_redirect_.c_str();
780765
} else {
781-
final_path = headers.getPathValue();
782-
}
783-
if (!path_redirect_has_query_ && strip_query_) {
784-
const size_t path_end = final_path.find('?');
785-
if (path_end != absl::string_view::npos) {
786-
final_path = final_path.substr(0, path_end);
766+
const absl::string_view current_path = headers.getPathValue();
767+
const size_t path_end = current_path.find('?');
768+
const bool current_path_has_query = path_end != absl::string_view::npos;
769+
if (current_path_has_query) {
770+
final_path_value = path_redirect_;
771+
final_path_value.append(current_path.data() + path_end, current_path.length() - path_end);
772+
final_path = final_path_value;
773+
} else {
774+
final_path = path_redirect_.c_str();
787775
}
788776
}
789777
} else {
790-
if (!path_redirect_.empty()) {
791-
final_path = path_redirect_.c_str();
792-
} else {
793-
final_path = headers.getPathValue();
794-
if (strip_query_) {
795-
const size_t path_end = final_path.find("?");
796-
if (path_end != absl::string_view::npos) {
797-
final_path = final_path.substr(0, path_end);
798-
}
799-
}
778+
final_path = headers.getPathValue();
779+
}
780+
if (!path_redirect_has_query_ && strip_query_) {
781+
const size_t path_end = final_path.find('?');
782+
if (path_end != absl::string_view::npos) {
783+
final_path = final_path.substr(0, path_end);
800784
}
801785
}
802786

source/common/router/config_impl.h

-1
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,6 @@ class RouteEntryImplBase : public RouteEntry,
812812
const std::string port_redirect_;
813813
const std::string path_redirect_;
814814
const bool path_redirect_has_query_;
815-
const bool enable_preserve_query_in_path_redirects_;
816815
const bool https_redirect_;
817816
const bool using_new_timeouts_;
818817
const std::string prefix_rewrite_redirect_;

source/common/runtime/runtime_features.cc

-1
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,6 @@ constexpr const char* runtime_features[] = {
7878
"envoy.reloadable_features.http2_skip_encoding_empty_trailers",
7979
"envoy.reloadable_features.overload_manager_disable_keepalive_drain_http2",
8080
"envoy.reloadable_features.prefer_quic_kernel_bpf_packet_routing",
81-
"envoy.reloadable_features.preserve_query_string_in_path_redirects",
8281
"envoy.reloadable_features.remove_forked_chromium_url",
8382
"envoy.reloadable_features.require_ocsp_response_for_must_staple_certs",
8483
"envoy.reloadable_features.stop_faking_paths",

test/common/router/BUILD

-1
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,6 @@ envoy_cc_benchmark_binary(
455455
"//source/common/router:config_lib",
456456
"//test/mocks/server:instance_mocks",
457457
"//test/mocks/stream_info:stream_info_mocks",
458-
"//test/test_common:test_runtime_lib",
459458
"//test/test_common:utility_lib",
460459
"@envoy_api//envoy/config/route/v3:pkg_cc_proto",
461460
],

test/common/router/config_impl_speed_test.cc

-4
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66

77
#include "test/mocks/server/instance.h"
88
#include "test/mocks/stream_info/mocks.h"
9-
#include "test/test_common/test_runtime.h"
109
#include "test/test_common/utility.h"
1110

1211
#include "benchmark/benchmark.h"
@@ -88,9 +87,6 @@ static RouteConfiguration genRouteConfig(benchmark::State& state,
8887
*/
8988
static void bmRouteTableSize(benchmark::State& state, RouteMatch::PathSpecifierCase match_type) {
9089
// Setup router for benchmarking.
91-
TestScopedRuntime scoped_runtime;
92-
Runtime::LoaderSingleton::getExisting()->mergeValues(
93-
{{"envoy.reloadable_features.preserve_query_string_in_path_redirects", "false"}});
9490
Api::ApiPtr api = Api::createApiForTest();
9591
NiceMock<Server::Configuration::MockServerFactoryContext> factory_context;
9692
NiceMock<Envoy::StreamInfo::MockStreamInfo> stream_info;

test/common/router/config_impl_test.cc

-61
Original file line numberDiff line numberDiff line change
@@ -6711,67 +6711,6 @@ TEST_F(RouteConfigurationV2, RedirectRegexRewrite) {
67116711
}
67126712
}
67136713

6714-
TEST_F(RouteConfigurationV2, PathRedirectQueryNotPreserved) {
6715-
TestScopedRuntime scoped_runtime;
6716-
Runtime::LoaderSingleton::getExisting()->mergeValues(
6717-
{{"envoy.reloadable_features.preserve_query_string_in_path_redirects", "false"}});
6718-
6719-
std::string yaml = R"EOF(
6720-
virtual_hosts:
6721-
- name: redirect
6722-
domains: [redirect.lyft.com]
6723-
routes:
6724-
- match: { path: "/path/redirect/"}
6725-
redirect: { path_redirect: "/new/path-redirect/" }
6726-
- match: { path: "/path/redirect/strip-query/true"}
6727-
redirect: { path_redirect: "/new/path-redirect/", strip_query: "true" }
6728-
- match: { path: "/path/redirect/query"}
6729-
redirect: { path_redirect: "/new/path-redirect?foo=1" }
6730-
- match: { path: "/path/redirect/query-with-strip"}
6731-
redirect: { path_redirect: "/new/path-redirect?foo=2", strip_query: "true" }
6732-
)EOF";
6733-
6734-
TestConfigImpl config(parseRouteConfigurationFromYaml(yaml), factory_context_, true);
6735-
EXPECT_EQ(nullptr, config.route(genRedirectHeaders("www.foo.com", "/foo", true, true), 0));
6736-
6737-
{
6738-
Http::TestRequestHeaderMapImpl headers =
6739-
genRedirectHeaders("redirect.lyft.com", "/path/redirect/?lang=eng&con=US", true, false);
6740-
EXPECT_EQ("https://redirect.lyft.com/new/path-redirect/",
6741-
config.route(headers, 0)->directResponseEntry()->newPath(headers));
6742-
}
6743-
{
6744-
Http::TestRequestHeaderMapImpl headers = genRedirectHeaders(
6745-
"redirect.lyft.com", "/path/redirect/strip-query/true?lang=eng&con=US", true, false);
6746-
EXPECT_EQ("https://redirect.lyft.com/new/path-redirect/",
6747-
config.route(headers, 0)->directResponseEntry()->newPath(headers));
6748-
}
6749-
{
6750-
Http::TestRequestHeaderMapImpl headers =
6751-
genRedirectHeaders("redirect.lyft.com", "/path/redirect/query", true, false);
6752-
EXPECT_EQ("https://redirect.lyft.com/new/path-redirect?foo=1",
6753-
config.route(headers, 0)->directResponseEntry()->newPath(headers));
6754-
}
6755-
{
6756-
Http::TestRequestHeaderMapImpl headers =
6757-
genRedirectHeaders("redirect.lyft.com", "/path/redirect/query?bar=1", true, false);
6758-
EXPECT_EQ("https://redirect.lyft.com/new/path-redirect?foo=1",
6759-
config.route(headers, 0)->directResponseEntry()->newPath(headers));
6760-
}
6761-
{
6762-
Http::TestRequestHeaderMapImpl headers =
6763-
genRedirectHeaders("redirect.lyft.com", "/path/redirect/query-with-strip", true, false);
6764-
EXPECT_EQ("https://redirect.lyft.com/new/path-redirect?foo=2",
6765-
config.route(headers, 0)->directResponseEntry()->newPath(headers));
6766-
}
6767-
{
6768-
Http::TestRequestHeaderMapImpl headers = genRedirectHeaders(
6769-
"redirect.lyft.com", "/path/redirect/query-with-strip?bar=1", true, false);
6770-
EXPECT_EQ("https://redirect.lyft.com/new/path-redirect?foo=2",
6771-
config.route(headers, 0)->directResponseEntry()->newPath(headers));
6772-
}
6773-
}
6774-
67756714
// Test to check Strip Query for redirect messages
67766715
TEST_F(RouteConfigurationV2, RedirectStripQuery) {
67776716
std::string yaml = R"EOF(

0 commit comments

Comments
 (0)