mirror of
https://github.com/bulwarkmail/webmail.git
synced 2026-11-02 00:14:23 +00:00
Stalwart does no BIMI, so sender icons were only ever favicons, which anyone controls for any domain. The webmail server now does the receiver side itself at /api/bimi, and avatars ask it only for messages whose own Authentication-Results say dmarc=pass for the exact From domain. - `lib/bimi/`: DMARC policy check (quarantine or reject, pct=100, the parent domain's sp and p for subdomains), the assertion record with fallback to the parent domain, mark certificate validation (chain to pinned DigiCert, GlobalSign and SSL.com VMC roots, BIMI key purpose, validity, SAN, SCTs present, CRL revocation, logo from the logotype extension), SVG Tiny PS checks and rendering to PNG, caching - logos backed only by the DNS record show by default; the admin setting "Require a mark certificate" (`BIMI_REQUIRE_CERTIFICATE`) limits them to VMC and CMC backed ones - a check mark beside the sender's name for certificate-backed logos - avatars try contact photo, BIMI logo, plugin avatar, favicon; the sender warning shield still wins, and logos follow the sender icons setting and the no-third-party-traffic mode - the two-label public suffix list moved to `lib/root-domain.ts` SCT signatures are not verified and only the default selector is used.
72 lines
3.3 KiB
TypeScript
72 lines
3.3 KiB
TypeScript
import { describe, expect, it } from 'vitest';
|
|
import { dmarcAllowsBimi, pickBimiRecord, pickDmarcRecord, type DmarcRecord } from '@/lib/bimi/records';
|
|
|
|
describe('pickBimiRecord', () => {
|
|
it('reads the logo and certificate locations', () => {
|
|
expect(pickBimiRecord(['v=BIMI1; l=https://brand.example/logo.svg; a=https://brand.example/vmc.pem;'])).toEqual({
|
|
logoUrl: 'https://brand.example/logo.svg',
|
|
evidenceUrl: 'https://brand.example/vmc.pem',
|
|
declined: false,
|
|
});
|
|
});
|
|
|
|
it('ignores the SPF record a wildcard TXT answers with', () => {
|
|
// netflix.com and coinbase.com answer default._bimi queries this way.
|
|
expect(pickBimiRecord(['v=spf1 include:_spf.example.com -all'])).toBeNull();
|
|
expect(pickBimiRecord(['v=spf1 -all', 'v=BIMI1;l=https://brand.example/logo.svg'])?.logoUrl).toBe('https://brand.example/logo.svg');
|
|
});
|
|
|
|
it('refuses two assertion records', () => {
|
|
expect(pickBimiRecord(['v=BIMI1; l=https://a.example/1.svg', 'v=BIMI1; l=https://a.example/2.svg'])).toBeNull();
|
|
});
|
|
|
|
it('treats empty l= and a= as declining', () => {
|
|
expect(pickBimiRecord(['v=BIMI1; l=; a=;'])?.declined).toBe(true);
|
|
// uber.com: a logo, an empty a=.
|
|
expect(pickBimiRecord(['v=BIMI1; l=https://brand.example/logo.svg; a='])).toEqual({
|
|
logoUrl: 'https://brand.example/logo.svg', evidenceUrl: undefined, declined: false,
|
|
});
|
|
});
|
|
|
|
it('refuses locations that are not https', () => {
|
|
expect(pickBimiRecord(['v=BIMI1; l=http://brand.example/logo.svg'])).toBeNull();
|
|
expect(pickBimiRecord(['v=BIMI1; l=https://brand.example/logo.svg; a=ftp://brand.example/vmc.pem'])).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('pickDmarcRecord', () => {
|
|
it('reads p, sp and pct', () => {
|
|
expect(pickDmarcRecord(['v=DMARC1; p=quarantine; sp=reject; pct=100; rua=mailto:d@example.com'])).toEqual({ p: 'quarantine', sp: 'reject', pct: 100 });
|
|
expect(pickDmarcRecord(['v=DMARC1;p=reject'])).toEqual({ p: 'reject', sp: undefined, pct: 100 });
|
|
});
|
|
|
|
it('refuses a record without a valid p', () => {
|
|
expect(pickDmarcRecord(['v=DMARC1; rua=mailto:d@example.com'])).toBeNull();
|
|
expect(pickDmarcRecord(['v=spf1 -all'])).toBeNull();
|
|
});
|
|
});
|
|
|
|
describe('dmarcAllowsBimi', () => {
|
|
const reject: DmarcRecord = { p: 'reject', pct: 100 };
|
|
const quarantine: DmarcRecord = { p: 'quarantine', pct: 100 };
|
|
const none: DmarcRecord = { p: 'none', pct: 100 };
|
|
|
|
it('needs quarantine or reject for every message', () => {
|
|
expect(dmarcAllowsBimi(reject, reject, false)).toBe(true);
|
|
expect(dmarcAllowsBimi(quarantine, quarantine, false)).toBe(true);
|
|
expect(dmarcAllowsBimi(none, none, false)).toBe(false);
|
|
expect(dmarcAllowsBimi({ p: 'reject', pct: 50 }, null, false)).toBe(false);
|
|
expect(dmarcAllowsBimi(null, null, false)).toBe(false);
|
|
});
|
|
|
|
it('applies the organizational domain\'s sp to a subdomain without its own record', () => {
|
|
expect(dmarcAllowsBimi(null, { p: 'reject', sp: 'none', pct: 100 }, true)).toBe(false);
|
|
expect(dmarcAllowsBimi(null, { p: 'quarantine', sp: 'reject', pct: 100 }, true)).toBe(true);
|
|
expect(dmarcAllowsBimi(null, reject, true)).toBe(true);
|
|
});
|
|
|
|
it('refuses a subdomain whose organizational domain is p=none, whatever the subdomain says', () => {
|
|
expect(dmarcAllowsBimi(reject, none, true)).toBe(false);
|
|
});
|
|
});
|