mirror of
https://github.com/zkemail/zk-email-verify.git
synced 2026-01-10 14:08:19 -05:00
helpers: add test for labelRemove sanitization
This commit is contained in:
@@ -19,6 +19,7 @@ export interface DKIMVerificationResult {
|
||||
algo: string;
|
||||
format: string;
|
||||
modulusLength: number;
|
||||
appliedSanitization?: string;
|
||||
}
|
||||
|
||||
export async function verifyDKIMSignature(
|
||||
@@ -38,6 +39,7 @@ export async function verifyDKIMSignature(
|
||||
let dkimResult = await tryVerifyDKIM(email, domain);
|
||||
|
||||
// If DKIM verification fails, try again after sanitizing email
|
||||
let appliedSanitization;
|
||||
if (dkimResult.status.comment === "bad signature" && enableSanitization) {
|
||||
const results = await Promise.all(
|
||||
sanitizers.map((sanitize) =>
|
||||
@@ -53,6 +55,7 @@ export async function verifyDKIMSignature(
|
||||
if (passed) {
|
||||
console.log(`DKIM: Verification passed after applying sanitization "${passed.sanitizer}"`);
|
||||
dkimResult = passed.result;
|
||||
appliedSanitization = passed.sanitizer;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,6 +88,7 @@ export async function verifyDKIMSignature(
|
||||
algo: dkimResult.algo,
|
||||
format: dkimResult.format,
|
||||
modulusLength: dkimResult.modulusLength,
|
||||
appliedSanitization,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -13,6 +13,7 @@ describe("DKIM signature verification", () => {
|
||||
const result = await verifyDKIMSignature(email);
|
||||
|
||||
expect(result.signingDomain).toBe("icloud.com");
|
||||
expect(result.appliedSanitization).toBeFalsy();
|
||||
});
|
||||
|
||||
it("should fail for invalid selector", async () => {
|
||||
@@ -86,3 +87,18 @@ describe("DKIM signature verification", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
describe("DKIM with sanitization", () => {
|
||||
it("should pass after removing label from Subject", async () => {
|
||||
const email = fs.readFileSync(
|
||||
path.join(__dirname, `test-data/email-good.eml`)
|
||||
);
|
||||
|
||||
// Add a label to the subject
|
||||
const tamperedEmail = email.toString().replace("Subject: ", "Subject: [EmailListABC]");
|
||||
|
||||
const result = await verifyDKIMSignature(tamperedEmail);
|
||||
|
||||
expect(result.appliedSanitization).toBe("removeLabels");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user