Skip to content

[medium] fix: [__main__] don't mask AttributeErrors raised inside dict_handler - #870

Open
elhoim wants to merge 2 commits into
MISP:mainfrom
elhoim:fix/064-dict-handler-attrerror
Open

elhoim wants to merge 2 commits into
MISP:mainfrom
elhoim:fix/064-dict-handler-attrerror

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026 •

Copy link
Copy Markdown
Contributor

BLUF — A bare except AttributeError in run_request masks real bugs inside a module's dict_handler.

  • Problem — QueryModule.run_request in misp_modules/__main__.py wraps the dict_handler() call in a bare except AttributeError to detect modules that lack one, which also swallows any AttributeError raised inside a working dict_handler and silently re-dispatches to the legacy handler(q=...) path.
  • Fix — Replaces the guard with an explicit hasattr() check so only genuinely missing implementations fall back.
  • Effect — Real bugs inside a module's dict_handler now surface as errors rather than returning quietly different results through the fallback path.

QueryModule.run_request in misp_modules/__main__.py used a bare except AttributeError to detect modules that lack a dict_handler implementation:

try:
    response = MODULES_HANDLERS[module_name].dict_handler(request=dict_payload)
except AttributeError:
    response = MODULES_HANDLERS[module_name].handler(q=json_payload)

The problem is that this except catches any AttributeError, including one raised from inside a working dict_handler implementation (e.g. a None.something access on malformed input, or a missing attribute on an internal object). Such an error gets silently swallowed and the request is silently re-dispatched to the legacy handler(q=...) path instead of failing loudly.

Impact on a MISP user/analyst: a genuine bug in a module's dict_handler is masked. The request appears to succeed via the fallback path (possibly with different/incomplete behavior or stale results) instead of surfacing an error, making the underlying defect much harder to detect and diagnose.

Fix: replace the broad except AttributeError with an explicit hasattr(MODULES_HANDLERS[module_name], "dict_handler") check before calling it. Only modules that genuinely lack dict_handler now fall back to handler(q=...); any AttributeError raised from inside a real dict_handler implementation now propagates instead of being masked.

This does not change behavior for any currently-working module (every module either has dict_handler or doesn't); it only stops masking errors raised inside dict_handler implementations that do exist.

Verification

  • flake8 on the changed file: clean (no output)
  • Full module test suite: 161 passed, 4 skipped, 5 subtests passed in 26.38s

Found during a review of the repository; other findings are being submitted as separate PRs.

🤖 Generated with Claude Code

QueryModule.run_request wraps the call to a module's dict_handler in a
bare except AttributeError, intending to catch modules that don't
define dict_handler and fall back to the legacy handler(q=...) path.
But that except clause also swallows any AttributeError raised from
inside a working dict_handler implementation (e.g. a bug accessing a
missing attribute on a response object), silently re-dispatching the
request to handler(q=...) instead of surfacing the real error. The
caller sees a confusing fallback response, or a second unrelated
failure, instead of the actual exception and traceback.

Replaced the try/except with an explicit hasattr check before calling
dict_handler, so only modules that genuinely lack the method fall back
to handler(q=...); a real AttributeError from within dict_handler now
propagates normally.

Verified with flake8 (clean) and the full pytest suite against a local
modules server: 161 passed, 4 skipped, 5 subtests passed, matching the
baseline.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
@elhoim elhoim changed the title fix: [__main__] don't mask AttributeErrors raised inside dict_handler [medium] fix: [__main__] don't mask AttributeErrors raised inside dict_handler Sep 3, 2026
Resolve the conflict in QueryModule.run_request: keep upstream's module_context wrapper and dispatch on hasattr(dict_handler) inside it, so an AttributeError raised inside a module's dict_handler is no longer masked.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>

This branch has not been deployed

No deployments
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