Skip to content

pattern: add Datadog API key detection - #358

Merged
Rome-1 merged 11 commits into
Raftersecurity:mainfrom
daocuong11:pattern/add-datadog-api-key-detection
Nov 16, 2026
Merged

Rome-1 merged 11 commits into
Raftersecurity:mainfrom
daocuong11:pattern/add-datadog-api-key-detection

Conversation

@daocuong11

Copy link
Copy Markdown
Contributor

Fixes #23. Adds a Datadog API key pattern to both implementations (Node secret-patterns.ts, Python secret_patterns.py), following the repo's pattern-addition workflow. Datadog API keys are 32 hex chars and app keys 40 hex chars, normally set as DD_API_KEY / DD_APP_KEY. A bare 32-char hex string is usually an MD5 hash, so the match is anchored on the Datadog context (datadog|DD_API_KEY|DD_APP_KEY) instead of matching any 32-char hex string. Tests in both suites: detects DD_API_KEY= + 32 hex and DD_APP_KEY= + 40 hex; does not match a bare 32-char hex string or a short/non-hex value. Verified: Node secret-patterns.test.ts 56 passed; Python test_regex_scanner.py + test_pattern_engine.py 72 passed (2 pre-existing failures on unreadable-file tests, which also fail on unmodified main when running as root). Feedback welcome — please contact me at ldcuong11@gmail.com, happy to fix any requested changes.

@Rome-1

Rome-1 commented Nov 13, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the PR, and for following the dual-implementation workflow. The Node and Python regexes match, the test sets mirror each other, and anchoring on context instead of matching bare 32-hex is the right call.

The anchor is narrower than it looks. The pattern allows only non-alphanumeric characters between the keyword and the hex, so any letter in between breaks the match. With made-up keys, DD_API_KEY= and DD_APP_KEY= match, but DATADOG_API_KEY=…, datadog_api_key = "…" and the DD-API-KEY: … header from Datadog's docs do not, and those are common forms. Could you widen the anchor to allow a separator and an api/app word between the keyword and key? Something like this worked in my checks and still rejects datadog <md5>:

(?i)(?<![a-z0-9])(?:dd|datadog)[_.-]?(?:api|app|application)?[_.-]?key\b[^a-zA-Z0-9]{0,20}[a-f0-9]{32}(?:[a-f0-9]{8})?\b

Please keep Node and Python identical, and add tests in both for DATADOG_API_KEY, lowercase datadog_api_key and the DD-API-KEY header, plus a 36-hex negative to pin the length boundary. The "not-a-real-key" negative can't fail, since it has no hex run, so the 36-hex case would be a better negative.

Last, please squash the four commits into one. I'll add the CHANGELOG entry when I merge.

Use the suggested pattern so DATADOG_API_KEY, lowercase datadog_api_key and the DD-API-KEY header also match; pin the length boundary with a 36-hex negative (replacing the vacuous not-a-real-key negative). Tests added in both Node and Python. Verified: Node secret-patterns.test.ts 60/60 pass; Python Datadog tests pass.
Same Datadog anchor widening in python/rafter_cli/scanners/secret_patterns.py.
Node Datadog tests: DATADOG_API_KEY, lowercase datadog_api_key and DD-API-KEY header detections; 36-hex and bare-MD5 negatives.
Python Datadog tests: DATADOG_API_KEY, lowercase datadog_api_key and DD-API-KEY header detections; 36-hex and bare-MD5 negatives.
@daocuong11

Copy link
Copy Markdown
Contributor Author

Thanks for the review! Done:

  • Applied your suggested pattern in both Node and Python, kept identical.
  • Added tests in both for DATADOG_API_KEY, lowercase datadog_api_key and the DD-API-KEY header, plus a 36-hex negative (replacing the not-a-real-key negative) and a datadog-followed-by-MD5 negative.
  • Verified: Node secret-patterns 60/60 pass; Python Datadog tests pass.

On squashing: I couldn't rewrite the branch history from here, so the fix landed as separate commits on top — happy for you to squash on merge if that works for you.

@Rome-1

Rome-1 commented Nov 14, 2026

Copy link
Copy Markdown
Collaborator

Thanks for the quick turnaround. The Python side and both test sets look right.

One bug on the Node side, partly our fault for posting the regex raw: in node/src/scanners/secret-patterns.ts the pattern is a normal JS string, so key\b needs a doubled backslash. As written, "\b" in a JS string is a backspace character, not a word boundary, so the Node pattern matches nothing (I checked: DD_API_KEY=, DATADOG_API_KEY= and the DD-API-KEY: header all fail to match). The trailing \\b is already escaped correctly. The fix is one character:

- ...[_.-]?key\b[^a-zA-Z0-9]{0,20}...
+ ...[_.-]?key\\b[^a-zA-Z0-9]{0,20}...

The new Node positive tests should fail on CI until that's fixed, which is a good sign that they guard the pattern. Once it's green we'll squash-merge, so no need to squash the commits yourself.

@daocuong11

Copy link
Copy Markdown
Contributor Author

Thanks for catching this — you were right. The pushed file had lost a backslash, so the JS string contained \b (a backspace) instead of a word boundary. Fixed to \b now and verified locally: DD_API_KEY, datadog_api_key and the DD-API-KEY header all match, and the 36-hex negative still does not match. CI should go green on this push; happy for you to squash-merge when ready.

@Rome-1 Rome-1 mentioned this pull request Nov 15, 2026
@github-actions github-actions Bot added secret-pattern New secret detection pattern testing Test coverage improvement labels Nov 16, 2026
@Rome-1
Rome-1 merged commit 11284c1 into Raftersecurity:main Nov 16, 2026
14 checks passed
This was referenced Nov 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

secret-pattern New secret detection pattern testing Test coverage improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pattern: add Datadog API key detection

2 participants