Fix overenthusiastic match on pass
Some checks failed
CI / test (push) Successful in 50s
CI / test (almalinux, docker.io/library/almalinux:9, python3.11) (push) Failing after 2m42s
CI / test (debian, docker.io/library/debian:13, python3) (push) Failing after 3m12s
Lint / test (push) Successful in 1m13s

This commit is contained in:
Miguel Jacq 2026-06-30 11:34:37 +10:00
parent 4146aa997b
commit 3781d602a1
Signed by: mig5
GPG key ID: 03906B4110AAD3B8
2 changed files with 33 additions and 13 deletions

View file

@ -103,23 +103,24 @@ HIGH_CONFIDENCE_SECRET_PATTERNS = [
# framing, so it is scanned on raw bytes. # framing, so it is scanned on raw bytes.
re.compile( re.compile(
rb"""(?ix) rb"""(?ix)
(^|[^A-Za-z0-9]) (^|[^A-Za-z0-9_.-])
[\"']? [\"']?
( (
[A-Za-z0-9_.-]* (?:[A-Za-z0-9]+[_.-])*
( (
password|passwd|passphrase|pass|pin|pwd| password|passwd|passphrase|pwd|
token|auth[_-]?token|access[_-]?token|refresh[_-]?token| token|auth[_.-]?token|access[_.-]?token|refresh[_.-]?token|
secret|client[_-]?secret|secret[_-]?key| secret|client[_.-]?secret|secret[_.-]?key|
api[_-]?key|access[_-]?key|private[_-]?key| api[_.-]?key|access[_.-]?key|private[_.-]?key|
credential|credentials| credential|credentials|
aws[_-]?access[_-]?key[_-]?id|aws[_-]?secret[_-]?access[_-]?key| aws[_.-]?access[_.-]?key[_.-]?id|aws[_.-]?secret[_.-]?access[_.-]?key|
azure[_-]?client[_-]?secret|azure[_-]?tenant[_-]?id|azure[_-]?client[_-]?id| azure[_.-]?client[_.-]?secret|azure[_.-]?tenant[_.-]?id|azure[_.-]?client[_.-]?id|
google[_-]?application[_-]?credentials|gcp[_-]?service[_-]?account| google[_.-]?application[_.-]?credentials|gcp[_.-]?service[_.-]?account|
service[_-]?account[_-]?key| service[_.-]?account[_.-]?key|
session_key session[_.-]?key|
pass|pin
) )
[A-Za-z0-9_.-]* (?:[_.-][A-Za-z0-9]+)*
) )
[\"']? [\"']?
\s*[:=] \s*[:=]
@ -141,7 +142,7 @@ SENSITIVE_CONTENT_PATTERNS = [
# heuristic and the only one tolerated inside comments, because stock config # heuristic and the only one tolerated inside comments, because stock config
# files legitimately ship value-less commented hints (e.g. "# token"). # files legitimately ship value-less commented hints (e.g. "# token").
re.compile( re.compile(
rb"(?i)\b(pass|passwd|password|passphrase|token|secret|" rb"(?i)\b(pass|pin|passwd|password|passphrase|token|secret|"
rb"credentials?|api[_-]?key)\b" rb"credentials?|api[_-]?key)\b"
), ),
] ]

View file

@ -51,6 +51,7 @@ def test_bare_word_password_denied():
b"machine api.example.com login bob password s3cret\n", b"machine api.example.com login bob password s3cret\n",
b"passphrase mysecretphrase\n", b"passphrase mysecretphrase\n",
b"credentials /run/creds/db\n", b"credentials /run/creds/db\n",
b"pin 1234\n",
]: ]:
assert ( assert (
pol._content_deny_reason("/etc/svc.conf", data) == "sensitive_content" pol._content_deny_reason("/etc/svc.conf", data) == "sensitive_content"
@ -63,11 +64,29 @@ def test_ppp_secrets_paths_denied():
assert pol._path_deny_reason(p) == "denied_path", p assert pol._path_deny_reason(p) == "denied_path", p
def test_short_credential_key_components_denied():
pol = IgnorePolicy(dangerous=False)
for data in [
b"pass = hunter2\n",
b"db_pass = hunter2\n",
b"pass_key = hunter2\n",
b"db-pass: hunter2\n",
b"pin = 1234\n",
b"db_pin = 1234\n",
b"pin-key: 1234\n",
]:
assert (
pol._content_deny_reason("/etc/app.conf", data) == "sensitive_content"
), data
def test_password_keyword_no_false_positives(): def test_password_keyword_no_false_positives():
pol = IgnorePolicy(dangerous=False) pol = IgnorePolicy(dangerous=False)
for data in [ for data in [
b"passive_mode = true\n", b"passive_mode = true\n",
b"PassengerRoot /usr/lib\n", b"PassengerRoot /usr/lib\n",
b"pinboard = enabled\n",
b"pinot_region = noir\n",
b"description = reset the account\n", b"description = reset the account\n",
b"compression = gzip\n", b"compression = gzip\n",
]: ]: