feat: cache auth check api calls for secret scans#1216
Open
6d7a wants to merge 1 commit into
Open
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #1216 +/- ##
==========================================
+ Coverage 93.57% 93.66% +0.08%
==========================================
Files 181 182 +1
Lines 9442 9560 +118
==========================================
+ Hits 8835 8954 +119
+ Misses 607 606 -1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
1f13907 to
5b1909a
Compare
secret scans
benjaminrigaud-gg
requested changes
May 13, 2026
2dddf4d to
71d8330
Compare
71d8330 to
18e9aa1
Compare
`check_client_api_key` hits `/v1/metadata` and `/v1/api_tokens/self` on every invocation. When a caller runs bursty scans — notably the VSCode extension, which rescans on every save — this is two API round-trips per scan even though the key state rarely changes between them. This commit introduces a cache for auth calls.
18e9aa1 to
cf4e4a1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Context
check_client_api_keyhits/v1/metadataand/v1/api_tokens/selfon every invocation. When a caller runs bursty scans — notably the GitGuardian VSCode extension, which rescans on every save — this is two API round-trips per scan even though the key state rarely changes between them.What has been done
This PR caches a successful auth check on disk for a short TTL (300s) keyed on
(instance_url, api_key_hash). While the entry is fresh,check_client_api_keyreturns without contacting the API, provided the cached scopes cover the required ones. A cache entry seeded without scopes (e.g. fromauth login) still skips/v1/metadatabut falls through to/v1/api_tokens/selfwhen the caller needs scopes.Trade-off: a server-side key revocation may not be observed for up to the TTL. This is self-healing — the next API call returns 401, which runs through
handle_api_errorand invalidates the cache.Validation
echo "my secret" > /tmp/scan-me.txtuv run ggshield --debug secret scan path /tmp/scan-me.txttwice in succession and confirm the second invocation does not log the metadata/api_tokens round-tripsPR check list
skip-changeloglabel has been added to the PR.