fix: reduce public content false positives#1633
Conversation
📝 WalkthroughWalkthroughRefines credential scanning: ChangesCredential scanning improvements
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 3
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@internal/qualitygate/publiccontent/scan_test.go`:
- Around line 1074-1086: The placeholder coverage in
TestScanFileAllowsConventionalCredentialPlaceholders only exercises
underscore-based variants, so it does not lock down the dash-normalization
behavior. Update this test in scan_test.go to include at least one dashed
placeholder case such as YOUR-API-KEY or ACCESS-TOKEN-HERE, and keep asserting
that ScanFile does not return public_content_generic_credential for those
values. This should verify the new normalization path alongside the existing
credential placeholder examples.
- Around line 991-1002: Tighten TestScanFileAllowsBearerHeaderPlaceholders so it
asserts the scan produces no findings at all for bearer-token placeholder
content, not just that public_content_bearer_header is absent. Update the loop
over ScanFile results to fail on any item, or otherwise verify the returned
slice is empty, so placeholders like those in docs/auth.md cannot slip through
as public_content_generic_credential or any other rule.
In `@internal/qualitygate/publiccontent/scan.go`:
- Around line 432-440: The isPlaceholderBearerHeader helper is mixing an index
computed from the lowercased normalized string with a slice taken from the
original match string, which can misalign offsets and panic on non-ASCII input.
Update the slicing to use the same normalized value used for LastIndex so the
offset stays consistent, and keep the rest of the placeholder check logic in
isPlaceholderBearerHeader unchanged.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: e0dc5d73-3481-4413-a11b-0c119b1478a7
📒 Files selected for processing (3)
internal/qualitygate/publiccontent/rules.gointernal/qualitygate/publiccontent/scan.gointernal/qualitygate/publiccontent/scan_test.go
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #1633 +/- ##
==========================================
+ Coverage 74.66% 74.69% +0.03%
==========================================
Files 806 808 +2
Lines 81391 81527 +136
==========================================
+ Hits 60769 60896 +127
- Misses 16089 16093 +4
- Partials 4533 4538 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🚀 PR Preview Install Guide🧰 CLI updatenpm i -g https://pkg.pr.new/larksuite/cli/@larksuite/cli@d7aaa1a46cd6a5acdc411e27b90404baac7a49ac🧩 Skill updatenpx skills add larksuite/cli#fix/public_content_detect -y -g |
Summary
Reduce public-content deterministic gate false positives for documented API identifiers and conventional placeholders while preserving detection for real JWTs, bearer tokens, and credential-shaped values.
Changes
alg, instead of rejecting every longa.b.cdotted value.YOUR_ACCESS_TOKEN,ACCESS_TOKEN_HERE, andYOUR_CLIENT_SECRET.Test Plan
go test ./internal/qualitygate/publiccontent -count=1go test ./internal/qualitygate/... -count=1make quality-gate QUALITY_GATE_CHANGED_FROM=upstream/maingit diff --checkRelated Issues
Summary by CodeRabbit
Bug Fixes
Tests