Skip to content

Commit aea4a25

Browse files
committed
Broaden accepted values in non-urlencoded headers
After open-telemetry#4103 we accept non url-encoded headers for OTLP. Naively this implementation only accepts digits, ascii letters, underscores (\w) and spaces. Instead broaden the accepted chars to what we accept for urlencoded values so that we accepts = to allow for base64 encoded values.
1 parent b2b133d commit aea4a25

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

opentelemetry-api/src/opentelemetry/util/re.py

+3-1
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,14 @@
3232
# A value contains a URL-encoded UTF-8 string. The encoded form can contain any
3333
# printable US-ASCII characters (0x20-0x7f) other than SP, DEL, and ",;/
3434
_VALUE_FORMAT = r"[\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
35+
# Like above with SP included
36+
_LIBERAL_VALUE_FORMAT = r"[\x20\x21\x23-\x2b\x2d-\x3a\x3c-\x5b\x5d-\x7e]*"
3537
# A key-value is key=value, with optional whitespace surrounding key and value
3638
_KEY_VALUE_FORMAT = rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_VALUE_FORMAT}{_OWS}"
3739

3840
_HEADER_PATTERN = compile(_KEY_VALUE_FORMAT)
3941
_LIBERAL_HEADER_PATTERN = compile(
40-
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}[\w ]*{_OWS}"
42+
rf"{_OWS}{_KEY_FORMAT}{_OWS}={_OWS}{_LIBERAL_VALUE_FORMAT}{_OWS}"
4143
)
4244
_DELIMITER_PATTERN = compile(r"[ \t]*,[ \t]*")
4345

opentelemetry-api/tests/util/test_re.py

+5
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ def test_parse_env_headers_liberal(self):
8989
inp = self._common_test_cases() + [
9090
# valid header value
9191
("key=value othervalue", [("key", "value othervalue")], False),
92+
(
93+
"key=value Other_Value==",
94+
[("key", "value Other_Value==")],
95+
False,
96+
),
9297
]
9398
for case_ in inp:
9499
headers, expected, warn = case_

0 commit comments

Comments
 (0)