Skip to content

Fix silent key drop and EOFError in configure_module --set/non-interactive - #47

Open
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/15-set-keys-dropped-eof
Open

Fix silent key drop and EOFError in configure_module --set/non-interactive#47
elhoim wants to merge 1 commit into
MISP:mainfrom
elhoim:fix/15-set-keys-dropped-eof

Conversation

@elhoim

@elhoim elhoim commented Aug 31, 2026

Copy link
Copy Markdown
Member

Finding 15 (Medium) — bin/cli.py:688-704

Problem

configure_module iterates only the module's declared config_keys, so a --set key the module does not declare (api_key vs apikey) is silently discarded; and any declared key not supplied still calls input(), which raises EOFError under cron - caught at :871, returning 1 with save_config (:716) never reached, losing keys already collected. README calls this 'Non-interactive configuration'.

Fix

configure_module() (bin/cli.py) silently discarded any --set KEY=VALUE whose key wasn't in the module's declared config_keys (e.g. api_key vs apikey), and for any declared key not covered by --set it called input(), which raises EOFError under cron/no-stdin contexts - caught by main()'s broad except, returning 1 before save_config() ran, losing any keys already collected. This broke the README's documented "Non-interactive configuration" use case. Fix: configure_module() now raises ValueError naming any unrecognized --set key(s) instead of dropping them, and a new --non-interactive flag makes it check for missing required keys up front and fail immediately (naming them) instead of calling input().

Verification

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

Before
python3 repro script calling cli.configure_module(modules, cfg_path, "testmod", {"api_key": "secret123"}) with stdin closed -> the wrong key "api_key" is silently ignored (module wants "apikey"), then input("Set value for 'apikey' ...") is called and raises: EOFError: EOF when reading a line (uncaught in the isolated call; in the real CLI this is caught by main()'s except at :871 which prints an error and returns 1, with save_config never reached, discarding any keys already collected).
After
Same call now raises ValueError: "Unknown --set key(s) for module 'testmod': api_key. Valid keys: apikey" immediately, no input() call. With --non-interactive and set_values={} it raises ValueError: "--non-interactive requires --set for missing key(s) for module 'testmod': apikey" immediately, no EOFError. With correct --set apikey=secret123 and non_interactive=True, it returns 0 and writes {"modules": {"testmod": {"apikey": "secret123"}}} to the config file.

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

…ctive

configure_module() only checked declared config_keys against --set, so a
mistyped or unsupported key (e.g. api_key vs apikey) was silently discarded
instead of erroring. Any declared key not covered by --set still called
input(), which raises EOFError with no stdin (e.g. under cron); that
exception propagated up and was caught by main()'s broad except, returning 1
before save_config() ran and discarding any keys already collected in that
call.

Fix:
- configure_module() now raises ValueError naming any --set key(s) that are
  not in the module's declared config_keys, instead of dropping them.
- Add a --non-interactive flag. When set, configure_module() checks for
  missing required keys up front and raises ValueError naming them, instead
  of calling input() and risking EOFError. This gives README's
  'Non-interactive configuration' a way to actually run under cron/unattended
  contexts.
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