@bobfrankston/mailx-types 0.1.59 → 0.1.63
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.d.ts +2 -0
- package/index.js +18 -0
- package/package.json +1 -1
- package/trust.d.ts +91 -0
- package/trust.js +354 -0
package/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@
|
|
|
4
4
|
* This is the contract between client and server.
|
|
5
5
|
*/
|
|
6
6
|
export { CONTACT_RULES } from "./contact-rules.js";
|
|
7
|
+
export { assessMessageTrust, spamScoreOf } from "./trust.js";
|
|
8
|
+
export type { TrustFinding, TrustInput, SpamScore } from "./trust.js";
|
|
7
9
|
export type { MailxApi } from "./mailx-api.js";
|
|
8
10
|
export { addContactsDenylistEntry, addContactsPreferredEntry, type PreferredContactEntry, type CloudReadFn, type CloudWriteFn, } from "./contacts-config.js";
|
|
9
11
|
export { expandRecipients, splitRecipients, isAddressToken, extractAddress, } from "./groups.js";
|
package/index.js
CHANGED
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
// this barrel so a single source-of-truth (contact-rules.jsonc) drives
|
|
8
8
|
// junk-contact filtering on every platform.
|
|
9
9
|
export { CONTACT_RULES } from "./contact-rules.js";
|
|
10
|
+
export { assessMessageTrust, spamScoreOf } from "./trust.js";
|
|
10
11
|
// Shared contacts.jsonc mutations — one implementation for desktop + Android.
|
|
11
12
|
export { addContactsDenylistEntry, addContactsPreferredEntry, } from "./contacts-config.js";
|
|
12
13
|
// Group-name expansion for recipient fields. Lets users type a group name
|
|
@@ -105,6 +106,23 @@ export function sanitizeHtml(html) {
|
|
|
105
106
|
clean = clean.replace(/<select\b[^>]*>[\s\S]*?<\/select>/gi, "[blocked: select]");
|
|
106
107
|
clean = clean.replace(/<button\b[^>]*>([\s\S]*?)<\/button>/gi, "$1");
|
|
107
108
|
clean = clean.replace(/<iframe\b[^>]*>[\s\S]*?<\/iframe>/gi, "");
|
|
109
|
+
// Disarm image maps. An <area> hotspot makes part of an image a link with
|
|
110
|
+
// no underlined text, no visible URL, and nothing to hover — and a forger
|
|
111
|
+
// sizes it to cover the whole picture, so there is no safe pixel to click.
|
|
112
|
+
// Two phishes on 2026-08-25 used exactly that: a "shared document" card
|
|
113
|
+
// whose every pixel was <area coords="0,0,10000,10000"> pointing at an
|
|
114
|
+
// open redirector. This sanitizer stripped their forms and inputs and left
|
|
115
|
+
// that armed.
|
|
116
|
+
//
|
|
117
|
+
// Image maps have no legitimate use in mail, so this is unconditional
|
|
118
|
+
// rather than a size threshold — nothing to tune and nothing to slip past
|
|
119
|
+
// by picking a smaller rectangle. The image still renders; only its hidden
|
|
120
|
+
// clickability goes. The reader is told rather than left to wonder why the
|
|
121
|
+
// picture stopped responding: assessMessageTrust (trust.ts) raises
|
|
122
|
+
// hidden-link-overlay from the RAW html and the viewer explains it.
|
|
123
|
+
// (Claude Code 2026-08-25)
|
|
124
|
+
clean = clean.replace(/<map\b[^>]*>[\s\S]*?<\/map>/gi, "");
|
|
125
|
+
clean = clean.replace(/\s+usemap\s*=\s*(?:"[^"]*"|'[^']*'|[^\s>]+)/gi, "");
|
|
108
126
|
return { html: clean, hasRemoteContent };
|
|
109
127
|
}
|
|
110
128
|
/**
|
package/package.json
CHANGED
package/trust.d.ts
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a message looks forged.
|
|
3
|
+
*
|
|
4
|
+
* Not a spam filter — a spam filter guesses, and a guess that fires on real
|
|
5
|
+
* mail teaches you to click past it. Everything here is EVIDENCE: a verdict
|
|
6
|
+
* your own mail server already reached, or a construct in the message that
|
|
7
|
+
* legitimate mail does not contain. Each finding names what was found and what
|
|
8
|
+
* it means, so the reader can check it rather than trust a score.
|
|
9
|
+
*
|
|
10
|
+
* Written 2026-08-25 after two phishes landed looking clean in the reader
|
|
11
|
+
* (Bob: "this is an attack — could you do a better job of identifying it as
|
|
12
|
+
* bogus?"). Both carried all of the following, and mailx surfaced NONE of it:
|
|
13
|
+
*
|
|
14
|
+
* X-Spam-Flag: YES <- his own server, score 6.7/4.5
|
|
15
|
+
* Authentication-Results: ... spf=fail
|
|
16
|
+
* From: bobip@bobf.frankston.com <- his own address, forged
|
|
17
|
+
* To: bobip@bobf.frankston.com
|
|
18
|
+
* Return-Path: <3EDTkWNvbY@visionsurveysqld.com.au>
|
|
19
|
+
* <area coords="0,0,10000,10000" href="http://.../redirect.php?newurl=...">
|
|
20
|
+
*
|
|
21
|
+
* No header in that list was read anywhere in the codebase, and the one
|
|
22
|
+
* impersonation check that existed (displayNameClaimsOtherAddress) needs a
|
|
23
|
+
* display name, which these messages did not have. The whole visible card was
|
|
24
|
+
* one hidden link through an open redirector, with the victim's own address
|
|
25
|
+
* base64'd into the fragment so the landing page could prefill it.
|
|
26
|
+
*
|
|
27
|
+
* Deliberately NOT included: bare SPF failure on mail that isn't claiming to
|
|
28
|
+
* be you. Forwarded mail fails SPF constantly, and flagging that would be
|
|
29
|
+
* exactly the cry-wolf banner this is trying not to be.
|
|
30
|
+
*/
|
|
31
|
+
/** One piece of evidence that a message is not what it claims to be. */
|
|
32
|
+
export interface TrustFinding {
|
|
33
|
+
/** Stable identifier — for tests, logs, and any future suppression UI. */
|
|
34
|
+
id: "server-spam-verdict" | "self-spoof" | "relay-auth-mismatch" | "zero-width-obfuscation" | "hidden-link-overlay" | "redirector-link";
|
|
35
|
+
/** `danger`: near-certain forgery. `caution`: worth a second look. */
|
|
36
|
+
severity: "danger" | "caution";
|
|
37
|
+
/** One line, naming what was found. Never "this message is suspicious". */
|
|
38
|
+
text: string;
|
|
39
|
+
/** The specific evidence — a header value, a host, a score. */
|
|
40
|
+
detail: string;
|
|
41
|
+
}
|
|
42
|
+
export interface TrustInput {
|
|
43
|
+
/** Every header line, in order, as mailparser's `headerLines`. Repeated
|
|
44
|
+
* headers matter: Authentication-Results and Received both appear more
|
|
45
|
+
* than once and the interesting one is not always the first. */
|
|
46
|
+
headerLines: {
|
|
47
|
+
key: string;
|
|
48
|
+
line: string;
|
|
49
|
+
}[];
|
|
50
|
+
/** Envelope From address. */
|
|
51
|
+
fromAddress: string;
|
|
52
|
+
/** Addresses belonging to the reader — their own aliases. Used only to
|
|
53
|
+
* recognise a message claiming to BE them. */
|
|
54
|
+
ownAddresses: string[];
|
|
55
|
+
/** Sanitized HTML body, for the link-construct checks. */
|
|
56
|
+
bodyHtml: string;
|
|
57
|
+
/** Plain-text body, for the character-level checks. Separate from the HTML
|
|
58
|
+
* because markup legitimately contains things prose does not, and the
|
|
59
|
+
* zero-width test would trip over an entity or an attribute value. */
|
|
60
|
+
bodyText?: string;
|
|
61
|
+
}
|
|
62
|
+
/**
|
|
63
|
+
* Everything findable about this message, worst first.
|
|
64
|
+
*
|
|
65
|
+
* Returns an empty array for ordinary mail — the caller then shows nothing,
|
|
66
|
+
* rather than a reassuring "looks fine" this cannot support. Absence of
|
|
67
|
+
* evidence is not a clean bill of health.
|
|
68
|
+
*/
|
|
69
|
+
export declare function assessMessageTrust(input: TrustInput): TrustFinding[];
|
|
70
|
+
/**
|
|
71
|
+
* The receiving server's spam score, whether or not it crossed the threshold.
|
|
72
|
+
*
|
|
73
|
+
* Separate from the findings on purpose. A finding is an accusation and only
|
|
74
|
+
* fires on evidence; this is a measurement, and the reader asked to see the
|
|
75
|
+
* number itself (Bob 2026-08-25: "should we have a flag ... with the spam
|
|
76
|
+
* assassin number and a color code?"). The sextortion mail is exactly why:
|
|
77
|
+
* 2.7 against a 4.5 threshold is not "clean", it is "did not quite trip the
|
|
78
|
+
* wire", and those are very different things to a person deciding whether to
|
|
79
|
+
* trust a message.
|
|
80
|
+
*
|
|
81
|
+
* Returns null when the server left no score — most mail from providers that
|
|
82
|
+
* filter server-side and say nothing in the headers.
|
|
83
|
+
*/
|
|
84
|
+
export interface SpamScore {
|
|
85
|
+
score: number;
|
|
86
|
+
threshold: number;
|
|
87
|
+
/** The server's own yes/no, which is simply score >= threshold. */
|
|
88
|
+
flagged: boolean;
|
|
89
|
+
}
|
|
90
|
+
export declare function spamScoreOf(headerLines: TrustInput["headerLines"]): SpamScore;
|
|
91
|
+
//# sourceMappingURL=trust.d.ts.map
|
package/trust.js
ADDED
|
@@ -0,0 +1,354 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Why a message looks forged.
|
|
3
|
+
*
|
|
4
|
+
* Not a spam filter — a spam filter guesses, and a guess that fires on real
|
|
5
|
+
* mail teaches you to click past it. Everything here is EVIDENCE: a verdict
|
|
6
|
+
* your own mail server already reached, or a construct in the message that
|
|
7
|
+
* legitimate mail does not contain. Each finding names what was found and what
|
|
8
|
+
* it means, so the reader can check it rather than trust a score.
|
|
9
|
+
*
|
|
10
|
+
* Written 2026-08-25 after two phishes landed looking clean in the reader
|
|
11
|
+
* (Bob: "this is an attack — could you do a better job of identifying it as
|
|
12
|
+
* bogus?"). Both carried all of the following, and mailx surfaced NONE of it:
|
|
13
|
+
*
|
|
14
|
+
* X-Spam-Flag: YES <- his own server, score 6.7/4.5
|
|
15
|
+
* Authentication-Results: ... spf=fail
|
|
16
|
+
* From: bobip@bobf.frankston.com <- his own address, forged
|
|
17
|
+
* To: bobip@bobf.frankston.com
|
|
18
|
+
* Return-Path: <3EDTkWNvbY@visionsurveysqld.com.au>
|
|
19
|
+
* <area coords="0,0,10000,10000" href="http://.../redirect.php?newurl=...">
|
|
20
|
+
*
|
|
21
|
+
* No header in that list was read anywhere in the codebase, and the one
|
|
22
|
+
* impersonation check that existed (displayNameClaimsOtherAddress) needs a
|
|
23
|
+
* display name, which these messages did not have. The whole visible card was
|
|
24
|
+
* one hidden link through an open redirector, with the victim's own address
|
|
25
|
+
* base64'd into the fragment so the landing page could prefill it.
|
|
26
|
+
*
|
|
27
|
+
* Deliberately NOT included: bare SPF failure on mail that isn't claiming to
|
|
28
|
+
* be you. Forwarded mail fails SPF constantly, and flagging that would be
|
|
29
|
+
* exactly the cry-wolf banner this is trying not to be.
|
|
30
|
+
*/
|
|
31
|
+
/** First value of a header, case-insensitive. */
|
|
32
|
+
function header(lines, name) {
|
|
33
|
+
const want = name.toLowerCase();
|
|
34
|
+
for (const h of lines) {
|
|
35
|
+
if ((h.key || "").toLowerCase() !== want)
|
|
36
|
+
continue;
|
|
37
|
+
const colon = h.line.indexOf(":");
|
|
38
|
+
return colon < 0 ? "" : h.line.slice(colon + 1).trim();
|
|
39
|
+
}
|
|
40
|
+
return "";
|
|
41
|
+
}
|
|
42
|
+
/** All values of a repeated header. */
|
|
43
|
+
function headerAll(lines, name) {
|
|
44
|
+
const want = name.toLowerCase();
|
|
45
|
+
const out = [];
|
|
46
|
+
for (const h of lines) {
|
|
47
|
+
if ((h.key || "").toLowerCase() !== want)
|
|
48
|
+
continue;
|
|
49
|
+
const colon = h.line.indexOf(":");
|
|
50
|
+
if (colon >= 0)
|
|
51
|
+
out.push(h.line.slice(colon + 1).trim());
|
|
52
|
+
}
|
|
53
|
+
return out;
|
|
54
|
+
}
|
|
55
|
+
function bare(addr) {
|
|
56
|
+
const m = (addr || "").match(/[^\s<>,;]+@[^\s<>,;]+/);
|
|
57
|
+
return (m ? m[0] : addr || "").toLowerCase().replace(/[.,;]+$/, "");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Did the receiving server's spam filter already say yes?
|
|
61
|
+
*
|
|
62
|
+
* The highest-value signal available, and it costs nothing: the mail server
|
|
63
|
+
* ran SpamAssassin before delivery and wrote the answer into the message.
|
|
64
|
+
* mailx was throwing it away.
|
|
65
|
+
*
|
|
66
|
+
* Only a POSITIVE verdict is trusted, never a negative one. Anyone can inject
|
|
67
|
+
* `X-Spam-Flag: NO` into a message they send, and treating that as a clean
|
|
68
|
+
* bill of health would hand attackers a switch for turning the check off. A
|
|
69
|
+
* forged YES only flags the forger's own mail, so the asymmetry is safe.
|
|
70
|
+
*/
|
|
71
|
+
function serverSpamVerdict(lines) {
|
|
72
|
+
const flag = header(lines, "x-spam-flag");
|
|
73
|
+
const status = header(lines, "x-spam-status");
|
|
74
|
+
if (!/^yes/i.test(flag) && !/^yes/i.test(status))
|
|
75
|
+
return null;
|
|
76
|
+
// "Yes, score=6.7 required=4.5 tests=..." — quote the numbers when they
|
|
77
|
+
// are there, so the reader sees how emphatic the verdict was.
|
|
78
|
+
const score = status.match(/score=([-\d.]+)/)?.[1];
|
|
79
|
+
const required = status.match(/required=([-\d.]+)/)?.[1];
|
|
80
|
+
return {
|
|
81
|
+
id: "server-spam-verdict",
|
|
82
|
+
severity: "danger",
|
|
83
|
+
text: "Your mail server classified this as spam before delivering it.",
|
|
84
|
+
detail: score && required
|
|
85
|
+
? `SpamAssassin score ${score}, threshold ${required}`
|
|
86
|
+
: (status || flag || "X-Spam-Flag: YES"),
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Does the message claim to come from the reader themselves, while failing the
|
|
91
|
+
* authentication that would prove it?
|
|
92
|
+
*
|
|
93
|
+
* Either half alone is ordinary — people really do mail themselves notes, and
|
|
94
|
+
* forwarded mail really does fail SPF. Together they are not: mail genuinely
|
|
95
|
+
* from your own account authenticates as your own account. This is the most
|
|
96
|
+
* common shape of targeted phish, because a From line showing your own address
|
|
97
|
+
* defeats every visual check a reader makes.
|
|
98
|
+
*
|
|
99
|
+
* Requires an Authentication-Results header to exist. A message without one
|
|
100
|
+
* never crossed a trust boundary — it is your own mail, handled internally —
|
|
101
|
+
* and is not evidence of anything. That case is the overwhelming majority:
|
|
102
|
+
* 10,034 of the 10,338 self-claimed messages in a 50,000-message scan of Bob's
|
|
103
|
+
* store had no such header at all.
|
|
104
|
+
*
|
|
105
|
+
* `spf=none` counts as "not authenticated", not just `fail`. A domain with no
|
|
106
|
+
* SPF record published can never produce a failure, only a shrug — so treating
|
|
107
|
+
* `none` as neutral leaves the least-protected domain the least defended.
|
|
108
|
+
* bobf.frankston.com publishes no SPF, and that is precisely the hole the
|
|
109
|
+
* 2026-08-25 sextortion mail walked through: SpamAssassin scored it 2.7
|
|
110
|
+
* against a 4.5 threshold and delivered it. In that same 50,000-message scan
|
|
111
|
+
* `spf=none` on self-claimed mail occurred 18 times and was spam nearly every
|
|
112
|
+
* time ("Settle your debt", "AAA Final notice", "McAfee Protection Plan
|
|
113
|
+
* Ended"); legitimate self-mail was in the no-header group, untouched by this.
|
|
114
|
+
*/
|
|
115
|
+
function selfSpoof(input) {
|
|
116
|
+
const from = bare(input.fromAddress);
|
|
117
|
+
if (!from)
|
|
118
|
+
return null;
|
|
119
|
+
const own = new Set(input.ownAddresses.map(bare).filter(Boolean));
|
|
120
|
+
if (!own.has(from))
|
|
121
|
+
return null;
|
|
122
|
+
const auth = headerAll(input.headerLines, "authentication-results").join(" ; ");
|
|
123
|
+
if (!auth)
|
|
124
|
+
return null;
|
|
125
|
+
const failed = [
|
|
126
|
+
/\bspf=(fail|softfail)\b/i.test(auth) ? "SPF" : "",
|
|
127
|
+
/\bdkim=(fail|permerror)\b/i.test(auth) ? "DKIM" : "",
|
|
128
|
+
/\bdmarc=(fail|permerror)\b/i.test(auth) ? "DMARC" : "",
|
|
129
|
+
].filter(Boolean);
|
|
130
|
+
// Nothing failed, but did anything actually PASS? "spf=none dkim=none" is
|
|
131
|
+
// not a clean bill of health for a message claiming to be you.
|
|
132
|
+
if (!failed.length) {
|
|
133
|
+
if (/\b(spf|dkim|dmarc)=pass\b/i.test(auth))
|
|
134
|
+
return null;
|
|
135
|
+
const envelopeAddr = bare(header(input.headerLines, "return-path"));
|
|
136
|
+
const note = envelopeAddr && envelopeAddr !== from ? `; envelope sender ${envelopeAddr}` : "";
|
|
137
|
+
return {
|
|
138
|
+
id: "self-spoof",
|
|
139
|
+
severity: "danger",
|
|
140
|
+
text: `This claims to be from your own address, ${from}, and nothing proves it came from your account.`,
|
|
141
|
+
detail: `no SPF, DKIM or DMARC result to check against${note} — your domain publishes no SPF record, so forgery cannot be detected by the sending side`,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
// Name the envelope sender when it disagrees — that is the address that
|
|
145
|
+
// actually sent this, and seeing it beside the claim is the whole story.
|
|
146
|
+
const envelope = bare(header(input.headerLines, "return-path"));
|
|
147
|
+
const envelopeNote = envelope && envelope !== from ? `; actually sent by ${envelope}` : "";
|
|
148
|
+
return {
|
|
149
|
+
id: "self-spoof",
|
|
150
|
+
severity: "danger",
|
|
151
|
+
text: `This claims to be from your own address, ${from}, but it did not come from your account.`,
|
|
152
|
+
detail: `${failed.join(" and ")} authentication failed${envelopeNote}`,
|
|
153
|
+
};
|
|
154
|
+
}
|
|
155
|
+
/** Bigger than any real image. An honest layout never needs a hotspot this
|
|
156
|
+
* large; a forger picks an absurd number so they don't have to know the
|
|
157
|
+
* rendered size. Not a tuned threshold — a sanity bound. */
|
|
158
|
+
const OVERLAY_MIN_EDGE_PX = 2000;
|
|
159
|
+
/**
|
|
160
|
+
* Is an entire image covered by one invisible link?
|
|
161
|
+
*
|
|
162
|
+
* `<area coords="0,0,10000,10000">` turns every pixel of an image into a link
|
|
163
|
+
* with no underlined text, no visible URL, and no safe area to click. Real
|
|
164
|
+
* mail uses image maps almost never, and never at that size.
|
|
165
|
+
*/
|
|
166
|
+
function hiddenLinkOverlay(bodyHtml) {
|
|
167
|
+
for (const m of bodyHtml.matchAll(/<area\b[^>]*>/gi)) {
|
|
168
|
+
const tag = m[0];
|
|
169
|
+
const href = tag.match(/href\s*=\s*["']([^"']+)["']/i)?.[1];
|
|
170
|
+
if (!href)
|
|
171
|
+
continue;
|
|
172
|
+
const coords = (tag.match(/coords\s*=\s*["']([^"']+)["']/i)?.[1] || "")
|
|
173
|
+
.split(/[,\s]+/).map(Number).filter(n => Number.isFinite(n));
|
|
174
|
+
if (coords.length < 4)
|
|
175
|
+
continue;
|
|
176
|
+
const width = Math.abs(coords[2] - coords[0]);
|
|
177
|
+
const height = Math.abs(coords[3] - coords[1]);
|
|
178
|
+
if (width < OVERLAY_MIN_EDGE_PX || height < OVERLAY_MIN_EDGE_PX)
|
|
179
|
+
continue;
|
|
180
|
+
let host = href;
|
|
181
|
+
try {
|
|
182
|
+
host = new URL(href).hostname;
|
|
183
|
+
}
|
|
184
|
+
catch { /* keep the raw href */ }
|
|
185
|
+
return {
|
|
186
|
+
id: "hidden-link-overlay",
|
|
187
|
+
severity: "danger",
|
|
188
|
+
text: "The picture in this message is one large hidden link — clicking anywhere on it goes to the same place.",
|
|
189
|
+
detail: `${width}x${height} clickable area over the image, pointing at ${host}`,
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
return null;
|
|
193
|
+
}
|
|
194
|
+
/**
|
|
195
|
+
* Does a link route through a redirector carrying its real destination in the
|
|
196
|
+
* query string?
|
|
197
|
+
*
|
|
198
|
+
* `castanet-sa.fr/modules/babel/redirect.php?newurl=https%3A%2F%2Fevil.example`
|
|
199
|
+
* borrows a real site's reputation: the visible host is a legitimate business
|
|
200
|
+
* whose redirect script was left open, and the destination appears only
|
|
201
|
+
* percent-encoded inside a parameter. Reporting the ENDPOINT is the point — a
|
|
202
|
+
* reader cannot be expected to URL-decode a query string.
|
|
203
|
+
*/
|
|
204
|
+
function redirectorLink(bodyHtml) {
|
|
205
|
+
for (const m of bodyHtml.matchAll(/href\s*=\s*["']([^"']+)["']/gi)) {
|
|
206
|
+
let url;
|
|
207
|
+
try {
|
|
208
|
+
url = new URL(m[1]);
|
|
209
|
+
}
|
|
210
|
+
catch {
|
|
211
|
+
continue;
|
|
212
|
+
}
|
|
213
|
+
if (!/^https?:$/.test(url.protocol))
|
|
214
|
+
continue;
|
|
215
|
+
for (const [, value] of url.searchParams) {
|
|
216
|
+
let target;
|
|
217
|
+
try {
|
|
218
|
+
target = new URL(value);
|
|
219
|
+
}
|
|
220
|
+
catch {
|
|
221
|
+
continue;
|
|
222
|
+
}
|
|
223
|
+
if (!/^https?:$/.test(target.protocol))
|
|
224
|
+
continue;
|
|
225
|
+
if (target.hostname === url.hostname)
|
|
226
|
+
continue; // same-site, not laundering
|
|
227
|
+
return {
|
|
228
|
+
id: "redirector-link",
|
|
229
|
+
severity: "caution",
|
|
230
|
+
text: `A link hides where it goes: it passes through ${url.hostname} and ends at ${target.hostname}.`,
|
|
231
|
+
detail: `${url.hostname} -> ${target.hostname}`,
|
|
232
|
+
};
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
return null;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Everything findable about this message, worst first.
|
|
239
|
+
*
|
|
240
|
+
* Returns an empty array for ordinary mail — the caller then shows nothing,
|
|
241
|
+
* rather than a reassuring "looks fine" this cannot support. Absence of
|
|
242
|
+
* evidence is not a clean bill of health.
|
|
243
|
+
*/
|
|
244
|
+
export function assessMessageTrust(input) {
|
|
245
|
+
const findings = [
|
|
246
|
+
serverSpamVerdict(input.headerLines),
|
|
247
|
+
selfSpoof(input),
|
|
248
|
+
relayAuthMismatch(input),
|
|
249
|
+
zeroWidthObfuscation(input.bodyText || ""),
|
|
250
|
+
hiddenLinkOverlay(input.bodyHtml || ""),
|
|
251
|
+
redirectorLink(input.bodyHtml || ""),
|
|
252
|
+
].filter(Boolean);
|
|
253
|
+
const rank = { danger: 0, caution: 1 };
|
|
254
|
+
return findings.sort((a, b) => rank[a.severity] - rank[b.severity]);
|
|
255
|
+
}
|
|
256
|
+
/**
|
|
257
|
+
* Did the relay record a different account than the one the message claims?
|
|
258
|
+
*
|
|
259
|
+
* Shared hosts stamp the identity that actually authenticated to submit the
|
|
260
|
+
* message. That stamp is added by the RELAY, downstream of whoever sent it, so
|
|
261
|
+
* a forger cannot remove or edit it — which makes disagreement between the
|
|
262
|
+
* stamp and the From line about as close to proof as mail headers get.
|
|
263
|
+
*
|
|
264
|
+
* The 2026-08-25 sextortion mail (Bob: "note that the origin is different than
|
|
265
|
+
* the from domain in antiabuse and in source-auth"):
|
|
266
|
+
*
|
|
267
|
+
* From: universe@bobf.frankston.com
|
|
268
|
+
* X-Source-Auth: admin@calebjross.com
|
|
269
|
+
* X-Source-Cap: (base64) calebjro;calebjro;box2202.bluehost.com
|
|
270
|
+
* Message-ID: <...@calebjross.com>
|
|
271
|
+
*
|
|
272
|
+
* A Bluehost cPanel account belonging to an unrelated domain authenticated and
|
|
273
|
+
* sent mail wearing Bob's address. SpamAssassin scored the whole thing 2.7
|
|
274
|
+
* against a 4.5 threshold and let it through.
|
|
275
|
+
*
|
|
276
|
+
* Compared at the registrable-domain level, not the full address: a host that
|
|
277
|
+
* legitimately sends for a domain authenticates as some account AT that
|
|
278
|
+
* domain, and the local part varies for perfectly ordinary reasons.
|
|
279
|
+
*/
|
|
280
|
+
const RELAY_IDENTITY_HEADERS = [
|
|
281
|
+
"x-source-auth", // cPanel / Exim (Bluehost, HostGator, most shared hosts)
|
|
282
|
+
"x-authenticated-sender", // Postfix / Communigate
|
|
283
|
+
"x-auth-id",
|
|
284
|
+
"x-authenticated-user",
|
|
285
|
+
];
|
|
286
|
+
function relayAuthMismatch(input) {
|
|
287
|
+
const from = bare(input.fromAddress);
|
|
288
|
+
const fromDomain = from.split("@")[1] || "";
|
|
289
|
+
if (!fromDomain)
|
|
290
|
+
return null;
|
|
291
|
+
for (const name of RELAY_IDENTITY_HEADERS) {
|
|
292
|
+
const stamped = bare(header(input.headerLines, name));
|
|
293
|
+
const stampedDomain = stamped.split("@")[1] || "";
|
|
294
|
+
if (!stampedDomain || stampedDomain === fromDomain)
|
|
295
|
+
continue;
|
|
296
|
+
// Sub/parent-domain is the same organisation — mail.example.com
|
|
297
|
+
// sending for example.com is ordinary. Cross-organisation is not.
|
|
298
|
+
if (stampedDomain.endsWith("." + fromDomain) || fromDomain.endsWith("." + stampedDomain))
|
|
299
|
+
continue;
|
|
300
|
+
return {
|
|
301
|
+
id: "relay-auth-mismatch",
|
|
302
|
+
severity: "danger",
|
|
303
|
+
text: `The account that actually sent this belongs to someone else: ${stampedDomain}, not ${fromDomain}.`,
|
|
304
|
+
detail: `the sending server recorded ${stamped} as the authenticated sender, while the message claims to be from ${from}`,
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
return null;
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Is the text stuffed with invisible characters to break word matching?
|
|
311
|
+
*
|
|
312
|
+
* Zero-width space, zero-width non-joiner, zero-width joiner and the
|
|
313
|
+
* zero-width no-break space render as nothing, so a reader sees plain prose
|
|
314
|
+
* while every filter matching on words sees gibberish. The 2026-08-25
|
|
315
|
+
* sextortion mail put one between nearly every pair of letters — "i regret to
|
|
316
|
+
* inform you" reached the parser as `i regret to inform you`. SpamAssassin
|
|
317
|
+
* spotted it (UNICODE_OBFU_ZW_MANY) and still scored the message 2.7 against a
|
|
318
|
+
* 4.5 threshold, so it was delivered.
|
|
319
|
+
*
|
|
320
|
+
* Counted only BETWEEN TWO LATIN LETTERS, which is what obfuscation looks like
|
|
321
|
+
* and what the legitimate uses do not: an emoji ZWJ sequence joins pictographs,
|
|
322
|
+
* Arabic and Indic ZWNJ sit between their own scripts' letters, and a soft
|
|
323
|
+
* hyphen marks a break opportunity rather than splitting a word mid-render.
|
|
324
|
+
*
|
|
325
|
+
* The count guards against a single stray character surviving a copy-paste out
|
|
326
|
+
* of a web page — it is a sanity bound, not a tuned dial. Prose does not
|
|
327
|
+
* accumulate dozens of these by accident; the sample message had over 900.
|
|
328
|
+
*/
|
|
329
|
+
const ZERO_WIDTH_MIN_OCCURRENCES = 12;
|
|
330
|
+
function zeroWidthObfuscation(bodyText) {
|
|
331
|
+
if (!bodyText)
|
|
332
|
+
return null;
|
|
333
|
+
const between = bodyText.match(/[A-Za-z][][A-Za-z]/g);
|
|
334
|
+
const count = between ? between.length : 0;
|
|
335
|
+
if (count < ZERO_WIDTH_MIN_OCCURRENCES)
|
|
336
|
+
return null;
|
|
337
|
+
return {
|
|
338
|
+
id: "zero-width-obfuscation",
|
|
339
|
+
severity: "danger",
|
|
340
|
+
text: "The words in this message are stuffed with invisible characters to get past spam filters.",
|
|
341
|
+
detail: `${count} zero-width characters hidden inside words — legitimate mail has no reason to do this`,
|
|
342
|
+
};
|
|
343
|
+
}
|
|
344
|
+
export function spamScoreOf(headerLines) {
|
|
345
|
+
const status = header(headerLines, "x-spam-status");
|
|
346
|
+
if (!status)
|
|
347
|
+
return null;
|
|
348
|
+
const score = Number(status.match(/score=([-\d.]+)/)?.[1]);
|
|
349
|
+
const threshold = Number(status.match(/required=([-\d.]+)/)?.[1]);
|
|
350
|
+
if (!Number.isFinite(score) || !Number.isFinite(threshold))
|
|
351
|
+
return null;
|
|
352
|
+
return { score, threshold, flagged: /^yes/i.test(status) };
|
|
353
|
+
}
|
|
354
|
+
//# sourceMappingURL=trust.js.map
|