fix(trufflehog): exclude .yarn/releases/ to silence yarn 4 false positives#162
fix(trufflehog): exclude .yarn/releases/ to silence yarn 4 false positives#162tolzhabayev wants to merge 4 commits into
Conversation
…se positives The TruffleHog v1 Gitlab detector (DetectorType=9) matches any 20-char alphanumeric token near the keyword "gitlab". This triggers on every Grafana repo that vendors a Yarn 4 release binary via corepack: the minified `.yarn/releases/yarn-*.cjs` bundle contains yarn config keys like `npmPublishProvenance` (exactly 20 alphanumeric chars) co-located with internal mentions of GitLab Package Registry URLs, which trips the detector on every CI run. Evidence: grafana/levitate-grafana-ci#109 — the Yarn 4.15.0 bundle fires `DetectorName=Gitlab`, `Raw=npmPublishProvenance` at line 711. Every repo upgrading to Yarn 4 will produce the same noise comment until contributors learn to ignore it. Tradeoff: this disables Gitlab personal-access-token detection entirely (the legacy detector is the only Gitlab detector — v2/v3 are internal regex revisions of the same protobuf enum, not separate detector types). Real GitLab credentials in this org are already covered by: - GitHub native secret scanning (push protection on for grafana/*) - GitHub Advanced Security (push protection + push to repos) - Pre-commit `pre-commit/trufflehog.sh` for local dev (same flag can be added there in a follow-up if desired) The false-positive rate of v1 Gitlab is high enough that the signal it provides is already drowned out — see trufflesecurity/trufflehog issue tracker for the long history of "GitLab detector triggers on random alphanumeric" reports.
isaiah-grafana
left a comment
There was a problem hiding this comment.
Thanks for chasing this down.. the Yarn 4 thing in .yarn/releases/ is annoying and I’ve seen the same GitLab FP pop up elsewhere.
I’m not sure we want to disable the GitLab detector org-wide though. For org-wide TruffleHog noise we usually handle it with path excludes, not turning off detectors:
Have you seen this?
https://github.com/grafana/security-docs/blob/main/docs/appsec/security-tools/trufflehog.md#org-wide-exclusions
Pivot from per-detector exclude to path-based exclusion, per review feedback on grafana#162. The previous commit disabled the entire Gitlab detector org-wide; the org pattern (per security-docs trufflehog.md "Org-wide exclusions") is to add path patterns to `trufflehog/exclude-paths.txt` instead, keeping detection coverage intact. `.yarn/releases/` is the corepack-vendored Yarn 4 binary directory — the minified `.cjs` bundle contains config keys like `npmPublishProvenance` near internal GitLab mentions, which trips the Gitlab detector on every PR that touches it. Revert the `--exclude-detectors Gitlab` flag from both `trufflehog filesystem` invocations and add `\.yarn/releases/` to the shared `trufflehog/exclude-paths.txt` so all org repos pick it up at scan time.
|
Pivoted — yes, I'd seen the doc but the path-based approach didn't click as the right primary fix until your review. Agree disabling the detector org-wide was the wrong lever.
Kept the pattern narrow ( |
Summary
Add
\.yarn/releases/to the sharedtrufflehog/exclude-paths.txtso all org repos stop scanning the corepack-vendored Yarn 4 binary.Why this matters
Every Grafana repo bumping to Yarn 4 produces a TruffleHog PR comment like:
Concrete evidence from grafana/levitate-grafana-ci#109:
{ "DetectorName": "Gitlab", "DetectorType": 9, "Verified": false, "Raw": "npmPublishProvenance", "file": ".yarn/releases/yarn-4.15.0.cjs", "line": 711 }The Yarn 4 release bundle is a minified
.cjsblob that contains yarn config keys likenpmPublishProvenance(20 alphanumeric chars) co-located with internal mentions of GitLab Package Registry URLs — exactly the shape that TruffleHog's Gitlab detector flags..yarn/releases/is yarn-managed corepack output, not user code; scanning it for secrets has no value.Approach
Per the org-wide exclusions section of security-docs, the fix is a one-line addition to
trufflehog/exclude-paths.txt:The workflow already fetches this file at runtime and passes it to
trufflehog --exclude-paths, so the change rolls out to every org repo on the next scan with no per-repo work.The Gitlab detector stays enabled — real
glpat-*PATs and other Gitlab credentials anywhere else in a repo are still detected.Scope decision
Kept the pattern narrow (
\.yarn/releases/) rather than excluding all of.yarn/, since that's the only subdirectory with evidenced false positives. If.yarn/plugins/or other subdirectories trigger noise later, adding them is a one-line follow-up to this file.Reverted from the previous approach
--exclude-detectors Gitlabfrom bothtrufflehog filesysteminvocations inreusable-trufflehog.yml.Test plan
.yarn/releases/yarn-*.cjsno longer produces a TruffleHog PR comment for that file.glpat-test token elsewhere in the same repo still gets flagged (detector remains active).