-
Notifications
You must be signed in to change notification settings - Fork 851
Add support for more PP fields #12864
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
base: master
Are you sure you want to change the base?
Changes from all commits
1dbb5f4
e74d912
ab3f1d4
7afd3c5
71f2fd5
78eeeef
214207a
8296706
2aa259f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /** @file | ||
|
|
||
| This plugin counts the number of times every header has appeared. | ||
| Maintains separate counts for client and origin headers. | ||
|
|
||
| @section license License | ||
|
|
||
| Licensed to the Apache Software Foundation (ASF) under one | ||
| or more contributor license agreements. See the NOTICE file | ||
| distributed with this work for additional information | ||
| regarding copyright ownership. The ASF licenses this file | ||
| to you under the Apache License, Version 2.0 (the | ||
| "License"); you may not use this file except in compliance | ||
| with the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| */ | ||
|
|
||
| #include <ts/ts.h> | ||
|
|
||
| DbgCtl dbg_ctl{"custom_logfield"}; | ||
|
|
||
| char PLUGIN_NAME[] = "header_freq"; | ||
| char VENDOR_NAME[] = "Apache Software Foundation"; | ||
| char SUPPORT_EMAIL[] = "dev@trafficserver.apache.org"; | ||
|
|
||
| int | ||
| marshal_function(TSHttpTxn txnp, char *) | ||
| { | ||
| Dbg(dbg_ctl, "Marshaling a custom field"); | ||
| TSAssert(txnp); | ||
| return 0; | ||
| } | ||
|
|
||
| int | ||
| unmarshal_function(char **, char *, int) | ||
| { | ||
| Dbg(dbg_ctl, "Unarshaling a custom field"); | ||
| return 0; | ||
| } | ||
|
|
||
| int | ||
| lifecycle_event_handler(TSCont /* contp ATS_UNUSED */, TSEvent event, void * /* edata ATS_UNUSED */) | ||
| { | ||
| TSAssert(event == TS_EVENT_LIFECYCLE_LOG_INITIAZLIED); | ||
|
|
||
| Dbg(dbg_ctl, "Registering a custom field"); | ||
| TSLogFieldRegister("custom log field", "cstm", TS_LOG_TYPE_STRING, marshal_function, unmarshal_function); | ||
|
|
||
| return TS_SUCCESS; | ||
| } | ||
|
|
||
| void | ||
| TSPluginInit(int /* argc ATS_UNUSED */, const char ** /* argv ATS_UNUSED */) | ||
| { | ||
| Dbg(dbg_ctl, "Initializing plugin"); | ||
|
|
||
| TSPluginRegistrationInfo info = {PLUGIN_NAME, VENDOR_NAME, SUPPORT_EMAIL}; | ||
| if (TSPluginRegister(&info) != TS_SUCCESS) { | ||
| TSError("[%s](%s) Plugin registration failed. \n", PLUGIN_NAME, __FUNCTION__); | ||
| } | ||
|
|
||
| TSCont cont = TSContCreate(lifecycle_event_handler, nullptr); | ||
| TSLifecycleHookAdd(TS_LIFECYCLE_LOG_INITIAZLIED_HOOK, cont); | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -547,6 +547,84 @@ ProxyProtocol::get_tlv(const uint8_t tlvCode) const | |||||||||||||||||||||||||||||||||
| return std::nullopt; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| /* | ||||||||||||||||||||||||||||||||||
| * PP2_TYPE_SSL | ||||||||||||||||||||||||||||||||||
| * struct pp2_tlv_ssl { | ||||||||||||||||||||||||||||||||||
| * uint8_t client; | ||||||||||||||||||||||||||||||||||
| * uint32_t verify; | ||||||||||||||||||||||||||||||||||
| * struct pp2_tlv sub_tlv[0]; | ||||||||||||||||||||||||||||||||||
| * }; | ||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| std::optional<std::string_view> | ||||||||||||||||||||||||||||||||||
| ProxyProtocol::_get_tlv_ssl_subtype(uint8_t subtype) const | ||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||
| if (auto v = tlv.find(PP2_TYPE_SSL); v != tlv.end() && v->second.length() != 0) { | ||||||||||||||||||||||||||||||||||
| auto ssl = v->second; | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Is the client connected over TLS | ||||||||||||||||||||||||||||||||||
| if ((ssl.data()[0] & 0x01) == 0) { | ||||||||||||||||||||||||||||||||||
| // Not over TLS | ||||||||||||||||||||||||||||||||||
| return std::nullopt; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| if (ssl.length() < 5) { | ||||||||||||||||||||||||||||||||||
| return std::nullopt; | ||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| // Find the given subtype | ||||||||||||||||||||||||||||||||||
| uint16_t len = ssl.length(); | ||||||||||||||||||||||||||||||||||
| const char *p = ssl.data() + 5; // Skip client (uint8_t) + verify (uint32_t) | ||||||||||||||||||||||||||||||||||
| const char *end = ssl.data() + len; | ||||||||||||||||||||||||||||||||||
| while (p != end) { | ||||||||||||||||||||||||||||||||||
|
Comment on lines
575
to
579
|
||||||||||||||||||||||||||||||||||
| // Find the given subtype | |
| uint16_t len = ssl.length(); | |
| const char *p = ssl.data() + 5; // Skip client (uint8_t) + verify (uint32_t) | |
| const char *end = p + len + 1; | |
| while (p != end) { | |
| // The SSL TLV must contain at least the client (uint8_t) and verify (uint32_t) fields. | |
| if (ssl.length() < 5) { | |
| Dbg(dbg_ctl_proxyprotocol_v2, "SSL TLV too short: %zu bytes (expected at least 5)", static_cast<size_t>(ssl.length())); | |
| return std::nullopt; | |
| } | |
| // Find the given subtype | |
| uint16_t len = ssl.length(); | |
| const char *p = ssl.data() + 5; // Skip client (uint8_t) + verify (uint32_t) | |
| const char *end = ssl.data() + len; // End of the SSL TLV value | |
| while (p < end) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
_get_tlv_ssl_subtype() reads
ssl.data()[0]and skips 5 bytes without verifying the TLV value is at least 5 bytes long. If PP2_TYPE_SSL is present but truncated/malformed, this will access beyond the string_view. Add assl.size() >= 5(and preferably>= 5 + 3before parsing sub-TLVs) guard before dereferencing and parsing.