Repository navigation
fix(signatures): send canonical signature types and skip invalid expectations (#352) - #364
Open
Mariot Tsitoara (mariot) wants to merge 1 commit into
Open
Mariot Tsitoara (mariot) wants to merge 1 commit into
Mariot Tsitoara (mariot) wants to merge 1 commit into
Conversation
…ctations (#352) SignatureManager.build_payload sent the ExecutionSignature field names (start_time, source_ipv4, target_hostname, ...) as signature types. The platform stores them as is, so every collector failed to build the whole expectation batch and no expectation was matched. - build_payload maps the fields to their SignatureTypes value and leaves out unknown keys and None, list or dict values, with one warning - expectations_models_for_source builds expectations one by one and skips the invalid ones with a warning instead of failing the whole fetch
There was a problem hiding this comment.
🟢 Approval recommended
The focused changes address the reported failures with regression coverage and no identified blocking issues.
0 open findings
What changed in this PR
Fixes #352 by sending canonical signature types and preventing invalid expectations from blocking collectors.
Changes:
- Maps signature names and filters unsupported keys and values.
- Skips invalid expectations individually with warnings.
- Adds regression coverage for payload compatibility and expectation handling.
| File | Description |
|---|---|
| test/signatures/test_signature_manager_build_payload.py | Tests canonical types, filtering, overrides, and collector compatibility. |
| test/apis/inject_expectation/test_inject_expectation.py | Tests model selection and isolation of invalid expectations. |
| pyoaev/signatures/signature_manager.py | Canonicalizes and filters outgoing signatures. |
| pyoaev/apis/inject_expectation/inject_expectation.py | Logs and skips invalid expectations individually. |
🧠 Review effort: Balanced
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
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.
Proposed changes
SignatureManager.build_payloadsends the canonicalSignatureTypesvalues instead of theExecutionSignaturefield names:start_time→start_date,end_time→end_date,source_ipv4/source_ipv6→source_ipv4_address/source_ipv6_address,target_ipv4/target_ipv6/target_hostname→target_ipv4_address/target_ipv6_address/target_hostname_address. The cloud fields already use canonical names.SignatureTypesvalue (partial_results, Nmap'sports_discovered/services_discovered, Netexec'sprotocols_*, Nuclei'scves_*) andNone, list or dict values are left out, with one warning per call that names them. The platform already discards non-scalar values, and collectors parse each signature asSignatureTypes+str. Extra signatures go through the same mapping, and they still override the base value for the same type.expectations_models_for_sourcebuilds expectations one by one and skips an invalid one with a warning (its id and the validation error), so one bad expectation no longer hides the others. I skip the whole expectation rather than dropping its unknown signatures, becausematch_alertrequires every signature to match: dropping one would loosen the match and could create false positives.ExecutionSignaturefield names are unchanged, so injector code using them keeps working.Before / after
Signatures received by the platform (Mimikyu), same inject, pyoaev
3.261014.1vs this branchNmap SYN scan on an asset group (one hostname target, one IPv4 target), DETECTION + PREVENTION:
nmap)start_time,source_ipv4,target_hostname/target_ipv4,ports_discovered,services_discoverednetexec)protocols_tested,protocols_succeedednuclei, VULNERABILITY + DETECTION)cves_tested,cves_found_vulnerablestart_time,end_timestart_date,end_datesource_email/target_email/url_hashindicators are unchangedCollectors: each one ran for 50 s (
COLLECTOR_PERIOD=PT20S) against Mimikyu + ofapi. A proxy added the 4 expectations the unfixed Nmap run produced (stored as the platform stores them) to the 11 valid ones Mimikyu serves.Error fetching expectations: 5 validation errors for DetectionExpectation, 0 expectations processedSkipping expectation <id>warnings, the 11 valid expectations are processed (Splunk ES, template and both Defenders update them)Unit tests: 196 → 212. Ten of the new tests fail on
mainand pass here. The other ten pin behaviour that must not change (extras merge order, per-expectation-type extras, model per expectation type,nullsignatures).Testing Instructions
pytest, plusblack --check .,isort --check-only .,flake8 --ignore=E,W .SignatureManager(Nmap, Netexec, Nuclei, Email SMTP) with this branch against Mimikyu, and check the signature callback. Then run a collector against expectations that containstart_time/source_ipv4signatures and check that the valid ones are still processed.Related issues
Checklist
Further comments
Found while testing, not changed here:
build_payloadacceptstargets_metaas a dict, but then readstarget.agent_id, so a dict raisesAttributeError. Every injector passes a list of objects, so I left it.KeyError: 'assetGroups'(execute()passes the parsed credentials toTargets.build_execution_messageinstead of the inject message). The error handler then callsinjector_logger.error(msg, inject_id, e), whichAppLogger.errordoesn't accept, so the inject never gets an error callback.