Skip to content

[medium] Merge input types for modules sharing the same name - #28

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/39-duplicate-module-names
Open

[medium] Merge input types for modules sharing the same name#28
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/39-duplicate-module-names

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026

Copy link
Copy Markdown
Member

BLUF — Modules sharing a name overwrite each other's input types instead of merging them.

  • Problemget_module_to_types_map in bin/cli.py assigns rather than merges its per-name entry, so when two modules share a name — including two modules that both fall back to the placeholder <unknown> because they declare no name field — the second one's input types silently overwrite the first one's.
  • Fix — Accumulates into a dict of sets with setdefault and update, converting to sorted lists only when the final mapping is built.
  • Effect — Listings and type lookups show the union of input types for every duplicated module name instead of dropping some entirely.

Finding 39 (Low) — bin/cli.py:123

Problem

get_module_to_types_map assigns rather than merges, so two modules sharing a name - including two both defaulting to '' - silently lose the first one's input types.

Fix

get_module_to_types_map in bin/cli.py used a per-module assignment (mapping[name] = sorted(...)) instead of merging, so whenever two modules shared the same name — including two modules both falling back to the default "" label because they lacked a "name" field — the later module's input-type list silently overwrote the earlier one's, losing its input types entirely. The fix changes the accumulator to a dict of sets, using setdefault(name, set()) to get (or create) the module's type set and .update() to merge each module's input types into it, converting every set to a sorted list only at the end when building the returned dict. This preserves the union of input types across all modules sharing a name.

Verification

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

Before
python /tmp/repro.py (temporary script, not committed) built a modules list with two "dup_mod" expansion modules (inputs ["ip-src"] and ["domain"]) and two nameless expansion modules (inputs ["ip-dst"] and ["hostname"], both defaulting to "<unknown>"). Calling cli.get_module_to_types_map(modules) returned {'<unknown>': ['hostname'], 'dup_mod': ['domain']} — the first module sharing each name ("ip-src" and "ip-dst") vanished, overwritten by the second.
After
Same script against the patched code returned {'<unknown>': ['hostname', 'ip-dst'], 'dup_mod': ['domain', 'ip-src']} — both modules' input types are now present and merged for each duplicated name.

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

@elhoim elhoim changed the title Remove accidentally committed __pycache__ Merge input types for modules sharing the same name Aug 31, 2026
get_module_to_types_map assigned per-module input lists rather than merging them, so when two modules shared a name (including two both falling back to the default '<unknown>' name), the second module's assignment silently overwrote the first's input types.

Fix: accumulate each module's input types into a set via setdefault, merging across all modules with the same name, then convert to sorted lists at the end.

Cleanup: pycache artifacts from local test run should not be tracked.
@elhoim
elhoim force-pushed the fix/39-duplicate-module-names branch from a31cc35 to 4677738 Compare August 31, 2026 13:53
@elhoim elhoim changed the title Merge input types for modules sharing the same name [medium] Merge input types for modules sharing the same name Sep 3, 2026
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