Hash all fingerprints into the manual security check

The manual check used to show the first 8 bytes of the first fingerprint
each SDP named, so an interposer could add its own certificate beside the
claimed one and the codes still matched. Now each code is the first 16
bytes of a SHA-256 over every fingerprint the SDP names, also ones hidden
in other lines, so whatever the browser uses changes the code. Without a
fingerprint on either side the connection ends. End-to-end tests try a
claimed certificate in several hiding places.

The README says that a working connection isn't necessarily direct and what
the meeting tracker sees, TODO.md lists hardening from a security review.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
SchluffeandClaude Opus 5.5 committed 2026-10-29 00:23:04 +01:00
1 parent ae871a2647
commit ae1e3bef9b
5 files changed
+205 -38

No files matched your search

+11 -6
View File
@@ -32,15 +32,15 @@ to the encryption keys of this very connection. Someone in between, or anyone el
know the code, can't do that, and HellCon drops the connection and waits for the right one.
The manual exchange has no code, so there you compare yourselves. Once connected, both sides see two
short codes: **You** and **Peer**. Compare them with the other person over a channel you already
trust, ideally a call or in person:
codes: **You** and **Peer**. Compare them with the other person over a channel you already trust,
ideally a call or in person:
- your **You** must be their **Peer**, and
- your **Peer** must be their **You**.
If both match, you are connected directly to each other. If they don't, someone has placed
themselves in between: click **Codes don't match** and nothing is sent. Nothing is transferred before
both sides confirmed, so take the few seconds to really compare them.
both sides confirmed, so take the time to compare every character, not just the start and end.
The codes are taken from the encryption keys of the connection. Someone in between would need their
own keys, which show up as different codes.
@@ -63,8 +63,11 @@ On the receiving side, HellCon hands the incoming data to the browser's own down
it arrives. That's why files larger than your memory work too, and why the download shows up in
your browser's download list.
There is no relay server. If both sides are behind very strict networks, e.g. some company or mobile
networks, a direct connection may not be possible.
HellCon uses no relay server. If both sides are behind very strict networks, e.g. some company or
mobile networks, a direct connection may not be possible. And a connection that works isn't
necessarily direct: the other side may name a relay of its own, and a STUN server that reports a
wrong address can put itself in between. Either only passes on encrypted data. The security check
makes sure the connection ends at the two of you.
## Privacy
@@ -73,7 +76,9 @@ networks, a direct connection may not be possible.
few trackers see it too, from the request itself. HellCon tries the STUN servers in order and
sticks with the first that answers. The sender stays on the first tracker that accepts it. The
receiver goes down the list until it finds the sender, and the trackers it passes keep its
encrypted offer. Nobody without the code learns your address through a tracker.
encrypted offer. Nobody without the code learns your address through a tracker. The tracker the
two of you meet on does see which addresses share with each other, and when. If that matters,
use your own tracker and STUN server, or the manual exchange.
- Nothing is kept: every reload starts with the default settings.
- Whoever hosts HellCon serves the code that runs in your browser. If you'd rather not trust that,
host your own (below).
+36
View File
@@ -1,5 +1,41 @@
# TODO
## Hardening
From a security review, none of them urgent.
- Sanitize file names for display: `MAX_NAME` only limits the length. Control and bidi characters
(e.g. U+202E) can fake log lines or disguise an extension, `invoice‮fdp.exe` shows as
`invoiceexe.pdf`. Strip C0/C1 and bidi controls where the name is shown and logged, maybe for
`Content-Disposition` in `sw.js` too, though browsers sanitize download names themselves.
- Limit what a tracker can make the page do: no size or rate limit on its messages, `parse` and
`unseal` take whatever arrives, failure reasons after acceptance are logged, and the log in
`App.vue` grows without bound. A malicious tracker can freeze the tab. Only availability, and only
of a tracker the user chose, but cheap: cap `event.data.length` before parsing, cap the log, drop
failure reasons after acceptance or log one.
- The tracker relays anything: `isSdp` only checks for a string, so it passes any payload up to
`MAX_FORWARDED` between two peers of a swarm, usable as a small message relay. The SDP is sealed,
the tracker can't check it's SDP. Checking for base64 of a plausible length only shapes what it
relays, any data can be base64. What limits the relay is a quota: bytes forwarded per IP over
time, and a per-IP connection rate, not only `MAX_PER_IP` concurrent ones, so reconnecting doesn't
reset it. Or decide this is accepted and say so in `tracker.mjs`.
- The tracker's plain HTTP path isn't counted: `MAX_CONNECTIONS` and `MAX_PER_IP` only apply to
upgrades, a non-upgrade request gets a 404 with Node's default timeouts. Don't count on Caddy for
it, its defaults may not cut slow clients short either. Setting `headersTimeout`,
`requestTimeout`, `keepAliveTimeout` and `maxHeadersCount`, and closing the socket after the 404,
costs little. Queues can reach `MAX_QUEUED` × `MAX_CONNECTIONS` = 32 MiB against `mem_limit: 96m`,
maybe a global byte budget.
- Framing: no `frame-ancestors`, so another page can frame HellCon and overlay the security check's
buttons. Gains little: a framed HellCon starts empty like any other, nothing is kept, so it has no
file or offer the user didn't pick or paste inside it, and the address bar shows the framing site.
That site could as well serve a modified copy that fakes the codes. `frame-ancestors` and
`X-Frame-Options` only work as headers, not in a `<meta>`. Recommend them,
`X-Content-Type-Options: nosniff` and `Referrer-Policy: no-referrer` in Host your own.
## Ideas
- Resume interrupted transfers: the receiver already reports how much the download manager has
+72 -2
View File
@@ -291,9 +291,9 @@ async function connect(mode: string, sender: Page, receiver: Page, source: strin
if (mode === 'tracker') return proven(sender, receiver);
const check = (page: Page, side: string) => page.locator(`#check-${side}`).textContent();
// Each side shows ? until it has that fingerprint, the remote one can come after the local one.
// The check shows up once both are connected, which can take a while.
for (const side of ['local', 'remote']) {
await expect(sender.locator(`#check-${side}`)).toHaveText(/^([0-9A-F]{2} ){7}[0-9A-F]{2}$/, {
await expect(sender.locator(`#check-${side}`)).toHaveText(/^([0-9A-F]{2} ){15}[0-9A-F]{2}$/, {
timeout: 45_000,
});
}
@@ -383,6 +383,33 @@ async function payload(content: Buffer, name = 'payload.bin') {
return source;
}
// Where a man in the middle of the manual exchange may put the a=fingerprint line it claims beside
// its own: a parser may read the claimed one where the browser reads the own one. With the own one
// on a line of its own the browser connects to the middle. Or the own one where a parser may miss
// it: Chromium and Firefox don't read it there and don't connect, a browser that did must not get
// the sender's code either.
const HIDDEN: Record<string, { connects: boolean; place: (own: string, claimed: string) => string }> = {
'a line before': { connects: true, place: (own, claimed) => `${claimed}\r\n${own}` },
'a candidate line': {
connects: true,
place: (own, claimed) => `a=candidate:1 1 udp 1 127.0.0.1 9 typ host ${claimed}\r\n${own}`,
},
'another attribute': { connects: true, place: (own, claimed) => `a=x-decoy:${claimed}\r\n${own}` },
'a line after a bare CR': { connects: true, place: (own, claimed) => `a=x-decoy:\r${claimed}\r\n${own}` },
'an indented own line': { connects: false, place: (own, claimed) => `${claimed}\r\n ${own}` },
'an own line after a bare CR': { connects: false, place: (own, claimed) => `${claimed}\r\na=x-decoy:\r${own}` },
};
// The security code of the manual exchange for these fingerprints, like securityCheck in src/core.ts.
const manualCode = (fingerprints: string[]) =>
createHash('sha256')
.update(JSON.stringify(fingerprints))
.digest('hex')
.slice(0, 32)
.toUpperCase()
.match(/../g)!
.join(' ');
// Interoperability and data integrity between every pair, with no server involved.
for (const from of Object.keys(BROWSERS)) {
for (const to of Object.keys(BROWSERS)) {
@@ -759,6 +786,49 @@ for (const name of Object.keys(BROWSERS)) {
});
});
// A man in the middle of the manual exchange hands the receiver an offer of its own, claiming the
// certificate the sender would name beside its own one, see HIDDEN. However the browser takes that,
// the receiver never shows the sender's code: it doesn't connect, or its code covers the middle's
// certificate. Where it connects, the browser accepted the middle's, so without the check the
// middle would get the file.
for (const [variant, { connects, place }] of Object.entries(HIDDEN)) {
test(`check: ${name} manual exchange shows other codes for a certificate claimed in ${variant}`, async () => {
const [middle, receiver] = await Promise.all([open(name), open(name)]);
const claimed = `sha-256 ${Array.from(randomBytes(32), (byte) => byte.toString(16).padStart(2, '0')).join(':')}`;
await withLogs(middle, receiver, async () => {
for (const page of [middle, receiver]) await page.uncheck('#stun');
await middle.setInputFiles('input[type=file]', await payload(randomBytes(1000)));
await middle.click('#send-manual summary');
await middle.click('#create-offer');
await expect(middle.locator('#offer')).toHaveValue(/.+/);
const sdp = Buffer.from(await middle.inputValue('#offer'), 'base64').toString();
const tampered = sdp.replace(/^a=fingerprint:[^\r\n]*/gm, (line) =>
place(line, `a=fingerprint:${claimed.toUpperCase()}`),
);
expect(tampered).not.toBe(sdp);
await receiver.click('#receive-manual summary');
await receiver.fill('#offer-input', Buffer.from(tampered).toString('base64'));
await receiver.click('#create-answer');
const remote = receiver.locator('#check-remote');
const failed = (page: Page) => page.locator('#send-error, #receive-error').filter({ hasText: /.+/ });
await expect(receiver.locator('#answer').or(failed(receiver))).toBeVisible({ timeout: 15_000 });
if (!(await failed(receiver).count())) {
await middle.fill('#answer-input', await receiver.inputValue('#answer'));
await middle.click('#accept-answer');
// The middle may take the answer or not, the receiver connects or not.
const settled = async () =>
(await remote.count()) + (await failed(receiver).count()) + (await failed(middle).count());
await expect.poll(settled, { timeout: 15_000 }).toBeGreaterThan(0);
}
if (connects) await expect(remote).toBeVisible();
if (await remote.count()) await expect(remote).not.toHaveText(manualCode([claimed]));
});
});
}
test(`protocol: ${name} manual exchange reports a broken offer and answer`, async () => {
const [sender, receiver] = await Promise.all([open(name), open(name)]);
await sender.setInputFiles('input[type=file]', await payload(randomBytes(1000)));
+46 -11
View File
@@ -508,23 +508,45 @@ describe('messages', () => {
expect(() => decode('not base64!', 'answer')).toThrow('not a valid answer, copy all of it');
});
it('counts every fingerprint once, at session or media level', () => {
it('counts every fingerprint once, at session or media level, also hidden ones', () => {
const sdp =
'v=0\r\na=fingerprint:sha-256 AB:CD\r\nm=application\r\na=fingerprint:SHA-256 ab:cd\r\na=fingerprint:sha-1 01\r\n';
expect(fingerprints(sdp)).toEqual(['sha-1 01', 'sha-256 ab:cd']);
'v=0\r\na=fingerprint:sha-256 AB:CD\r\nm=application\r\na=fingerprint:SHA-256 ab:cd\na=fingerprint:sha-1\t01\r\n' +
// Hidden in lines the browser reads otherwise.
'a=candidate:1 1 udp 1 127.0.0.1 9 typ host a=fingerprint:sha-256 01:02\r\n' +
'a=x-decoy:a=fingerprint:sha-256 03:04\r\na=x-decoy:\ra=fingerprint:sha-256 05:06\r\n' +
// A bare CR doesn't end the line for the browser.
'a=fingerprint:sha-256\r07:08\r\n';
expect(fingerprints(sdp)).toEqual([
'sha-1 01',
'sha-256 01:02',
'sha-256 03:04',
'sha-256 05:06',
'sha-256 07:08',
'sha-256 ab:cd',
]);
});
it('shows the first 8 bytes of both fingerprints for the check', () => {
const sdp = (fingerprint: string) => ({ sdp: `v=0\r\na=fingerprint:sha-256 ${fingerprint}\r\n` });
it('shows the first 16 bytes of a hash over all fingerprints for the check', async () => {
const code = (list: string[]) =>
createHash('sha256')
.update(JSON.stringify(list))
.digest('hex')
.slice(0, 32)
.toUpperCase()
.match(/../g)!
.join(' ');
const pc = {
localDescription: sdp('aa:bb:cc:dd:ee:ff:00:11:22:33'),
remoteDescription: sdp('01:02:03:04:05:06:07:08:09'),
localDescription: { sdp: 'v=0\r\na=fingerprint:sha-256 aa:bb\r\n' },
remoteDescription: { sdp: 'v=0\r\na=fingerprint:sha-256 0A:0B\r\nm=application\r\na=fingerprint:sha-1 0c\r\n' },
} as RTCPeerConnection;
expect(securityCheck(pc)).toEqual({ local: 'AA BB CC DD EE FF 00 11', remote: '01 02 03 04 05 06 07 08' });
expect(securityCheck({ localDescription: null, remoteDescription: null } as RTCPeerConnection)).toEqual({
local: '?',
remote: '?',
expect(await securityCheck(pc)).toEqual({
local: code(['sha-256 aa:bb']),
remote: code(['sha-1 0c', 'sha-256 0a:0b']),
});
expect(await securityCheck({ ...pc, remoteDescription: { sdp: 'v=0\r\n' } } as RTCPeerConnection)).toBeUndefined();
expect(
await securityCheck({ localDescription: null, remoteDescription: null } as RTCPeerConnection),
).toBeUndefined();
});
it('names the side without a public address', () => {
@@ -1170,6 +1192,19 @@ describe('manual exchange', () => {
expect(openPeers()).toEqual([]);
});
it('shows other codes for a peer that named a second certificate', async () => {
const [sender, receiver] = [side(), side()];
const { offer, accept } = await createOffer(file(10), sender.events, sender.signal);
// The real one first, the fake one connects too. FakePeer only knows the first.
const tampered = btoa(`${atob(offer)}m=application\r\na=fingerprint:sha-256 AA:BB\r\n`);
await accept(await answerOffer(tampered, receiver.events, receiver.signal));
await until(() => sender.checks[0] && receiver.checks[0]);
const [own, peer] = [sender.checks[0]!, receiver.checks[0]!];
expect(peer.remote).not.toBe(own.local);
expect(peer.local).toBe(own.remote);
expect(receiver.status()).toBe('wait: Compare the security codes above with the sender');
});
it('reports a broken offer and answer, the offer stays good for the right answer', async () => {
const receiver = side();
await expect(answerOffer(btoa('v=0 but nothing else'), receiver.events, receiver.signal)).rejects.toThrow(
+40 -19
View File
@@ -442,24 +442,39 @@ const BLOCKED = 'a network in between, e.g. a VPN or firewall, may block direct
const host = (url: string) => URL.parse(url)?.host || url;
// Anti-MITM check: the first 8 bytes of both DTLS certificate fingerprints, fewer an interposer can
// brute force with matching certificates. My local code must equal the peer's remote code and vice
// versa, otherwise someone interposed on the signaling.
export function securityCheck(pc: RTCPeerConnection) {
const short = (sdp = '') =>
sdp
.match(/a=fingerprint:\S+ ([0-9A-F:]+)/i)?.[1]
?.toUpperCase()
.split(':')
.slice(0, 8)
.join(' ') ?? '?';
return { local: short(pc.localDescription?.sdp), remote: short(pc.remoteDescription?.sdp) };
}
// Every fingerprint the SDP names, in full: one added beside the real one changes the result too.
// Browsers may move them between session and media level, so each counts once.
// Browsers may move them between session and media level, so each counts once. Any a=fingerprint
// counts, also one hidden in another line: one the browser ignores only makes the result differ,
// one missed that the browser uses would let an interposer through. So nothing depends on how a
// browser splits lines.
export const fingerprints = (sdp: string) =>
[...new Set([...sdp.matchAll(/^a=fingerprint:(.+)$/gim)].map(([, line]) => line!.trim().toLowerCase()))].sort();
[
...new Set(
[...sdp.matchAll(/a=fingerprint:([^\n]*)/gi)].map(([, fingerprint]) =>
fingerprint!.trim().replace(/\s+/g, ' ').toLowerCase(),
),
),
].sort();
// Anti-MITM check of the manual exchange: the first 16 bytes of a SHA-256 over all DTLS
// certificate fingerprints of each side. An interposer can try one cheaply, it only has to vary a
// line the browser ignores, so it takes that many to be out of its reach. My local code must equal
// the peer's remote code and vice versa, otherwise someone interposed on the signaling. All of them
// count, like in prove: one certificate may be named by several hash functions, and a browser may
// accept a certificate by any of them. Without one on either side there is nothing to check:
// undefined.
export async function securityCheck(pc: RTCPeerConnection) {
const short = async (sdp = '') => {
const list = fingerprints(sdp);
if (!list.length) return;
const digest = await crypto.subtle.digest('SHA-256', new TextEncoder().encode(JSON.stringify(list)));
return Array.from(new Uint8Array(digest, 0, 16), (byte) => byte.toString(16).padStart(2, '0'))
.join(' ')
.toUpperCase();
};
const [local, remote] = await Promise.all([short(pc.localDescription?.sdp), short(pc.remoteDescription?.sdp)]);
if (local && remote) return { local, remote };
}
// The security check of tracker signaling, resolves once the peer proved the code. Each side signs its
// role, its SDP type, and the fingerprints of both certificates as it sees them. The peer checks that
@@ -522,7 +537,6 @@ function connected(
events.log(`connected via ${via}`);
events.log('waiting for the security check');
if (key) events.status('start', 'Connected, checking the code');
else events.status('wait', `Compare the security codes above with the ${peer}`);
let done = false;
const end = (reason: string) => {
if (done) return;
@@ -541,8 +555,15 @@ function connected(
return {
checked: key
? prove(pc, channel, key, end).then(() => events.log('security check passed'))
: new Promise((resolve) =>
events.check({ ...securityCheck(pc), confirm: resolve, reject: () => end('security check failed') }),
: securityCheck(pc).then(
(codes) =>
new Promise<void>((resolve) => {
// The peer may have left while the codes were computed.
if (done) return;
if (!codes) return end('no certificate to check');
events.check({ ...codes, confirm: resolve, reject: () => end('security check failed') });
events.status('wait', `Compare the security codes above with the ${peer}`);
}),
),
start: () => (done = true),
end,