Better detection of commented out Authorization strings (ignore policy)
All checks were successful
CI / test (push) Successful in 51s
CI / test (almalinux, docker.io/library/almalinux:9, python3.11) (push) Successful in 11m5s
CI / test (debian, docker.io/library/debian:13, python3) (push) Successful in 16m28s
Lint / test (push) Successful in 45s

This commit is contained in:
Miguel Jacq 2026-07-01 15:41:38 +10:00
parent c468bc221e
commit c6e171e0f0
Signed by: mig5
GPG key ID: 03906B4110AAD3B8
2 changed files with 54 additions and 1 deletions

View file

@ -30,6 +30,46 @@ def test_authorization_headers_denied():
), data
def test_commented_authorization_headers_denied():
"""A commented-out populated Authorization header is a real (disabled)
credential and must still be refused in safe mode, regardless of the
single-line comment marker used. This is high-confidence material, so it is
scanned against the raw bytes; the pattern must not anchor to the physical
start of line, or a leading comment marker defeats it (the soft/comment-aware
tier never sees it because that tier strips comment lines)."""
pol = IgnorePolicy(dangerous=False)
for data in [
b"# Authorization: Bearer eyJhbGciOiJIUzI1NiIs\n",
b"#Authorization: Bearer eyJhbGciOiJIUzI1NiIs\n",
b"; Authorization: Basic dXNlcjpwYXNzd29yZA==\n",
b"// Authorization: Digest abc123\n",
b" //Authorization: Bearer abc123\n",
b"* Authorization: Bearer abc123\n", # block-comment continuation line
b"\t# Authorization: Token abc123\n",
b"dnl Authorization: Bearer abc123\n", # m4-style comment
b"-- Proxy-Authorization: Basic abc123\n", # sql/lua-style comment
b"REM Authorization: Bearer abc123\n", # bat-style comment
b"# Proxy-Authorization: Bearer xyz\n",
]:
assert (
pol._content_deny_reason("/etc/svc/app.conf", data) == "sensitive_content"
), data
def test_authorization_header_word_not_false_positive():
"""The Authorization-header pattern must not fire on benign prose mentions,
a non-scheme value, or an identifier that merely ends in 'authorization'."""
pol = IgnorePolicy(dangerous=False)
for data in [
b"# how to set the authorization header is documented elsewhere\n",
b"authorization: required\n",
b"my_authorization: bearer x\n",
]:
assert pol._content_deny_reason("/etc/svc/app.conf", data) is None, data
def test_benign_urls_not_false_positive():
pol = IgnorePolicy(dangerous=False)
for data in [