Repository navigation
Conversation
…ields is_cof_valid_strict() was a permanent stub that returned True unconditionally. Since validate_cof() defaults to strict=True and the cof2misp import module is its only caller, every COF ndjson line was accepted regardless of content. A line missing rrtype, rrname or rdata therefore sailed past the validation guard and blew up moments later in parse_and_insert_cof() with a bare KeyError, so an analyst importing a slightly malformed passive DNS feed got an opaque module crash instead of the intended "Could not validate the COF input" error. Until the full JSON Schema validation is written, strict validation now delegates to is_cof_valid_simple(), which checks the mandatory fields and their types. This is stricter than before by design: input that used to be silently waved through and then crash is now rejected with a clear message. Verified with the module's own __main__ self-tests and the full test suite against a live modules server: 161 passed, 4 skipped, 5 subtests passed. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_018dfYpyaSZd1nxSRLr8suj8
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
BLUF — Strict COF validation actually checks the mandatory fields instead of accepting everything.
is_cof_valid_strict()inmisp_modules/lib/cof2misp/cof.pywas a permanent stub returningTrueunconditionally, and sincevalidate_cof()defaults tostrict=True, the only caller inimport_mod/cof2misp.pyhad no validation at all.is_cof_valid_simple(), which already checks the mandatoryrrname,rrtype,rdataand first/last-seen fields.KeyErrorlater in the import.FIXMEis kept in place noting this.The defect
is_cof_valid_strict()inmisp_modules/lib/cof2misp/cof.pywas a permanent stub:validate_cof()defaults tostrict=True, and the only caller,misp_modules/modules/import_mod/cof2misp.py:84(if not validate_cof(entry):),relies on that default. So COF validation was entirely inert: any input, valid or
not, was waved through.
Impact
A malformed passive-DNS COF line (e.g. missing
rrtype,rrname, orrdata)never got the intended "validation failed" rejection. Instead it fell through to
field access further down in
cof2misp.pyand died with a bareKeyError— anopaque crash for the analyst instead of a clear, actionable validation error.
The fix
is_cof_valid_strict()now delegates to the existingis_cof_valid_simple(),which already implements the mandatory-field checks (
rrname,rrtype,rdata, and the first/last-seen time fields) with clear stderr messages onfailure. A
FIXMEis kept in place noting that full JSON Schema validation isstill not implemented — this only wires up the mandatory-field check that
already existed and was unused.
Behaviour change
This flips strict-mode COF validation from a no-op to an actual check, so input
that was previously silently accepted is now rejected when it's missing a
mandatory field. This is the correct behaviour per the function's own
docstring and is what the caller (
strict=Trueby default) already expected.Note:
is_cof_valid_simple()has a pre-existing precedence quirk in itstime-field condition (records carrying
zone_time_first/zone_time_lastinstead of
time_first/time_lastcan be rejected due to unparenthesizednot (...) or (...)logic) and a harmless duplicatedrdatapresence check.Neither is introduced by this change — they already ran on every
strict=Falsecall — but routing strict-mode traffic through this function for the first time
means strict callers now also see that quirk. Fixing it is out of scope here;
this PR only replaces the always-
Truestub with the existing intended check.Verification
Ran directly in this session (not just reported by the fix):
python -m py_compileis clean (the file is undermisp_modules/lib/, excludedfrom flake8 in CI). The full module test suite was also run and reported:
161 passed, 4 skipped, 5 subtests passed in 92.95s (0:01:32).Found during a review of the repository; other findings are being submitted as
separate PRs.
🤖 Generated with Claude Code