Skip to content

Commit 273971b

Browse files
daddykotexKriechi
authored andcommitted
prevent sensitive header value being logged
1 parent 7b9a7fc commit 273971b

File tree

2 files changed

+11
-6
lines changed

2 files changed

+11
-6
lines changed

CHANGELOG.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ dev
1414
- Support for Python 3.14 has been added.
1515
- Support for PyPy 3.11 has been added.
1616

17-
1817
**Bugfixes**
1918

20-
-
19+
- Prevent sensitive headers from being leaked
2120

2221
4.1.0 (2025-01-22)
2322
------------------

src/hpack/hpack.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -284,16 +284,22 @@ def encode(self,
284284
def add(self, to_add: tuple[bytes, bytes], sensitive: bool, huffman: bool = False) -> bytes:
285285
"""
286286
Serializes a header key-value tuple.
287+
288+
When sensitive is True, the header will not be added to the header table,
289+
furthermore, the header value will be redacted in debug logs, as "SENSITIVE_REDACTED",
290+
to prevent accidental exposure of sensitive information.
287291
"""
292+
name, value = to_add
293+
294+
display_value = value if not sensitive else b"SENSITIVE_REDACTED"
288295
log.debug(
289-
"Adding %s to the header table, sensitive:%s, huffman:%s",
290-
to_add,
296+
"Adding %s=%s to the header table, sensitive:%s, huffman:%s",
297+
name,
298+
display_value,
291299
sensitive,
292300
huffman,
293301
)
294302

295-
name, value = to_add
296-
297303
# Set our indexing mode
298304
indexbit = INDEX_INCREMENTAL if not sensitive else INDEX_NEVER
299305

0 commit comments

Comments
 (0)