Prune expired cache entries on save - #33
Open
elhoim wants to merge 1 commit into
Open
Conversation
get_cached_response correctly ignores expired entries but neither it nor set_cached_response ever removed them, so cache.json (which stores full module responses, potentially secret-bearing) grew without bound. The only remedy was --purge-cache, which wipes the whole file. Add prune_expired_entries() and call it before persisting the cache in the query command, dropping any entry whose cached_at predates the configured TTL. This bounds cache.json to roughly one TTL window of entries instead of accumulating indefinitely.
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.
Finding 21 (Medium) —
bin/cli.py:661Problem
Expired entries are never pruned - get_cached_response ignores them and set_cached_response only adds. cache.json grows without bound, and the only remedy (--purge-cache) deletes the entire file, so secret-bearing keys accumulate until a full wipe.
Fix
get_cached_response() correctly ignores TTL-expired entries when reading, but nothing ever removed them: set_cached_response() only adds, and cache.json (which holds full, potentially secret-bearing module responses) grows without bound. The only cleanup path was --purge-cache, which deletes the whole file. Added a prune_expired_entries(cache, now, ttl_seconds) helper and called it right before the cache is persisted in the query command, dropping any entry whose cached_at is older than the configured TTL (also dropping malformed entries). This bounds the cache to roughly one TTL window's worth of entries on every run that touches the cache, without requiring a full wipe.
Verification
Reproduced against the unmodified code at
9b8c605, then re-checked after the change.Before
After
python bin/cli.py --helpexits 0 and the module still imports cleanly. Verification was performed offline against the pure functions — no runningmisp-modulesinstance is required.Branched from
9b8c605. This PR addresses only this finding; the other findings from the same review are in separate PRs, so they will need rebasing against each other as they merge.🤖 Generated with Claude Code
https://claude.ai/code/session_01DYX4TKA5inzByJ4qGWKjqh