Skip to content
Merged
Show file tree
Hide file tree
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
34 changes: 11 additions & 23 deletions entrypoints/popup/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
import { filterMailInfraLinesWhenCompact } from '@/lib/checks/mailInfra';
import type { SpfMailProviderHint } from '@/lib/checks/mailProviderSpfHint';
import { getActiveTabHostname } from '@/lib/tabHost';
import { buildWallOfShameDmarcIssueUrl } from '@/lib/wallOfShameDmarcIssue';
import {
filterBreakdownForCompactMode,
type FullScore,
Expand Down Expand Up @@ -118,25 +119,6 @@ function mxtoolboxEmailHealthUrl(domain: string): string {
const DNS_TECHNIQUE_DISCLOSURE =
'DNS queries use DNS-over-HTTPS (Cloudflare / Google). Entra probe uses HTTPS only; no MTA-STS policy files or cert inspection. DKIM probes _domainkey for null DKIM, then provider/common selectors, then *._domainkey.';

const WALL_OF_SHAME_REPO = 'jkerai1/DMARC-WallOfShame';


function wallOfShameNewIssueUrl(company: string, result: CheckResult): string {
const domain = result.dmarcLookupHost;
const title = `${company} (${domain})`;
const bodyParts = [
`**Company:** ${company}`,
`**Domain:** ${domain}`,
];
if (result.queryHostname !== result.dmarcLookupHost) {
bodyParts.push(`**Checked hostname:** ${result.queryHostname}`);
}
bodyParts.push('', '_Submitted via JayQuery browser extension._');
const body = bodyParts.join('\n');
const params = new URLSearchParams({ title, body });
return `https://github.com/${WALL_OF_SHAME_REPO}/issues/new?${params}`;
}

/** Opens a URL from a user gesture (e.g. modal submit) without extra extension permissions. */
function openUrlInNewTab(url: string): void {
const a = document.createElement('a');
Expand Down Expand Up @@ -174,10 +156,10 @@ function renderCastShameModal(result: CheckResult): string {
<div class="cast-shame-modal__backdrop" id="cast-shame-backdrop" aria-hidden="true"></div>
<div class="cast-shame-modal__panel" role="dialog" aria-modal="true" aria-labelledby="cast-shame-heading">
<h2 class="cast-shame-modal__title" id="cast-shame-heading">Report DMARC issue</h2>
<p class="cast-shame-modal__lede">Please submit the company name for the DMARC issue.</p>
<label class="cast-shame-modal__label" for="cast-shame-company">Company name</label>
<p class="cast-shame-modal__lede">Enter the organisation name for the DMARC submission form.</p>
<label class="cast-shame-modal__label" for="cast-shame-company">Organisation name</label>
<input type="text" class="cast-shame-modal__input" id="cast-shame-company" autocomplete="organization" maxlength="160" placeholder="e.g. Acme Ltd" />
<p class="cast-shame-modal__error" id="cast-shame-error" hidden role="alert">Enter a company name.</p>
<p class="cast-shame-modal__error" id="cast-shame-error" hidden role="alert">Enter an organisation name.</p>
<div class="cast-shame-modal__actions">
<button type="button" class="cast-shame-modal__btn cast-shame-modal__btn--ghost" id="cast-shame-cancel">Cancel</button>
<button type="button" class="cast-shame-modal__btn cast-shame-modal__btn--primary" id="cast-shame-submit">Continue to GitHub</button>
Expand Down Expand Up @@ -238,7 +220,13 @@ function bindCastShameModal(result: CheckResult): void {
shameInput.focus();
return;
}
openUrlInNewTab(wallOfShameNewIssueUrl(trimmed, result));
openUrlInNewTab(
buildWallOfShameDmarcIssueUrl(
trimmed,
result.dmarcLookupHost,
result.dmarcRecords,
),
);
closeModal();
});

Expand Down
167 changes: 167 additions & 0 deletions lib/wallOfShameDmarcIssue.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,167 @@
import { describe, expect, it } from 'vitest';
import {
WALL_OF_SHAME_DMARC_ISSUES_NEW,
buildWallOfShameDmarcIssueUrl,
formatWallOfShameDmarcRecordForUrl,
inferWallOfShameDmarcIssueType,
mxtoolboxDmarcLookupUrl,
WALL_OF_SHAME_DMARC_RECORD_URL_MAX,
} from '@/lib/wallOfShameDmarcIssue';

describe('mxtoolboxDmarcLookupUrl', () => {
it('builds SuperTool action dmarc:<domain> with encoded action param', () => {
expect(mxtoolboxDmarcLookupUrl('example.com')).toBe(
'https://mxtoolbox.com/SuperTool.aspx?action=dmarc%3Aexample.com',
);
});

it('encodes special characters in the domain', () => {
expect(mxtoolboxDmarcLookupUrl('bad host')).toContain(
encodeURIComponent('dmarc:bad host'),
);
});
});

describe('inferWallOfShameDmarcIssueType', () => {
it('returns missing when there are no DMARC TXT records', () => {
expect(inferWallOfShameDmarcIssueType([])).toBe(
'No DMARC record (missing)',
);
});

it('returns missing when TXT is not DMARC-shaped', () => {
expect(inferWallOfShameDmarcIssueType(['v=spf1 ~all'])).toBe(
'No DMARC record (missing)',
);
});

it('returns p=none option when policy is none', () => {
expect(
inferWallOfShameDmarcIssueType(['v=DMARC1; p=none; rua=mailto:a@b.co']),
).toBe("DMARC policy set to 'none' (p=none)");
});

it('returns malformed when multiple DMARC records exist', () => {
expect(
inferWallOfShameDmarcIssueType([
'v=DMARC1; p=reject;',
'v=DMARC1; p=none;',
]),
).toBe('Malformed / invalid DMARC record');
});

it('returns malformed when DMARC exists but policy tag is invalid', () => {
expect(
inferWallOfShameDmarcIssueType(['v=DMARC1; p=monitor;']),
).toBe('Malformed / invalid DMARC record');
});

it('returns not a Wall of Shame issue for valid strict policies', () => {
expect(
inferWallOfShameDmarcIssueType(['v=DMARC1; p=reject;']),
).toBe('Not a Wall of Shame issue (valid DMARC policy)');
expect(
inferWallOfShameDmarcIssueType(['v=DMARC1; p=quarantine;']),
).toBe('Not a Wall of Shame issue (valid DMARC policy)');
});
});

describe('formatWallOfShameDmarcRecordForUrl', () => {
it('returns empty string when there are no records', () => {
expect(formatWallOfShameDmarcRecordForUrl([])).toBe('');
});

it('returns empty when maxChars is non-positive (no unsafe slice)', () => {
const rec = 'v=DMARC1; p=none;';
expect(formatWallOfShameDmarcRecordForUrl([rec], 0)).toBe('');
expect(formatWallOfShameDmarcRecordForUrl([rec], -1)).toBe('');
});

it('truncates to a single ellipsis character when maxChars is 1', () => {
expect(formatWallOfShameDmarcRecordForUrl(['v=DMARC1;'], 1)).toBe('…');
expect(formatWallOfShameDmarcRecordForUrl(['v=DMARC1;'], 1).length).toBe(1);
});

it('returns the single record verbatim when within limit', () => {
const rec = 'v=DMARC1; p=none;';
expect(formatWallOfShameDmarcRecordForUrl([rec])).toBe(rec);
});

it('joins multiple records with a separator line', () => {
const a = 'v=DMARC1; p=reject;';
const b = 'v=DMARC1; p=none;';
expect(formatWallOfShameDmarcRecordForUrl([a, b])).toBe(`${a}\n---\n${b}`);
});

it('truncates long records with an ellipsis suffix', () => {
const inner = 'x'.repeat(100);
const rec = `v=DMARC1; p=none; note=${inner}`;
const max = 40;
const out = formatWallOfShameDmarcRecordForUrl([rec], max);
expect(out.length).toBe(max);
expect(out.endsWith('…')).toBe(true);
expect(out.startsWith('v=DMARC1;')).toBe(true);
});

it('respects default max length constant behaviour', () => {
const long = 'v=DMARC1; ' + 'z'.repeat(WALL_OF_SHAME_DMARC_RECORD_URL_MAX);
const out = formatWallOfShameDmarcRecordForUrl([long]);
expect(out.length).toBe(WALL_OF_SHAME_DMARC_RECORD_URL_MAX);
expect(out.endsWith('…')).toBe(true);
});
});

describe('buildWallOfShameDmarcIssueUrl', () => {
function parseIssueUrl(url: string): URLSearchParams {
const u = new URL(url);
expect(u.origin + u.pathname).toBe(WALL_OF_SHAME_DMARC_ISSUES_NEW);
return u.searchParams;
}

it('sets template, title, org, domain, issue type, lookup, and omits dmarc_record when absent', () => {
const url = buildWallOfShameDmarcIssueUrl(
'ACME Corp',
'example.com',
[],
);
const q = parseIssueUrl(url);
expect(q.get('template')).toBe('dmarc_submission.yml');
expect(q.get('title')).toBe('[DMARC] example.com');
expect(q.get('org_name')).toBe('ACME Corp');
expect(q.get('domain')).toBe('example.com');
expect(q.get('issue_type')).toBe('No DMARC record (missing)');
expect(q.has('dmarc_record')).toBe(false);
expect(q.get('lookup_url')).toBe(mxtoolboxDmarcLookupUrl('example.com'));
});

it('includes dmarc_record when records exist', () => {
const rec = 'v=DMARC1; p=none;';
const url = buildWallOfShameDmarcIssueUrl('Co', 'x.test', [rec]);
const q = parseIssueUrl(url);
expect(q.get('dmarc_record')).toBe(rec);
expect(q.get('issue_type')).toBe("DMARC policy set to 'none' (p=none)");
});

it('encodes organisation names with ampersands and preserves round-trip via URLSearchParams', () => {
const url = buildWallOfShameDmarcIssueUrl(
'Foo & Bar Ltd',
'brand.example',
[],
);
const q = parseIssueUrl(url);
expect(q.get('org_name')).toBe('Foo & Bar Ltd');
expect(url).toContain('org_name=');
});

it('uses malformed issue type for multiple DMARC TXTs', () => {
const url = buildWallOfShameDmarcIssueUrl(
'Co',
'dup.example',
['v=DMARC1; p=reject;', 'v=DMARC1; p=none;'],
);
expect(parseIssueUrl(url).get('issue_type')).toBe(
'Malformed / invalid DMARC record',
);
expect(parseIssueUrl(url).get('dmarc_record')).toContain('\n---\n');
});
});
73 changes: 73 additions & 0 deletions lib/wallOfShameDmarcIssue.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
import { analyzeDmarc } from '@/lib/parse/dmarc';

export const WALL_OF_SHAME_DMARC_ISSUES_NEW =
'https://github.com/jkerai1/DMARC-WallOfShame/issues/new';

/** Max chars for DMARC TXT prefilled via URL (avoid GitHub URI limits). */
export const WALL_OF_SHAME_DMARC_RECORD_URL_MAX = 3500;

function truncateForUrlSnippet(s: string, max: number): string {
if (max <= 0) return '';
const t = s.trim();
if (t.length <= max) return t;
return `${t.slice(0, max - 1)}…`;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

/** MXToolbox SuperTool deep link (matches Wall of Shame issue template placeholder). */
export function mxtoolboxDmarcLookupUrl(domain: string): string {
return `https://mxtoolbox.com/SuperTool.aspx?action=${encodeURIComponent(`dmarc:${domain}`)}`;
}

/** Maps analysed DMARC TXT to the Wall of Shame issue form dropdown value. */
export function inferWallOfShameDmarcIssueType(
dmarcRecords: readonly string[],
): string {
const a = analyzeDmarc([...dmarcRecords]);
if (a.multipleRecords) {
return 'Malformed / invalid DMARC record';
}
if (!a.present) {
return 'No DMARC record (missing)';
}
if (a.policy === 'none') {
return "DMARC policy set to 'none' (p=none)";
}
if (a.policy === 'quarantine' || a.policy === 'reject') {
return 'Not a Wall of Shame issue (valid DMARC policy)';
}
return 'Malformed / invalid DMARC record';
}

/** DMARC TXT snippet for GitHub issue URL prefilling (may be empty). */
export function formatWallOfShameDmarcRecordForUrl(
dmarcRecords: readonly string[],
maxChars: number = WALL_OF_SHAME_DMARC_RECORD_URL_MAX,
): string {
if (maxChars <= 0) return '';
if (!dmarcRecords.length) return '';
const joined =
dmarcRecords.length === 1
? dmarcRecords[0]
: dmarcRecords.join('\n---\n');
return truncateForUrlSnippet(joined, maxChars);
}

/** Builds the prefilled DMARC Wall of Shame GitHub issue form URL. */
export function buildWallOfShameDmarcIssueUrl(
orgName: string,
domain: string,
dmarcRecords: readonly string[],
): string {
const params = new URLSearchParams();
params.set('template', 'dmarc_submission.yml');
params.set('title', `[DMARC] ${domain}`);
params.set('org_name', orgName);
params.set('domain', domain);
params.set('issue_type', inferWallOfShameDmarcIssueType(dmarcRecords));
const dmarcSnippet = formatWallOfShameDmarcRecordForUrl(dmarcRecords);
if (dmarcSnippet) {
params.set('dmarc_record', dmarcSnippet);
}
params.set('lookup_url', mxtoolboxDmarcLookupUrl(domain));
return `${WALL_OF_SHAME_DMARC_ISSUES_NEW}?${params}`;
}