Skip to content

fix: [csvimport] avoid AttributeError on unset header/delimiter config - #874

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/057-csvimport-config-nullstrip
Open

fix: [csvimport] avoid AttributeError on unset header/delimiter config#874
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/057-csvimport-config-nullstrip

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026

Copy link
Copy Markdown
Member

csvimport's dict_handler() crashes when the module is invoked without the optional header / special_delimiter config keys set:

header = request["config"]["header"].split(",") if request["config"].get("header").strip() else []
delimiter = request["config"]["special_delimiter"] if request["config"].get("special_delimiter").strip() else ","

request["config"].get("header") (and the delimiter equivalent) returns None when the key is absent, and None.strip() raises AttributeError before the intended fallback (empty header list / , delimiter) is ever reached.

Impact: an analyst importing a CSV via this module without explicitly setting header or special_delimiter in the config gets an unhandled AttributeError instead of the module falling back to its documented defaults — the import fails outright rather than degrading gracefully.

Fix: wrap both .get(...) calls as (request["config"].get(key) or "").strip(), so a missing key is treated as an empty string and the existing fallback logic (empty header list / , delimiter) runs as originally intended. No change to behavior when the keys are present and set.

Verification

  • flake8 misp_modules/modules/import_mod/csvimport.py — clean, no output.
  • Started the misp-modules server (python -m misp_modules -l 127.0.0.1 -p 6666) and ran the full test suite: python -m pytest tests/ -q161 passed, 4 skipped, 5 subtests passed in 20.10s.

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

🤖 Generated with Claude Code

https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8

dict_handler() calls .strip() directly on request["config"].get("header")
and request["config"].get("special_delimiter"). When a MISP instance
submits the import without these optional config keys set, .get() returns
None and the subsequent .strip() raises AttributeError instead of falling
back to the intended defaults (an empty header list or the "," delimiter),
so the import fails with an unhandled exception rather than a clean
misperrors response.

Verified with flake8 (clean) and the full pytest suite against a live
modules server on port 6757: 161 passed, 4 skipped, 5 subtests passed,
matching the recorded 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