aboutsummaryrefslogtreecommitdiffstats
path: root/tests/test_report.py
AgeCommit message (Collapse)AuthorFilesLines
29 hoursfix: escape the continuation marker so a value cannot forge oneDanilo M.1-0/+199
The marker was an unescaped trailing backslash, and a backslash is legal in a URL path, so a value ending in one was indistinguishable from a wrap. An attacker who read this source could append one and make their own indicator garble itself in the report an abuse desk reads: an adversarial trigger on attacker-supplied text, not an edge case. The short case needed no wrapping at all to corrupt. unwrap() ate the following line regardless, merging an indicator with its own origin annotation. On Subject it was worse, absorbing the Date beneath it and making the "Message as declared" block misstate what the message declared, which is the one thing that block exists to report faithfully. Every backslash is now doubled before wrapping and halved on the way back, and unwrap() tells a marker from content by the PARITY of the trailing run. Doubling only a trailing one would leave "x\\" encoding as "x\" plus a marker, the same bug one character along. A second defect surfaced only under a randomised sweep, after the first fix and a green suite: a break landing BETWEEN the halves of an escaped pair splits the run whose parity unwrap() counts, so a real marker reads as content and the tail is silently dropped. It needs a backslash at exactly the break column, so no hand-written case found it and 454 of 3538 random ones did. The wrap now backs off a character rather than splitting a pair. Verified over 9132 adversarial values, including every backslash pattern up to length 9 and values that are entirely backslashes: 0 round-trip failures, 0 header-block corruptions, no line over 72 columns. Values are escaped, never rejected or sanitised: the report says what the message contained. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xj1ayFRSUQ2u7cwb3S4axE
29 hoursfeat: build the human-readable part of a reportDanilo M.1-0/+209
The ask goes first, only this desk's own indicators appear, and the redaction note is unconditional: a desk seeing REDACTED with no explanation may read the report as doctored. Nothing is truncated. The plan cut three lines with a [:72] slice and left the indicator list unwrapped, which is the same defect twice: a cut URL is a WRONG indicator rather than a short one, and a desk acting on the first 72 characters acts on a resource nobody reported. Long values are divided with an explicit trailing-backslash continuation instead, and unwrap() is the exact inverse, so the tests assert reassembly rather than mere presence. That is what rules out a truncation passing as a wrap. Origins are mapped to English. "header-list_unsubscribe" is a parser's vocabulary and reads as debug output; an origin the table does not know is shown as-is, because losing the only line saying where an indicator came from is worse than showing an ugly token. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xj1ayFRSUQ2u7cwb3S4axE
29 hoursfeat: list the indicators no abuse desk was found forDanilo M.1-0/+208
Not an error and not an exit code: a case where nothing resolved still reaches MISP and the vendors. Visible beats absent, so review can see it without diffing IOC lists. Two departures from the plan, both about the pair of lists agreeing. An indicator is unreportable only when NONE of its contacts produced a mailable address, not when any one of them failed. Contacts fold by host, so an indicator can sit in a domain contact that resolved and an IP contact that did not; listing it regardless puts it in the destinations and in the "no desk found" list at once, and a reviewer acting on the second hand-reports something already on its way to a desk. An abuse value with no "@", or with either half empty, no longer becomes a destination. RDAP jCard data is third-party and occasionally malformed, and such a value produced a pending destination with an unsendable target, which the unreportable array then skipped because the contact did have an abuse entry. Both functions now apply one mailability test, so the two lists partition the indicators exactly. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xj1ayFRSUQ2u7cwb3S4axE
29 hoursfix: fold a role mailbox's case, and test the half that was not testedDanilo M.1-5/+98
"Abuse@Host.Invalid" and "abuse@host.invalid" produced two destinations and two mails to one desk, which is the duplicate-mail behaviour the grouping exists to prevent. The root cause is the test, not the grouping. _group_key folded the domain correctly, but the test written for it used a lowercase local part in both of its inputs, so it varied only the half that worked and passed while the other half was never exercised. A test that varies one half of its input proves nothing about the other. The local part now folds for the RFC 2142 role mailboxes. That RFC mandates those names and requires them matched case-insensitively, so no host runs "Abuse@" and "abuse@" as different desks and treating them as two costs a duplicate mail with nothing on the other side of the trade. This reverses the earlier decision only for the standardised names: any other local part is still left as published, because for a named mailbox folding could merge two desks a host genuinely distinguishes, and a dropped desk is worse than a duplicate. Each half now folds on the strength of its own standard. Both folds are mutation-checked and killed by distinct tests, so neither masks the other, and the role fold is checked across all five role names. Also pins two behaviours that held only by luck: the caller's contacts are not modified, and a destination's ioc list is not aliased to the contact's. Both are true today because the grouping starts a fresh list, and nothing would have caught an implementation that reused the contact's. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xj1ayFRSUQ2u7cwb3S4axE
29 hoursfix: derive a destination id from its address, not its positionDanilo M.1-19/+93
A positional id names a slot in one run's list, and report may run again on a case whose contacts have changed since. A newly resolved indicator whose desk sorts ahead renumbers every desk after it, so bodies/<id>.xarf on disk comes to belong to a different desk than the manifest entry sharing that id. The body hash recorded per destination would then compare one desk's body against another's, reporting an edit nobody made or missing one that was. Hashing the address makes an id follow the desk. It hashes the same normalised form the grouping uses, so two spellings of one desk share an id rather than letting whichever spelling RDAP published first decide a body's filename. Eight hex chars is a deliberate ceiling: collision probability is about 1e-8 at ten desks, and a short id keeps a case directory readable to the person reviewing it. Also strengthens two tests that passed against trivially wrong code: the no-address case now asserts alongside a contact that does resolve, so returning nothing at all is no longer a passing answer, and the two-address case asserts the ioc lists and distinct ids rather than the sorted targets alone. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xj1ayFRSUQ2u7cwb3S4axE
29 hoursfeat: group abuse contacts into one destination per addressDanilo M.1-0/+143
Two contacts can resolve to the same desk, an IP and a domain at one hoster being the common case, and grouping per contact would send that desk two mails about one incident. The domain half of an address is folded to lowercase before grouping, since it is case-insensitive by definition; the local part is left verbatim, because only the receiving host knows whether it folds, and folding two desks a host distinguishes would silently drop one. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Xj1ayFRSUQ2u7cwb3S4axE