fix: avoid mutable default for qsentry_feed date - #882
Open
elhoim wants to merge 1 commit into
Open
Conversation
qsentry_feed() defaulted feed_date to datetime.today(), which is evaluated once at import time. In a long-running server process that default freezes at process start, so any caller relying on the default gets an increasingly stale feed date instead of today's, silently fetching the wrong day's feed rather than erroring. Default feed_date to None and compute datetime.today() inside the function body so each call picks up the current date. Verified with flake8 (excluded by CI for lib/, ran python -m py_compile instead, clean) and the full test suite against a live modules server on port 6773: 161 passed, 4 skipped, 5 subtests passed, matching baseline. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
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.
qsentry_feed()inmisp_modules/lib/qintel_helper.pyuses a mutable/eager default argument:datetime.today()is evaluated exactly once, at module import time, and that value is baked into the function's default forever. In a long-running server process (which is exactly how misp-modules runs), every call toqsentry_feed()that relies on the defaultfeed_datekeeps using the date the process started, not the date the call actually happens on.Impact: an analyst or integration calling
qsentry_feed()without an explicitfeed_dateon a server that has been up for more than a day gets the QSentry feed for a stale date, silently, until the process is restarted.Fix: default
feed_datetoNoneand computedatetime.today()inside the function body when no date is supplied, so the date is evaluated per-call instead of at import time.No behaviour change for callers that explicitly pass
feed_date; callers relying on the default now get the correct current date instead of a frozen one, which is the intended/correct behaviour.Found during a review of the repository; other findings are being submitted as separate PRs.
Verification
python -m py_compile misp_modules/lib/qintel_helper.py: clean (this file is undermisp_modules/lib/, excluded from flake8 per CI rules).🤖 Generated with Claude Code
https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8