Skip to content

Commit 89e7b7a

Browse files
Sanitize Bearer Token in debug output (#658)
1 parent 0c18aa0 commit 89e7b7a

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

linodecli/api_request.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,6 +283,9 @@ def _print_request_debug_info(method, url, headers, body):
283283
"""
284284
print(f"> {method.__name__.upper()} {url}", file=sys.stderr)
285285
for k, v in headers.items():
286+
# If this is the Authorization header, sanitize the token
287+
if k.lower() == "authorization":
288+
v = "Bearer " + "*" * 64
286289
print(f"> {k}: {v}", file=sys.stderr)
287290
print("> Body:", file=sys.stderr)
288291
print("> ", body or "", file=sys.stderr)

tests/unit/test_api_request.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,14 @@ def test_request_debug_info(self):
4444
api_request._print_request_debug_info(
4545
SimpleNamespace(__name__="get"),
4646
"https://definitely.linode.com/",
47-
{"cool": "test"},
47+
{"cool": "test", "Authorization": "sensitiveinfo"},
4848
"cool body",
4949
)
5050

5151
output = stderr_buf.getvalue()
5252
assert "> GET https://definitely.linode.com/" in output
5353
assert "> cool: test" in output
54+
assert f"> Authorization: Bearer {'*' * 64}" in output
5455
assert "> Body:" in output
5556
assert "> cool body" in output
5657
assert "> " in output

0 commit comments

Comments
 (0)