8000 fix(leak-gate): exempt maintainer's mail-domain address in message scope by simon-inkie · Pull Request #5 · simon-inkie/inkie-deck · GitHub
[go: up one dir, main page]

Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 70 additions & 8 deletions scripts/leak-gate.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -57,15 +57,23 @@ import { fileURLToPath } from "node:url";
const REPO_ROOT = path.dirname(path.dirname(fileURLToPath(import.meta.url)));

/**
* @param {{ label: string, why: string, pattern: string[], flags?: string, sample: string[], messageExempt?: boolean }} spec
* @param {{ label: string, why: string, pattern: string[], flags?: string, sample: string[], messageExempt?: boolean, messageExemptPattern?: string[] }} spec
*/
function rule({ label, why, pattern, flags = "i", sample, messageExempt = false }) {
function rule({ label, why, pattern, flags = "i", sample, messageExempt = false, messageExemptPattern }) {
return {
label,
why,
re: new RegExp(pattern.join(""), flags),
sample: sample.join(""),
messageExempt,
// A narrower, anchored allow-pattern: when set, a message-scope match is
// only skipped if the SAME line also matches this exact shape, everything
// else the rule's own pattern catches still fires. This is deliberately
// separate from `messageExempt` (a whole-rule skip), because a rule whose
// pattern class covers more than one person's identity (an email-domain
// rule, not a specific name) must not go blind to every OTHER match on
// that class just to permit one pre-approved instance.
messageExemptPattern: messageExemptPattern ? new RegExp(messageExemptPattern.join(""), flags) : undefined,
};
}

Expand Down Expand Up @@ -312,9 +320,10 @@ const RULES = [
// -- Email ----------------------------------------------------------------
rule({
label: "company-email-address",
why: "Addresses on the company mail domain are personal contact details, not public repo content.",
why: "Addresses on the company mail domain are personal contact details, not public repo content. NARROWLY exempt for one exact message shape only (see messageExemptPattern below), not the whole rule: GitHub's own squash-merge writes a Co-authored-by trailer carrying the maintainer's address onto the merge commit, and that address already sits in the author/committer header of every commit here by the same deliberate, standing decision that exempts his first name (principal-first-name, above). A blanket message-scope skip here would go blind to every OTHER address on the domain in every message shape, not just this one pre-approved instance, this rule's pattern class covers more than one person's identity, unlike a specific name. (An independent model-diverse review pass, 2026-08-17, caught the original blanket exemption on its first look.)",
pattern: ["[A-Za-z0-9._-]+@ink", "ie\\.ink\\b"],
sample: ["someone@ink", "ie.ink"],
messageExemptPattern: ["^Co-au", "thored-by: Si", "mon <si", "mon@ink", "ie\\.ink>$"],
}),

// -- Internal tooling -----------------------------------------------------
Expand Down Expand Up @@ -497,6 +506,28 @@ function scanHistory() {
return { findings, scanned, paths: seenPath.size };
}

/**
* Message-scope matching for a single line, pulled out of scanMessages so the
* self-test can pin the messageExempt / messageExemptPattern semantics
* directly against synthetic strings, without needing a real commit: git
* history is append-mostly by design, and this exemption logic is a security
* boundary that deserves a regression pin, not just a manually-run probe.
*
* @param {string} lineText
* @returns {{ label: string, why: string }[]}
*/
function scanMessageLine(lineText) {
const findings = [];
for (const { label, why, re, messageExempt, messageExemptPattern } of RULES) {
if (messageExempt) continue;
if (re.test(lineText)) {
if (messageExemptPattern && messageExemptPattern.test(lineText)) continue;
findings.push({ label, why });
}
}
return findings;
}

/**
* --messages: scan every reachable commit's subject, body and trailers.
*
Expand All @@ -518,11 +549,8 @@ function scanMessages() {
for (const sha of shas) {
const message = git(["log", "-1", "--format=%B", sha]);
for (const [index, lineText] of message.split("\n").entries()) {
for (const { label, why, re, messageExempt } of RULES) {
if (messageExempt) continue;
if (re.test(lineText)) {
findings.push({ file: `${sha.slice(0, 10)} (message)`, line: index + 1, label, why });
}
for (const { label, why } of scanMessageLine(lineText)) {
findings.push({ file: `${sha.slice(0, 10)} (message)`, line: index + 1, label, why });
}
}
}
Expand Down Expand Up @@ -626,9 +654,43 @@ function selfTest() {
console.error("leak-gate self-test: a real binary was scanned as text; the sniff window is not being honoured");
process.exit(1);
}
// Prove the message-scope EXEMPTION semantics, not just that the rules
// fire. Regression pin for a caught mistake: the first cut of this
// mechanism set messageExempt: true on company-email-address wholesale,
// which silently permitted every address on the domain in every message
// shape, not just the one pre-approved trailer, an independent review
// caught it before it shipped. Three cases, assembled from fragments so
// this file never carries the literal accepted string (see file header):
// the approved exact shape is skipped, the same address outside that
// shape still fires, and a DIFFERENT address in the same shape still
// fires, proving the allow-pattern is anchored to one instance, not the
// whole rule.
const emailRule = RULES.find((r) => r.label === "company-email-address");
if (!emailRule) {
console.error("leak-gate self-test: company-email-address rule missing");
process.exit(1);
}
const acceptedTrailer = ["Co-au", "thored-by: Si", "mon <si", "mon@ink", "ie.ink>"].join("");
const proseSameAddress = ["contact si", "mon@ink", "ie.ink for details"].join("");
const differentAddressTrailer = ["Co-au", "thored-by: Some", "one <some", "one@ink", "ie.ink>"].join("");
if (scanMessageLine(acceptedTrailer).some((f) => f.label === emailRule.label)) {
console.error("leak-gate self-test: the approved maintainer trailer shape should be exempt in message scope but fired");
process.exit(1);
}
if (!scanMessageLine(proseSameAddress).some((f) => f.label === emailRule.label)) {
console.error("leak-gate self-test: the same address outside the approved trailer shape should still fire in message scope");
process.exit(1);
}
if (!scanMessageLine(differentAddressTrailer).some((f) => f.label === emailRule.label)) {
console.error(
"leak-gate self-test: a different address in the approved trailer shape should still fire, messageExemptPattern is over-broad",
);
process.exit(1);
}
console.log(
`leak-gate self-test: all ${RULES.length} rules fire correctly (content, filename and binary-sniff paths)`,
);
console.log("leak-gate self-test: message-scope exemption is narrow (approved shape only, not the whole rule)");
} finally {
fs.rmSync(dir, { recursive: true, force: true });
}
Expand Down
Loading
0