Strip controls, line separators and bidi controls from offered file names
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
7f4811485a
commit
af0a8c9fee
3 files changed
+18
-12
No files matched your search
@@ -1,14 +1,5 @@
|
||||
# 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, `invoicefdp.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.
|
||||
|
||||
## Ideas
|
||||
|
||||
- Resume interrupted transfers: the receiver already reports how much the download manager has
|
||||
|
||||
@@ -1142,6 +1142,17 @@ describe('receiving', () => {
|
||||
}
|
||||
});
|
||||
|
||||
it('strips controls, line separators and bidi controls from the offered name', async () => {
|
||||
const { channel, session, check } = receiving();
|
||||
check();
|
||||
await until(() => channel.sent.length);
|
||||
channel.receive({ name: 'invoice\u202Efdp.exe\n\u2028done\u0000\u009B\u2066', size: 1 });
|
||||
expect(session.files).toMatchObject([{ name: 'invoicefdp.exedone' }]);
|
||||
expect(session.logs.at(-1)).toBe('offered invoicefdp.exedone (1 bytes)');
|
||||
session.files[0]!.download();
|
||||
expect(saved.at(-1)!.file.name).toBe('invoicefdp.exedone');
|
||||
});
|
||||
|
||||
it("saves the chunks in order, reports the download manager's reads and when it finished", async () => {
|
||||
const { channel, session, handshake, download } = await downloading(3 * CHUNK_SIZE);
|
||||
expect(handshake.start).toHaveBeenCalled();
|
||||
|
||||
+7
-3
@@ -62,6 +62,10 @@ export const PBKDF2_ITERATIONS = 600_000;
|
||||
export const PROOF_TIMEOUT = 10_000;
|
||||
// Far beyond what a file system stores, but keeps an absurd name out of the page and the worker.
|
||||
export const MAX_NAME = 1024;
|
||||
// Controls and line separators in an offered name could fake log lines, bidi controls disguise its
|
||||
// extension: invoice\u202Efdp.exe shows as invoiceexe.pdf. They go before the name is shown, logged
|
||||
// or saved.
|
||||
const HIDDEN = /[\p{Cc}\p{Zl}\p{Zp}\p{Bidi_Control}]/gu;
|
||||
|
||||
export type Check = {
|
||||
local: string;
|
||||
@@ -779,10 +783,10 @@ export function receiveFile(
|
||||
if (typeof name !== 'string' || name.length > MAX_NAME || !Number.isSafeInteger(size) || size < 0) {
|
||||
return handshake.end('the sender offered no valid file');
|
||||
}
|
||||
meta = { name, size };
|
||||
events.log(`offered ${name} (${size} bytes)`);
|
||||
meta = { name: name.replace(HIDDEN, ''), size };
|
||||
events.log(`offered ${meta.name} (${size} bytes)`);
|
||||
events.status('wait', 'Click Download to save the file');
|
||||
events.incoming({ name, size, download });
|
||||
events.incoming({ ...meta, download });
|
||||
} else if (downloading && !complete) {
|
||||
received += data.byteLength;
|
||||
if (received > meta!.size) return fail('the sender sent more than it offered');
|
||||
|
||||
Reference in new issue
Block a user