fix: findings from the code review of the mail and sharing work
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
This commit is contained in:
22 files changed
+752
-108
No files matched your search
@@ -24,6 +24,9 @@ export default function KontoApp() {
|
||||
const sagen = (t: string, ok: boolean) => { setMsg({ t, ok }); setTimeout(() => setMsg(null), 5000); };
|
||||
|
||||
const patch = async (body: unknown, erfolg: string) => {
|
||||
// Den neuen Wert sofort übernehmen, sonst springt der Haken beim Rerender
|
||||
// auf den alten Stand zurück und man klickt aus Versehen ein zweites Mal.
|
||||
setMe((m) => (m ? { ...m, ...(body as object) } as Me : m));
|
||||
setLaeuft(true);
|
||||
const r = await fetch('/api/me', {
|
||||
method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
||||
@@ -89,7 +92,7 @@ export default function KontoApp() {
|
||||
<div className="ko-kopf"><span className="mono-label">Benachrichtigungen</span></div>
|
||||
<div className="ko-inhalt">
|
||||
<label className="ko-schalt">
|
||||
<input type="checkbox" checked={me.notify_jobs} disabled={!me.email}
|
||||
<input type="checkbox" checked={me.notify_jobs} disabled={!me.email || laeuft}
|
||||
onChange={(e) => patch({ notify_jobs: e.target.checked },
|
||||
e.target.checked ? 'Hinweise eingeschaltet.' : 'Hinweise ausgeschaltet.')} />
|
||||
<span>
|
||||
|
||||
@@ -83,7 +83,7 @@ export default function ShareDialog(
|
||||
setKopiert(true); setTimeout(() => setKopiert(false), 2000);
|
||||
};
|
||||
|
||||
const waText = `${titel || 'Bilder'}${wort ? '' : ''}\n${url}`;
|
||||
const waText = `${titel || 'Bilder'}\n${url}`;
|
||||
const waHref = `https://wa.me/?text=${encodeURIComponent(waText)}`;
|
||||
|
||||
const mailen = async () => {
|
||||
|
||||
@@ -5,8 +5,13 @@ import { useCallback, useEffect, useState } from 'react';
|
||||
* ihn ändern, abschalten oder löschen.
|
||||
*
|
||||
* Der Zähler ist bewusst schlicht: Aufrufe, Downloads und die Zahl der
|
||||
* unterschiedlichen Besucher. Wer geschaut hat, steht nirgends — die
|
||||
* IP-Adressen liegen nur gehasht vor und lassen sich nicht zurückrechnen.
|
||||
* unterschiedlichen Besucher. Namen oder Adressen stehen nirgends: Gespeichert
|
||||
* wird ein Hash der IP, gesalzen mit dem Server-Geheimnis **und** der Kennung
|
||||
* des Links. Damit lässt sich derselbe Besucher innerhalb eines Links
|
||||
* wiedererkennen, aber nicht über mehrere Links hinweg verfolgen.
|
||||
* Ehrlich benannt ist das Pseudonymisierung, nicht Anonymisierung — wer den
|
||||
* Server-Schlüssel hat, könnte den IPv4-Raum durchrechnen. Deshalb wird auch
|
||||
* nur 90 Tage aufgehoben.
|
||||
*/
|
||||
interface Share {
|
||||
id: string; slug: string; kind: string; title: string | null; note: string | null;
|
||||
@@ -49,7 +54,11 @@ export default function SharesApp() {
|
||||
const r = await fetch(`/api/shares/${id}`, {
|
||||
method: 'PATCH', headers: { 'Content-Type': 'application/json' }, body: JSON.stringify(body),
|
||||
}).then((x) => x.json()).catch(() => ({ error: 'Netzwerkfehler.' }));
|
||||
if (r.error) sagen(r.error); else await laden_();
|
||||
// `{ok:false}` heißt: Der Link gehört jemand anderem oder war schon in dem
|
||||
// Zustand. Ohne Rückmeldung wirkt der Knopf kaputt.
|
||||
if (r.error) sagen(r.error);
|
||||
else if (r.ok === false) { sagen('Nichts zu ändern — vielleicht schon geschehen?'); await laden_(); }
|
||||
else await laden_();
|
||||
};
|
||||
|
||||
const loeschen = async (s: Share) => {
|
||||
@@ -68,10 +77,10 @@ export default function SharesApp() {
|
||||
const details = async (s: Share) => {
|
||||
if (offen === s.id) { setOffen(null); return; }
|
||||
setOffen(s.id);
|
||||
if (!zugriffe[s.id]) {
|
||||
const r = await fetch(`/api/shares/${s.id}`).then((x) => x.json()).catch(() => ({ zugriffe: [] }));
|
||||
setZugriffe((z) => ({ ...z, [s.id]: r.zugriffe || [] }));
|
||||
}
|
||||
// Bei jedem Aufklappen neu laden — sonst zeigt die Liste beim zweiten Mal
|
||||
// einen alten Stand, ohne dass man es merkt.
|
||||
const r = await fetch(`/api/shares/${s.id}`).then((x) => x.json()).catch(() => ({ zugriffe: [] }));
|
||||
setZugriffe((z) => ({ ...z, [s.id]: r.zugriffe || [] }));
|
||||
};
|
||||
|
||||
if (laden) return <p className="tw-leer">Einen Moment …</p>;
|
||||
@@ -104,7 +113,7 @@ export default function SharesApp() {
|
||||
<div className="tw-zahlen">
|
||||
<span><b>{s.views}</b> Aufrufe</span>
|
||||
<span><b>{s.downloads}</b> Downloads</span>
|
||||
<span><b>{s.besucher}</b> {s.besucher === 1 ? 'Besucher' : 'Besucher'}</span>
|
||||
<span><b>{s.besucher}</b> {s.besucher === 1 ? 'Besucher' : 'Besuchende'}</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -158,8 +167,10 @@ export default function SharesApp() {
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
<p className="tw-fein">Es wird festgehalten, <b>wann</b> und <b>womit</b> geöffnet wurde —
|
||||
nicht <b>wer</b>. Die IP-Adresse liegt nur gehasht vor und lässt sich nicht zurückrechnen.</p>
|
||||
<p className="tw-fein">Festgehalten wird, <b>wann</b> und mit welcher Art Gerät geöffnet
|
||||
wurde — nicht <b>wer</b>. Von der IP-Adresse wird nur ein verschlüsselter Fingerabdruck
|
||||
gespeichert, der außerdem an diesen einen Link gebunden ist; über mehrere Links hinweg
|
||||
lässt sich damit niemand verfolgen. Nach 90 Tagen wird alles gelöscht.</p>
|
||||
</div>
|
||||
)}
|
||||
</article>
|
||||
|
||||
Reference in new issue
Block a user