Two reviews, both dimensions. The serious ones, verified before fixing:
Sessions never expired server-side and survived a password reset. `Max-Age` is
a request to the browser, not a rule for the server, and `readSession` only
checked the signature -- a leaked cookie stayed valid indefinitely, and the very
reset meant to rescue a compromised account left the intruder logged in. A
demoted admin also kept admin, because the role came from the cookie. Now the
cookie carries a session epoch, `verifySession` checks the account against the
database on every request and takes the role from there, and the epoch is
bumped on password reset and on any role change. This was pre-existing, but the
reset feature promised safety it did not deliver.
"Allow download: off" did nothing for images with transparency -- exactly the
cutouts and stickers this tool exists for. The view path skipped resizing when
`has_alpha`, so the untouched original went out at full resolution, right-click
saveable. Verified: now 1500x2000 instead of 2400x3200, and the download route
returns 403.
The share title went into outgoing mail HTML unescaped while the message was
escaped -- a foreign link could be posted through the account's own
SPF/DKIM-signed mailserver. Both escaped now, plus length limits.
argon2 ran on every request for passphrase-protected links, including every
image: 130 ms and 64 MiB each. A 40-image gallery would have walked into the
memory limit, and a few dozen wrong guesses could have stalled the process.
Checked once, then a short-lived signed cookie scoped to that one link. The
passphrase moved from the query string to POST (it was landing in history and
proxy logs) and wrong guesses are now rate limited.
`days` accepted nonsense and quietly produced an unlimited link -- `Number('abc')`
is NaN and `NaN > 0` is false. `[]` coerced to 0, same result. Now rejected
outright, which matters when the pictures are of children.
Rate limits keyed on `clientAddress`, which is the *first* X-Forwarded-For
value -- set by the caller. Counting from the right instead, with the number of
trusted proxies configurable (TRUSTED_PROXIES, default 1), plus per-username and
per-recipient counters, a real limit on outgoing mail, and a limiter that
expires entries individually instead of clearing everyone's counter.
Also: expired links could still be mailed; missing PUBLIC_BASE_URL sent dead
links while reporting success; the reset endpoint's response time revealed
whether an account existed (send is no longer awaited); invalid UUIDs produced
500s; the email uniqueness race returned an HTML error page; share_views grew
without bound and is now one row per visitor per hour, hashed per link, user
agent reduced to browser and system, deleted after 90 days; double provenance
marking appended a second XMP packet with the older model instead of replacing.
21 new tests (97 total) for shares, mail and provenance -- all three were
completely untested, and that is where both reviews found the most.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01BNhLunz586g6DeYMa7Qsd1
67 lines
3.1 KiB
TypeScript
67 lines
3.1 KiB
TypeScript
import { test } from 'node:test';
|
|
import assert from 'node:assert/strict';
|
|
import { istMail, mailLayout, esc } from '../src/lib/mail.ts';
|
|
|
|
test('Gültige Adressen werden erkannt', () => {
|
|
for (const gut of ['mail@tillheidrich.de', 'a.b+c@sub.beispiel.co.uk', 'x@y.de', 'Oma_1949@web.de']) {
|
|
assert.ok(istMail(gut), `fälschlich abgelehnt: ${gut}`);
|
|
}
|
|
});
|
|
|
|
test('Ungültige Adressen werden abgelehnt — auch die mit angehängtem Zeilenumbruch', () => {
|
|
const schlecht = [
|
|
'', ' ', 'keine-adresse', 'a@b', '@b.de', 'a@.de', 'a b@c.de', 'a@b .de',
|
|
'a@b.de\nBcc: opfer@example.com', // Kopfzeilen-Einschleusung
|
|
'a@b.de\r\nSubject: x',
|
|
'a@b.de\n', // JS-„$" passt auch vor dem Zeilenende
|
|
'a'.repeat(250) + '@b.de', // zu lang
|
|
];
|
|
for (const s of schlecht) assert.ok(!istMail(s), `durchgerutscht: ${JSON.stringify(s)}`);
|
|
});
|
|
|
|
test('esc entschärft alles, was HTML zerlegen könnte', () => {
|
|
assert.equal(esc('<b>x</b>'), '<b>x</b>');
|
|
assert.equal(esc('a & b'), 'a & b');
|
|
assert.equal(esc('sagte "hallo"'), 'sagte "hallo"');
|
|
// Reihenfolge: & zuerst, sonst würde < zu &lt;
|
|
assert.equal(esc('<&>'), '<&>');
|
|
});
|
|
|
|
test('Die Überschrift der Mail wird immer maskiert', () => {
|
|
const html = mailLayout('</h1><script>alert(1)</script>', ['Text']);
|
|
assert.ok(!html.includes('<script>'), 'Skript-Tag im HTML gelandet');
|
|
assert.match(html, /<script>/);
|
|
});
|
|
|
|
test('Die Adresse des Knopfes wird maskiert', () => {
|
|
const html = mailLayout('Titel', ['Text'], { text: 'Ansehen', url: 'https://x.de/"><script>alert(1)</script>' });
|
|
assert.ok(!html.includes('<script>'), 'Skript-Tag über die Adresse eingeschleust');
|
|
});
|
|
|
|
test('Absätze dürfen bewusst HTML enthalten — deshalb müssen Aufrufer maskieren', () => {
|
|
// Das ist Absicht (für <b>), und genau deshalb ist es die Pflicht der
|
|
// Aufrufer, Nutzereingaben vorher durch esc() zu schicken. Der Fehler, den
|
|
// das Review gefunden hat, war eine Stelle, die das vergessen hatte.
|
|
const html = mailLayout('Titel', ['Ein <b>fettes</b> Wort']);
|
|
assert.match(html, /<b>fettes<\/b>/);
|
|
// Und mit esc() ist es entschärft:
|
|
assert.ok(!mailLayout('T', [esc('<b>x</b>')]).includes('<b>x</b>'));
|
|
});
|
|
|
|
test('Die Mail lädt nichts von fremden Servern nach', () => {
|
|
const html = mailLayout('Titel', ['Text'], { text: 'Los', url: 'https://klarbild.example/s/abc' });
|
|
// Keine Bilder, keine Schriften, keine Stylesheets von außen — sonst wäre es
|
|
// ein Zählpixel und würde in vielen Postfächern ohnehin blockiert.
|
|
assert.ok(!/<img/i.test(html), 'Bild im Mail-HTML');
|
|
assert.ok(!/<link/i.test(html), 'externe Ressource im Mail-HTML');
|
|
assert.ok(!/@import|url\(/i.test(html), 'CSS lädt etwas nach');
|
|
// Genau ein Ziel: der übergebene Link.
|
|
const ziele = [...html.matchAll(/href="([^"]*)"/g)].map((m) => m[1]);
|
|
assert.deepEqual([...new Set(ziele)], ['https://klarbild.example/s/abc']);
|
|
});
|
|
|
|
test('Ohne Knopf entsteht auch kein Link', () => {
|
|
const html = mailLayout('Titel', ['Nur Text']);
|
|
assert.ok(!html.includes('href='), 'unerwarteter Link');
|
|
});
|