Skip to content

Raise when describeTypes.json 'types' field is missing or malformed - #45

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/14-empty-valid-types-silent
Open

Raise when describeTypes.json 'types' field is missing or malformed#45
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/14-empty-valid-types-silent

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026

Copy link
Copy Markdown
Member

Finding 14 (Medium) — bin/cli.py:77

Problem

get_valid_types returns an empty set rather than raising when 'types' is missing or not a list, so an upstream schema change passes fetch_describe_types' own check and makes every invocation die at :926 with a generic message naming no cause.

Fix

get_valid_types() in bin/cli.py silently returned an empty set whenever describeTypes.json's "types" field was missing or not a list, letting fetch_describe_types' own shape check pass while valid_types stayed empty. This caused every invocation to die later at the generic "No valid MISP attribute type found." check with no indication that the real cause was an upstream schema change. The fix makes get_valid_types() raise a RuntimeError describing the actual problem (missing, non-list, or empty "types") when the field is malformed. The existing try/except around the call site (bin/cli.py, main()) already reports exceptions from this path as "[!] Unable to fetch describeTypes.json: ...", so the fix surfaces a specific, actionable error instead of a generic downstream failure, with no change needed at the call site.

Verification

Reproduced against the unmodified code at 9b8c605, then re-checked after the change.

Before
Calling get_valid_types({"categories": []}) (types key missing) or get_valid_types({"types": "not-a-list"}) both silently returned set() with no exception: "case 1: get_valid_types returned set() silently (no exception)" / "case 2: get_valid_types returned set() silently (no exception)". Simulating the caller's try/except at cli.py:854 with this malformed input produced no error output at all, so a real invocation would proceed and only fail later with the unrelated "No valid MISP attribute type found." message.
After
Same call now raises: "RuntimeError: describeTypes.json 'types' field is missing, empty, or not a list" (exit code 1). Simulating the caller's existing try/except now prints "[!] Unable to fetch describeTypes.json: describeTypes.json 'types' field is missing, empty, or not a list" — a specific, actionable error naming the real cause.

python bin/cli.py --help exits 0 and the module still imports cleanly. Verification was performed offline against the pure functions — no running misp-modules instance 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

get_valid_types() silently returned an empty set whenever the upstream
describeTypes.json response was missing the 'types' key or had it as a
non-list value. This let fetch_describe_types()'s own format check pass
while valid_types stayed empty, so every subsequent invocation died later
at the 'No valid MISP attribute type found.' check with no indication of
the real cause (an upstream schema change).

get_valid_types() now raises a RuntimeError describing the actual problem
when 'types' is missing, not a list, or empty. The existing try/except
around the call in main() already reports exceptions from this path as
'[!] Unable to fetch describeTypes.json: ...', so the fix surfaces a
specific, actionable error instead of a generic downstream failure.
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