Bound the per-issuer monitoring map against unbounded growth - #215
Open
djw8605 wants to merge 2 commits into
Open
Bound the per-issuer monitoring map against unbounded growth#215djw8605 wants to merge 2 commits into
djw8605 wants to merge 2 commits into
Conversation
MonitoringStats::get_issuer_stats() documents that returned references remain valid for the lifetime of the singleton, and Validator::verify() holds an IssuerStats pointer across the entire validation loop. But MonitoringStats::reset() called m_issuer_stats.clear(), destroying the entries. Any thread calling scitoken_reset_monitoring_stats() while another thread had a verification in flight left that thread updating freed memory. Zero the counters in place instead of erasing the entries, and skip all-zero entries when serializing to JSON so reset still produces an empty report. The failed-issuer map holds plain values only accessed under the mutex, so clearing it remains safe. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
MonitoringStats::get_issuer_stats() inserts a permanent entry keyed by the 'iss' claim of any syntactically valid token -- before the signature or issuer is validated (verify_async and get_public_key_pem both call it for unknown issuers). An attacker replaying unsigned tokens with random issuer strings could grow the map without bound. The existing MAX_FAILED_ISSUERS protection only covers the separate failed-lookup map (whose recording path is currently never called). Cap the tracked issuers at MAX_TRACKED_ISSUERS (1000); further issuers share a single aggregate overflow bucket reported as '<other>' in the JSON output. Entries are still never erased, preserving the reference stability that in-flight validations depend on. Also factors the per-issuer JSON serialization into a helper so the overflow bucket reuses it. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.
Problem
MonitoringStats::get_issuer_stats()inserts a permanent ~200-byte entry keyed by theissclaim of any syntactically valid token — before the signature or issuer is validated (verify_asyncrecordsasync_validations_started, andget_public_key_pemrecordsexpired_keysfor unknown issuers). An attacker replaying unsigned tokens with random issuer strings grows the map without bound.The existing DDoS protection (
MAX_FAILED_ISSUERS = 100) only covers the separate failed-lookup map — and its recording path (record_failed_issuer_lookup) is currently never called from anywhere, so it protects nothing.Fix
MAX_TRACKED_ISSUERS(1000). Once at capacity, statistics for further issuers aggregate into a single shared overflow bucket, reported as"<other>"in the monitoring JSON.serialize_issuer_stats()helper so the overflow bucket reuses it; no change to the JSON schema for existing issuers.Note: this branch is stacked on #214 (contains its commit) since both change
MonitoringStatsinternals — merging #214 first makes this a clean one-commit diff.Testing
ctestunit, env_config, and monitoring suites pass (the monitoring suite exercises stats collection, JSON output, and reset).🤖 Generated with Claude Code