Skip to content

fix: avoid mutable default for qsentry_feed date - #882

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/073-qsentry-feed-date-mutable-default
Open

fix: avoid mutable default for qsentry_feed date#882
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/073-qsentry-feed-date-mutable-default

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026

Copy link
Copy Markdown
Member

qsentry_feed() in misp_modules/lib/qintel_helper.py uses a mutable/eager default argument:

def qsentry_feed(query_type="anon", feed_date=datetime.today(), **kwargs):

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 to qsentry_feed() that relies on the default feed_date keeps using the date the process started, not the date the call actually happens on.

Impact: an analyst or integration calling qsentry_feed() without an explicit feed_date on 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_date to None and compute datetime.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 under misp_modules/lib/, excluded from flake8 per CI rules).
  • Full module test suite: 161 passed, 4 skipped, 5 subtests passed in 20.58s.

🤖 Generated with Claude Code

https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8

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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant