Skip to content

added 3 DLP rules - #126

Merged
blitzcrieg1 merged 1 commit into
blitzcrieg1:masterfrom
hvadlamani1:master
Aug 27, 2026
Merged

blitzcrieg1 merged 1 commit into
blitzcrieg1:masterfrom
hvadlamani1:master

Conversation

@hvadlamani1

@hvadlamani1 hvadlamani1 commented Aug 27, 2026 •

Copy link
Copy Markdown
Contributor

Added three DLP rules to [manifest.yaml] all credentials / critical:

stripe_api_key — (?i)\bsk_(live|test)[0-9a-z]{24,}\b, exactly as the issue specified.
anthropic_api_key — a separate rule (per the assignee's stated preference), (?i)\bsk-ant-[a-zA-Z0-9
-]{20,}, since the generic pattern's alnum-only run breaks at the hyphen after ant and never matches Anthropic keys.
generic_provider_api_key — (?i)\bsk-[a-zA-Z0-9]{20,}\b for OpenAI-shaped keys.

Added 6 test cases, a fire test each for Stripe live, Stripe test, Anthropic, and generic-provider, plus the two near-misses requested (a too-short Stripe-shaped string, and sk- followed by a short word like sk-test), etc.

All test cases successful. Closes #4

@github-actions

github-actions Bot commented Aug 27, 2026 •

Copy link
Copy Markdown

All contributors have signed the CLA ✍️ ✅
Posted by the CLA Assistant Lite bot.

@hvadlamani1

Copy link
Copy Markdown
Contributor Author

recheck

@hvadlamani1

Copy link
Copy Markdown
Contributor Author

Thank you for your submission. Before we can merge, please sign our Contributor License Agreement (CLA v1.0) by replying to this comment with exactly: "I have read the CLA Document and I hereby sign the CLA" Corporate contributors: see CCLA.md.

I have read the CLA Document and I hereby sign the CLA

You can retrigger this bot by commenting recheck in this Pull Request. Posted by the CLA Assistant Lite bot.

I have read the CLA Document and I hereby sign the CLA

@hvadlamani1

Copy link
Copy Markdown
Contributor Author

I have read the CLA Document and I hereby sign the CLA

github-actions Bot added a commit that referenced this pull request Aug 27, 2026
@hvadlamani1

Copy link
Copy Markdown
Contributor Author

recheck

@blitzcrieg1

Copy link
Copy Markdown
Owner

Thanks for this. It is a better contribution than most: three rules, six tests, and three of those are near-misses. sk_live_abc123 and echo sk-test both having to stay silent is the part people usually skip, and false positives are the failure mode this project spent its last release fixing. The gitleaks:allow annotations mean you read the CI before submitting, which I appreciate.

Your reasoning on the Anthropic rule is correct and I checked it rather than took it:

Anthropic key   -> ['anthropic']   generic correctly does NOT match
OpenAI-shaped   -> ['generic']

The hyphen after ant does break the alnum run at three characters, so sk-ant-api03-… genuinely needs its own rule.

One thing to fix before this lands

There is an existing DashScope rule in the manifest:

pattern: "(?i)\bsk-[a-f0-9]{32}\b"

Hex is a subset of alphanumeric and 32 is more than 20, so a DashScope token now matches your generic rule as well:

DashScope (sk- + 32 hex) -> ['dashscope', 'generic']

Your rule description says the specific rules are handled "above", so I think you assumed first match wins. It does not. scan() in core/audit/dlp/scanner.py says in its own docstring that it "Returns all matches, not just the first", so one DashScope key produces two critical findings.

Not a false positive, both are real credential matches, but duplicate criticals are the same noise problem in a different coat.

A negative lookahead on the generic pattern is enough:

pattern: "(?i)\bsk-(?!ant-)(?![a-f0-9]{32}\b)[a-zA-Z0-9]{20,}\b"

The (?!ant-) is belt and braces since the alnum run already excludes Anthropic keys, but it documents the intent next to the rule that depends on it. A test asserting a DashScope key yields exactly one match would pin it.

Why the checks have not run

This is a fork PR from a first-time contributor, so GitHub is holding the workflows for maintainer approval. That is why only the CLA check has reported and the branch shows as blocked. Nothing to do with your change; it will be approved.

Happy to take this either way: push the lookahead, or say the word and I will apply it on merge.

@blitzcrieg1
blitzcrieg1 merged commit 0fc7692 into blitzcrieg1:master Aug 27, 2026
9 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Aug 27, 2026
@blitzcrieg1

Copy link
Copy Markdown
Owner

Merged. Thanks.

Two corrections to my review, both in your favour.

The overlap is mostly not yours. I measured the regexes in isolation and said your generic rule "now produces two" matches on a DashScope key. Then I ran it against the real scanner on master, and the number is four:

bare DashScope token       2 matches: dashscope_api_token, generic_provider_api_key
DashScope via env assign   4 matches: agent_env_override,
                                      chinese_provider_api_key_assignment,
                                      dashscope_api_token,
                                      generic_provider_api_key
bare OpenAI-shaped token   1 match:   generic_provider_api_key
OpenAI via env assign      1 match:   generic_provider_api_key

Three of those four overlapped before your PR. You added one to a pile that already existed rather than creating it, and your rules are the only ones in that list with near-miss tests.

So I did not ask you to patch it. It is filed as #130 with the reproduction and four options, because a one-line lookahead on your rule would have hidden a wider problem behind a local fix. Your PR is what surfaced it. Every match is correct and none is a false positive; the problem is that a SOC gets four criticals for one secret, which is the alert-fatigue failure this project spent its last release fixing, in a different coat.

Not urgent either way: DLP defaults to log mode, so nothing pages on it today.

Your rules and all six tests are on master unchanged, and you are in CONTRIBUTORS.md. The entry names the near-miss tests specifically, because that is the part a reviewer skimming the diff would miss and it is the thing this project cares most about in a detection contribution.

If you want #130, it is yours. Option 3 in that issue, deduplicating on the matched span, looks closest to right to me: two token rules hitting the same 35 characters is one finding reported twice, while agent_env_override firing alongside them is genuinely a second finding about a different thing. But I have not decided, and an argument for one of the other three would be welcome.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add DLP rules for Stripe and LLM-provider API keys

2 participants