Skip to content

Commit ea7ad6e

Browse files
astuyvedatadog-official[bot]rithikanarayan
authored
Fix case-insensitive header redaction (#685)
* Normalize header redaction keys Co-authored-by: astuyve <astuyve@gmail.com> * feat: fmt * less than 3.19.0 --------- Co-authored-by: datadog-official[bot] <214633350+datadog-official[bot]@users.noreply.github.com> Co-authored-by: Rithika Narayan <rithika.narayan@datadoghq.com>
1 parent 8c28b41 commit ea7ad6e

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

datadog_lambda/tag_object.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,6 @@ def _should_try_string(obj):
6262

6363
def _redact_val(k, v):
6464
split_key = k.split(".").pop() or k
65-
if split_key in redactable_keys:
65+
if split_key.lower() in redactable_keys:
6666
return "redacted"
6767
return v

tests/test_tag_object.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,13 +73,14 @@ def test_tag_object_max_depth_0(self):
7373
"vals": [{"thingOne": 1}, {"thingTwo": 2}],
7474
}
7575
spanMock = MagicMock()
76+
expected_value = str(payload)
7677

7778
tag_object(spanMock, "function.request", payload)
7879
spanMock.set_tag.assert_has_calls(
7980
[
8081
call(
8182
"function.request",
82-
"{'hello': 'world', 'level1': {'level2_dict': {'level3': 3}, 'level2_list': [None, True, 'nice', {'l3': 'v3'}], 'level2_bool': True, 'level2_int': 2}, 'vals': [{'thingOne': 1}, {'thingTwo': 2}]}",
83+
expected_value,
8384
),
8485
],
8586
True,
@@ -105,6 +106,18 @@ def test_redacted_tag_object(self):
105106
True,
106107
)
107108

109+
def test_redacted_tag_object_case_insensitive(self):
110+
payload = {
111+
"Authorization": "secret",
112+
"headers": {"X-AUTHORIZATION": "another"},
113+
}
114+
spanMock = MagicMock()
115+
tag_object(spanMock, "function.request", payload)
116+
spanMock.set_tag.assert_any_call("function.request.Authorization", "redacted")
117+
spanMock.set_tag.assert_any_call(
118+
"function.request.headers.X-AUTHORIZATION", "redacted"
119+
)
120+
108121
def test_json_tag_object(self):
109122
payload = {
110123
"token": "world",

0 commit comments

Comments
 (0)