-
Notifications
You must be signed in to change notification settings - Fork 5.5k
formatter: print request header without query string #15711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 24 commits
f5ab2e6
dd0d834
ff3080c
dfd49a5
dcfb46b
d601684
c9218bd
0e20de5
e9a62da
afc16f7
1572fde
d17be60
436df70
bd7b0a2
190253e
6623659
e01865e
e9cb1bb
dd2eb36
c4e28c7
d3b709c
74088ea
d49a6f5
5db4589
d12ec1d
b16deb1
708c346
91d717d
52677c7
4e42d63
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| # DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py. | ||
|
|
||
| load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package") | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| api_proto_package( | ||
| deps = ["@com_github_cncf_udpa//udpa/annotations:pkg"], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| syntax = "proto3"; | ||
|
|
||
| package envoy.extensions.formatter.req_without_query.v3; | ||
|
|
||
| import "udpa/annotations/status.proto"; | ||
|
|
||
| option java_package = "io.envoyproxy.envoy.extensions.formatter.req_without_query.v3"; | ||
| option java_outer_classname = "ReqWithoutQueryProto"; | ||
| option java_multiple_files = true; | ||
| option (udpa.annotations.file_status).package_version_status = ACTIVE; | ||
|
|
||
| // [#protodoc-title: Formatter extension for printing request without query string] | ||
| // [#extension: envoy.formatter.req_without_query] | ||
|
|
||
| // ReqWithoutQuery formatter extension implements REQ_WITHOUT_QUERY command operator that | ||
| // works the same way as :ref:`REQ <config_access_log_format_req>` except that it will | ||
| // remove the query string. It is used to avoid logging any sensitive information into | ||
| // the access log. | ||
| // See :ref:`here <config_access_log>` for more information on access log configuration. | ||
|
|
||
| // %REQ_WITHOUT_QUERY(X?Y):Z% | ||
| // An HTTP request header where X is the main HTTP header, Y is the alternative one, and Z is an | ||
| // optional parameter denoting string truncation up to Z characters long. The value is taken from | ||
| // the HTTP request header named X first and if it's not set, then request header Y is used. If | ||
| // none of the headers are present '-' symbol will be in the log. | ||
|
|
||
| // Configuration for the request without query formatter. | ||
| message ReqWithoutQuery { | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,3 +28,4 @@ Extensions | |
| request_id/request_id | ||
| http/header_formatters | ||
| http/original_ip_detection | ||
| formatter/formatter | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| .. _api-v3_config_accesslog_formatters: | ||
|
|
||
| Access log formatters | ||
| ===================== | ||
|
|
||
| .. toctree:: | ||
| :glob: | ||
| :maxdepth: 2 | ||
|
|
||
| ../../extensions/formatter/*/v3/* |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| load( | ||
| "//bazel:envoy_build_system.bzl", | ||
| "envoy_cc_extension", | ||
| "envoy_cc_library", | ||
| "envoy_extension_package", | ||
| ) | ||
|
|
||
| licenses(["notice"]) # Apache 2 | ||
|
|
||
| envoy_extension_package() | ||
|
|
||
| # Access log formatter that strips query string from request path | ||
| # Public docs: docs/root/TODO(tsaarni) | ||
|
|
||
| envoy_cc_library( | ||
| name = "req_without_query_lib", | ||
| srcs = ["req_without_query.cc"], | ||
| hdrs = ["req_without_query.h"], | ||
| deps = [ | ||
| "//source/common/formatter:substitution_formatter_lib", | ||
| "//source/common/protobuf:utility_lib", | ||
| ], | ||
| ) | ||
|
|
||
| envoy_cc_extension( | ||
| name = "config", | ||
| srcs = ["config.cc"], | ||
| hdrs = ["config.h"], | ||
| deps = [ | ||
| "//envoy/registry", | ||
| "//source/extensions/formatter/req_without_query:req_without_query_lib", | ||
| "@envoy_api//envoy/extensions/formatter/req_without_query/v3:pkg_cc_proto", | ||
| ], | ||
| ) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,26 @@ | ||
| #include "source/extensions/formatter/req_without_query/config.h" | ||
|
|
||
| #include "envoy/extensions/formatter/req_without_query/v3/req_without_query.pb.h" | ||
|
|
||
| #include "source/extensions/formatter/req_without_query/req_without_query.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Formatter { | ||
|
|
||
| ::Envoy::Formatter::CommandParserPtr | ||
| ReqWithoutQueryFactory::createCommandParserFromProto(const Protobuf::Message&) { | ||
| return std::make_unique<ReqWithoutQueryCommandParser>(); | ||
| } | ||
|
|
||
| ProtobufTypes::MessagePtr ReqWithoutQueryFactory::createEmptyConfigProto() { | ||
| return std::make_unique<envoy::extensions::formatter::req_without_query::v3::ReqWithoutQuery>(); | ||
| } | ||
|
|
||
| std::string ReqWithoutQueryFactory::name() const { return "envoy.formatter.req_without_query"; } | ||
|
|
||
| REGISTER_FACTORY(ReqWithoutQueryFactory, ReqWithoutQueryFactory::CommandParserFactory); | ||
|
|
||
| } // namespace Formatter | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| #pragma once | ||
|
|
||
| #include "source/common/formatter/substitution_formatter.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Formatter { | ||
|
|
||
| class ReqWithoutQueryFactory : public ::Envoy::Formatter::CommandParserFactory { | ||
| public: | ||
| ::Envoy::Formatter::CommandParserPtr | ||
| createCommandParserFromProto(const Protobuf::Message&) override; | ||
| ProtobufTypes::MessagePtr createEmptyConfigProto() override; | ||
| std::string name() const override; | ||
| }; | ||
|
|
||
| } // namespace Formatter | ||
| } // namespace Extensions | ||
| } // namespace Envoy |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,88 @@ | ||
| #include "source/extensions/formatter/req_without_query/req_without_query.h" | ||
|
|
||
| #include <string> | ||
|
|
||
| #include "source/common/http/utility.h" | ||
| #include "source/common/protobuf/utility.h" | ||
|
|
||
| namespace Envoy { | ||
| namespace Extensions { | ||
| namespace Formatter { | ||
|
|
||
| namespace { | ||
|
|
||
| void truncate(std::string& str, absl::optional<uint32_t> max_length) { | ||
| if (!max_length) { | ||
| return; | ||
| } | ||
|
|
||
| str = str.substr(0, max_length.value()); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| ReqWithoutQuery::ReqWithoutQuery(const std::string& main_header, | ||
| const std::string& alternative_header, | ||
| absl::optional<size_t> max_length) | ||
| : main_header_(main_header), alternative_header_(alternative_header), max_length_(max_length) {} | ||
|
|
||
| absl::optional<std::string> ReqWithoutQuery::format(const Http::RequestHeaderMap& request, | ||
| const Http::ResponseHeaderMap&, | ||
| const Http::ResponseTrailerMap&, | ||
| const StreamInfo::StreamInfo&, | ||
| absl::string_view) const { | ||
| const Http::HeaderEntry* header = findHeader(request); | ||
| if (!header) { | ||
| return absl::nullopt; | ||
| } | ||
|
|
||
| std::string val = Http::Utility::stripQueryString(header->value()); | ||
| truncate(val, max_length_); | ||
|
|
||
| return val; | ||
| } | ||
|
|
||
| ProtobufWkt::Value ReqWithoutQuery::formatValue(const Http::RequestHeaderMap& request, | ||
| const Http::ResponseHeaderMap&, | ||
| const Http::ResponseTrailerMap&, | ||
| const StreamInfo::StreamInfo&, | ||
| absl::string_view) const { | ||
| const Http::HeaderEntry* header = findHeader(request); | ||
| if (!header) { | ||
| return ValueUtil::nullValue(); | ||
| } | ||
|
|
||
| std::string val = Http::Utility::stripQueryString(header->value()); | ||
| truncate(val, max_length_); | ||
| return ValueUtil::stringValue(val); | ||
| } | ||
|
|
||
| const Http::HeaderEntry* ReqWithoutQuery::findHeader(const Http::HeaderMap& headers) const { | ||
| const auto header = headers.get(main_header_); | ||
|
|
||
| if (header.empty() && !alternative_header_.get().empty()) { | ||
| const auto alternate_header = headers.get(alternative_header_); | ||
| // TODO(https://github.com/envoyproxy/envoy/issues/13454): Potentially log all header values. | ||
| return alternate_header.empty() ? nullptr : alternate_header[0]; | ||
| } | ||
|
|
||
| return header.empty() ? nullptr : header[0]; | ||
| } | ||
|
|
||
| ::Envoy::Formatter::FormatterProviderPtr | ||
| ReqWithoutQueryCommandParser::parse(const std::string& token, size_t, size_t) const { | ||
| if (absl::StartsWith(token, "REQ_WITHOUT_QUERY(")) { | ||
| std::string main_header, alternative_header; | ||
| absl::optional<size_t> max_length; | ||
|
|
||
| Envoy::Formatter::SubstitutionFormatParser::parseCommandHeader( | ||
| token, ReqWithoutQueryParamStart, main_header, alternative_header, max_length); | ||
| return std::make_unique<ReqWithoutQuery>(main_header, alternative_header, max_length); | ||
| } | ||
|
|
||
| return nullptr; | ||
| } | ||
|
|
||
| } // namespace Formatter | ||
| } // namespace Extensions | ||
| } // namespace Envoy | ||
Uh oh!
There was an error while loading. Please reload this page.