Skip to content

Commit eafebf9

Browse files
fix(traces): reject ids with a trailing newline
`$` matches before a final newline, so the length check plus `match` accepted a 31-hex trace id or 15-hex span id followed by `\n`. Use `fullmatch` so the validators enforce their contract.
1 parent 9ffa2a5 commit eafebf9

2 files changed

Lines changed: 3 additions & 1 deletion

File tree

posthog/test/tracing/test_ids.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ class TestValidation:
5555
("abc", False),
5656
("4BF92F3577B34DA6A3CE929D0E0E4736", False),
5757
("zz" * 16, False),
58+
("a" * 31 + "\n", False),
5859
(12345, False),
5960
(None, False),
6061
],
@@ -68,6 +69,7 @@ def test_is_valid_trace_id(self, value, expected):
6869
("00f067aa0ba902b7", True),
6970
("0" * 16, False),
7071
("4bf92f3577b34da6a3ce929d0e0e4736", False),
72+
("a" * 15 + "\n", False),
7173
],
7274
)
7375
def test_is_valid_span_id(self, value, expected):

posthog/tracing/_ids.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ def _is_valid_hex_id(value: object, length: int, invalid: str) -> bool:
3939
isinstance(value, str)
4040
and len(value) == length
4141
and value != invalid
42-
and _HEX_RE.match(value) is not None
42+
and _HEX_RE.fullmatch(value) is not None
4343
)
4444

4545

0 commit comments

Comments
 (0)