fix(check): two false-confident answers neither author could see from inside the module
mail-transport recorded truncation but never surfaced it, so a policy file cut off at the 32 KB limit could still be reported as mode=enforce from a partial parse. hardening's CAA comparison matched issuer tokens blindly, so a certificate naming only its profile (CN: R11, no O) against a CAA record for another CA produced "a renewal would be refused" out of nothing. Both now say they could not judge instead.
This commit is contained in:
1 parent
8925d10424
commit
85ec724928
4 files changed
+72
No files matched your search
@@ -340,6 +340,17 @@ function tokens(text) {
|
||||
.replace(/[^a-z0-9]/g, '');
|
||||
}
|
||||
|
||||
// A CAA mismatch is only claimed when the certificate names a company. "R11", "G2" and "E6" are
|
||||
// profile identifiers: they say nothing about who issued the certificate, so any comparison using
|
||||
// them would be a guess dressed as a finding.
|
||||
function issuerNamesItself(issuer) {
|
||||
if (!issuer || typeof issuer !== 'object') return false;
|
||||
const values = ['O', 'OU', 'CN']
|
||||
.map((key) => (typeof issuer[key] === 'string' ? issuer[key] : ''))
|
||||
.join(' ');
|
||||
return /[A-Za-z]{5,}/.test(values);
|
||||
}
|
||||
|
||||
function issuerTokens(issuer) {
|
||||
if (!issuer || typeof issuer !== 'object') return [];
|
||||
const out = [];
|
||||
@@ -463,6 +474,15 @@ function caaFindings(caa, certificate) {
|
||||
// no fix: this is the good case
|
||||
});
|
||||
clause = 'the CAA record names the CA that issued the certificate';
|
||||
} else if (!issuerNamesItself(issuer)) {
|
||||
// "R11", "G2", "E6" name a certificate profile, not a company. Comparing one to a CAA domain
|
||||
// produces a confident falsehood ("your renewal will be refused"), so say we could not compare.
|
||||
findings.push({
|
||||
level: 'info',
|
||||
code: 'hardening_caa_not_compared',
|
||||
message: `The CAA record allows ${policy.allowed.join(', ')}, but the certificate names its issuer only as ${policy.issuer || 'a short designator'}, which is a profile rather than a company, so the two were not compared.`
|
||||
});
|
||||
clause = `the CAA record allows ${policy.allowed.join(', ')} (issuer not identifiable)`;
|
||||
} else {
|
||||
findings.push({
|
||||
level: 'warn',
|
||||
|
||||
@@ -528,6 +528,17 @@ export function analyseMailTransport(gathered, { now = Date.now() } = {}) {
|
||||
);
|
||||
evidence.push({ label: 'MTA-STS policy', value: `not read (${policy.code})`, note: `the policy file ${policyReason(policy)}` });
|
||||
policyState = 'not-evaluated';
|
||||
} else if (policy.truncated) {
|
||||
// A partial file can look complete: the header lines survive, the mx: list may not. Reporting
|
||||
// mode=enforce from half a policy would claim protection the sender never gets.
|
||||
const limitKb = Math.round(POLICY_MAX_BYTES / 1024);
|
||||
add(
|
||||
'info',
|
||||
'mta_sts_policy_truncated',
|
||||
`The policy file at ${url} is larger than ${limitKb} KB and was only partly read, so its mode was not judged. Real policy files are a few hundred bytes.`
|
||||
);
|
||||
evidence.push({ label: 'MTA-STS policy', value: 'only partly read', note: `the file is larger than ${limitKb} KB` });
|
||||
policyState = 'not-evaluated';
|
||||
} else if (policy.kind === 'missing') {
|
||||
add(
|
||||
'warn',
|
||||
|
||||
@@ -671,3 +671,28 @@ test('no scenario in this file can reach state "fail"', () => {
|
||||
assert.ok(['ok', 'warn', 'not-evaluated'].includes(result.state));
|
||||
}
|
||||
});
|
||||
|
||||
test('a CAA mismatch is never claimed from a profile identifier like R11', () => {
|
||||
// Let's Encrypt certificates often carry only "R11"/"E6" as CN, with no O and no company name.
|
||||
// Comparing that to a CAA record naming another CA would invent "your renewal would be refused".
|
||||
const result = analyseHardening(
|
||||
facts({
|
||||
certificate: { issuer: { CN: 'R11' } },
|
||||
caa: { name: 'example.com', records: [{ critical: 0, issue: 'digicert.com' }] }
|
||||
}),
|
||||
{ now: NOW }
|
||||
);
|
||||
assert.equal(result.findings.find((f) => f.code === 'hardening_caa_issuer_mismatch'), undefined);
|
||||
assert.ok(result.findings.some((f) => f.code === 'hardening_caa_not_compared'));
|
||||
});
|
||||
|
||||
test('a real company name still produces the mismatch warning', () => {
|
||||
const result = analyseHardening(
|
||||
facts({
|
||||
certificate: { issuer: LETS_ENCRYPT },
|
||||
caa: { name: 'example.com', records: [{ critical: 0, issue: 'digicert.com' }] }
|
||||
}),
|
||||
{ now: NOW }
|
||||
);
|
||||
assert.ok(result.findings.some((f) => f.code === 'hardening_caa_issuer_mismatch'));
|
||||
});
|
||||
@@ -737,3 +737,19 @@ test('buildSummary has a sentence for the enforce case that names the file, not
|
||||
assert.match(summary, /policy file says mode=enforce/);
|
||||
assert.doesNotMatch(summary, /TXT record (protects|is enforcing)/);
|
||||
});
|
||||
|
||||
test('a policy file cut off at the size limit is not judged, because half a policy reads like a whole one', () => {
|
||||
// The header lines arrive before the mx: list, so a truncated file still parses. Claiming
|
||||
// mode=enforce from it would promise protection the sender does not get.
|
||||
const result = analyseMailTransport(
|
||||
gatheredFixture({
|
||||
mtaSts: { checked: true, present: true, valid: true, record: 'v=STSv1; id=20261110T000000', id: '20261110T000000', count: 1 },
|
||||
policy: { ...policyOk(), truncated: true }
|
||||
}),
|
||||
{ now: NOW }
|
||||
);
|
||||
assert.ok(codes(result).includes('mta_sts_policy_truncated'));
|
||||
assert.ok(!codes(result).includes('mta_sts_mode_enforce'));
|
||||
assert.equal(result.findings.find((finding) => finding.code === 'mta_sts_policy_truncated').level, 'info');
|
||||
assert.equal(result.state, 'not-evaluated');
|
||||
});
|
||||
Reference in new issue
Block a user