abuse reports in the browser: notice, visitor tips, operator form and queue

A listing page says when the node hides the listing and who flagged it. A
visitor can tip off the operator (proof-of-work, nothing is hidden by it); the
signed-in operator can sign or withdraw a report from the page and works
through the tips at #/mine/reports. e2e covers the real binaries.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AeFqV96dVeBX94inzcgZKw
This commit is contained in:
2026-11-18 21:23:13 +01:00
co-authored by Claude Sonnet 5.5
parent 6d55222ac5
commit 0d5903be79
13 changed files with 873 additions and 6 deletions
+41
View File
@@ -88,6 +88,47 @@ export async function postMessage(envelope: Envelope): Promise<void> {
throw new HttpError(res.status, detail, requiredBits);
}
/** What one node makes of the abuse reports about a listing. */
export interface ReportSummary {
/** The node's own rules hide the listing from search. */
hidden: boolean;
/** Reports from reporters this node trusts, by category. */
trusted: Record<string, number>;
/** Reports from reporters it does not trust: shown, never counted. */
others: number;
/** Tips from visitors waiting for the operator. */
signals: number;
/** The operator's own report, if any. */
own?: string;
}
/** The reports about a listing, or null if this node cannot say. */
export async function getReportSummary(author: string, id: string): Promise<ReportSummary | null> {
try {
const res = await fetch(`/api/v1/reports?author=${author}&id=${id}`);
if (!res.ok) return null;
const s = (await res.json()) as Partial<ReportSummary>;
if (typeof s.hidden !== "boolean" || typeof s.trusted !== "object" || s.trusted === null) return null;
return { hidden: s.hidden, trusted: s.trusted, others: Number(s.others) || 0, signals: Number(s.signals) || 0, own: s.own };
} catch {
return null;
}
}
/** Tells the node's operator about a listing. Unsigned: backed only by proof-of-work (see sendTip). */
export async function postSignal(body: string): Promise<void> {
const res = await fetch("/api/v1/signals", { method: "POST", headers: { "Content-Type": "application/json" }, body });
if (res.ok) return;
let detail = res.statusText;
try {
const b = (await res.json()) as { error?: unknown };
if (typeof b.error === "string") detail = b.error;
} catch {
// keep the status text
}
throw new HttpError(res.status, detail);
}
/** Envelopes in a mailbox created at or after `since` (unix seconds). Unverified. */
export async function pollMailbox(tag: string, since: number): Promise<unknown[]> {
const data = await getJSON(`/api/v1/messages?mailbox=${encodeURIComponent(tag)}&since=${since}`);
+60
View File
@@ -72,6 +72,36 @@ const de = {
"Dieser Knoten kennt die Anzeige nicht (mehr), oder der Anbieter hat sein Gerät gewechselt. Lade die Anzeige neu.",
"send.429": "Zu viele Nachrichten. Bitte warte einen Moment.",
"send.busy": "Diese Anzeige bekommt gerade sehr viele Nachrichten. Versuche es später noch einmal.",
"rep.hiddenNotice": "Diese Anzeige wird auf diesem Knoten nicht in der Suche gezeigt, weil sie gemeldet wurde. Du siehst sie, weil du den Link kennst.",
"rep.counts": "Gemeldet von vertrauenswürdigen Betreibern: {list}.",
"rep.others": "Dazu kommen {n} Meldungen von Betreibern, denen dieser Knoten nicht vertraut. Sie zählen nicht.",
"rep.cat.scam": "Betrug",
"rep.cat.illegal": "rechtswidrige Inhalte",
"rep.cat.category": "falsche Kategorie",
"rep.cat.other": "Sonstiges",
"rep.report": "Anzeige melden",
"rep.intro": "Deine Meldung geht an den Betreiber dieses Knotens. Sie blendet nichts aus: er entscheidet.",
"rep.reason": "Grund",
"rep.note": "Anmerkung (optional)",
"rep.send": "Melden",
"rep.working": "Wird vorbereitet …",
"rep.thanks": "Danke. Der Betreiber dieses Knotens wurde informiert.",
"rep.fail": "Die Meldung konnte nicht gesendet werden: {detail}",
"rep.operator": "Als Betreiber melden",
"rep.operatorIntro": "Deine Meldung wird signiert und im Netz verbreitet. Auf deinem Knoten blendet sie die Anzeige sofort aus.",
"rep.operatorSend": "Signiert melden",
"rep.withdraw": "Meine Meldung zurückziehen",
"rep.done": "Gemeldet.",
"rep.withdrawn": "Zurückgezogen.",
"rep.mine": "Deine Meldung: {what}.",
"rep.title": "Meldungen",
"rep.tipsIntro": "Hinweise von Besuchern dieses Knotens. Sie blenden nichts aus: du entscheidest, ob du selbst meldest.",
"rep.none": "Keine Hinweise von Besuchern.",
"rep.work": "Aufwand {n} Bit",
"rep.sign": "Als „{what}“ melden",
"rep.dismiss": "Verwerfen",
"rep.open": "Anzeige ansehen",
"rep.back": "← Meine Anzeigen",
"send.other": "Senden fehlgeschlagen: {detail}",
"send.network": "Der Knoten ist nicht erreichbar.",
"chat.back": "← Zur Anzeige",
@@ -355,6 +385,36 @@ const en: Record<keyof typeof de, string> = {
"This node does not know the listing (anymore), or the owner changed device. Reload the listing.",
"send.429": "Too many messages. Please wait a moment.",
"send.busy": "This listing is receiving a lot of messages right now. Please try again later.",
"rep.hiddenNotice": "This listing is hidden from search on this node because it was reported. You can see it because you have its link.",
"rep.counts": "Reported by trusted operators: {list}.",
"rep.others": "{n} more reports came from operators this node does not trust. They do not count.",
"rep.cat.scam": "scam",
"rep.cat.illegal": "illegal content",
"rep.cat.category": "wrong category",
"rep.cat.other": "other",
"rep.report": "Report this listing",
"rep.intro": "Your report goes to the operator of this node. It hides nothing by itself: they decide.",
"rep.reason": "Reason",
"rep.note": "Note (optional)",
"rep.send": "Send report",
"rep.working": "Preparing …",
"rep.thanks": "Thank you. The operator of this node has been told.",
"rep.fail": "The report could not be sent: {detail}",
"rep.operator": "Report as operator",
"rep.operatorIntro": "Your report is signed and shared with the network. On your node it hides the listing at once.",
"rep.operatorSend": "Sign and report",
"rep.withdraw": "Withdraw my report",
"rep.done": "Reported.",
"rep.withdrawn": "Withdrawn.",
"rep.mine": "Your report: {what}.",
"rep.title": "Reports",
"rep.tipsIntro": "Tips from visitors of this node. They hide nothing: you decide whether to report yourself.",
"rep.none": "No tips from visitors.",
"rep.work": "Effort {n} bits",
"rep.sign": "Report as “{what}”",
"rep.dismiss": "Dismiss",
"rep.open": "View listing",
"rep.back": "← My listings",
"send.other": "Sending failed: {detail}",
"send.network": "The node is not reachable.",
"chat.back": "← Back to the listing",
+3
View File
@@ -5,6 +5,7 @@ import { decodeGeohash } from "./geohash.ts";
import { lang, t, type Key } from "./i18n.ts";
import { contactPanel, showConversation, showInbox } from "./chat.ts";
import { showOwner } from "./owner.ts";
import { reportPanel, showReports } from "./reports.ts";
import { getToken, setToken } from "./ownerApi.ts";
import { showPublish } from "./publish.ts";
import { showRegions } from "./regions.ts";
@@ -299,6 +300,7 @@ function listingBody(l: Listing): HTMLElement[] {
? h("section", { class: "panel" }, h("h2", null, t("detail.features")), h("ul", { class: "chips" }, ...l.features.map((f) => h("li", null, f))))
: h("span"),
contactPanel(l),
reportPanel(l),
];
}
@@ -377,6 +379,7 @@ function route(): void {
else if (c) void showConversation(c[1]!, c[2]!, c[3]!);
else if (path === "/messages") showInbox();
else if (path === "/mine/regions") showRegions();
else if (path === "/mine/reports") void showReports();
else if (path === "/mine/new") void showPublish();
else if (edit) void showPublish(edit[1]);
else if (own) void showOwner(own[1], own[2]);
+1 -1
View File
@@ -213,7 +213,7 @@ const tick = () => new Promise<void>((r) => setTimeout(r, 0));
* canonical text is split once around it and the shared prefix is hashed once.
* Yields to the page now and then so it stays responsive.
*/
async function mine(env: Envelope, difficulty: number): Promise<void> {
export async function mine(env: { pow: number }, difficulty: number): Promise<void> {
const canon = canonicalize({ ...env, pow: 0 });
const marker = '"pow":0,';
const at = canon.indexOf(marker);
+1
View File
@@ -91,6 +91,7 @@ export async function showOwner(listingId?: string, thread?: string): Promise<vo
h("p", null, h("a", { class: "btn primary", href: "#/mine/new" }, t("own.new"))),
listingsBox,
h("p", null, h("a", { class: "btn", href: "#/mine/regions" }, t("reg.title"))),
h("p", null, h("a", { class: "btn", href: "#/mine/reports" }, t("rep.title"))),
h("p", null, h("button", { type: "button", class: "btn", onclick: logout }, t("own.logout"))),
);
+25
View File
@@ -175,6 +175,31 @@ export async function getBlocked(): Promise<Blocked[]> {
return (await call("GET", "/api/v1/blocked")) as Blocked[];
}
/** A visitor's tip about a listing, as the operator sees it. */
export interface Tip {
id: number;
author: string;
listing: string;
title?: string;
category: string;
note: string;
created_at: number;
work: number;
}
export async function getTips(): Promise<Tip[]> {
return (await call("GET", "/api/v1/signals")) as Tip[];
}
export async function dismissTips(author: string, listing: string): Promise<void> {
await call("DELETE", `/api/v1/signals/${e(author)}/${e(listing)}`);
}
/** Signs a report as this node's operator and shares it; the answer is the node's new view. */
export async function signReport(author: string, listing: string, category: string, note: string): Promise<void> {
await call("POST", "/api/v1/reports", { listing: { author, id: listing }, category, note });
}
/** The saved address of a listing, or null if none is saved. */
export async function getAddress(listing: string): Promise<Address | null> {
try {
+238
View File
@@ -0,0 +1,238 @@
// Abuse reports in the browser: the notice on a flagged listing, the form a
// visitor uses to tip off the node's operator, and the operator's own report
// form and queue of tips. Nothing here hides anything: a node's rules do, and
// they are the operator's (see "Abuse reports" in docs/PROTOCOL.md).
import { HttpError, getReportSummary, postSignal, type ReportSummary } from "./api.ts";
import { append, clear, h } from "./dom.ts";
import { t, type Key } from "./i18n.ts";
import { canonicalize } from "./jcs.ts";
import { DEFAULT_MESSAGE_DIFFICULTY, mine } from "./message.ts";
import { renderLogin } from "./owner.ts";
import { Unauthorized, dismissTips, getToken, getTips, signReport, type Tip } from "./ownerApi.ts";
import { nowSeconds, state } from "./state.ts";
import type { Listing } from "./verify.ts";
/** The reasons a visitor or an operator can give, in the order they are offered. */
const REASONS = ["scam", "illegal", "category", "other"] as const;
const MAX_NOTE_BYTES = 300;
const reasonLabel = (c: string): string => (REASONS as readonly string[]).includes(c) ? t(`rep.cat.${c}` as Key) : c;
const utf8 = (s: string) => new TextEncoder().encode(s).length;
/**
* Tells the node's operator about a listing. A visitor has no key, so the
* request is not signed: it is backed by proof-of-work, mined here like the
* proof of a message, and the node keeps it for its operator only.
*/
async function sendTip(author: string, id: string, category: string, note: string): Promise<void> {
const bits = state.node?.message_difficulty ?? DEFAULT_MESSAGE_DIFFICULTY;
// Keys in canonical order; `pow` must be followed by another key (see mine()).
const body = { category, created_at: nowSeconds(), listing: { author, id }, note, pow: 0, v: 1 };
await mine(body, bits);
await postSignal(canonicalize(body));
}
function describe(e: unknown): string {
if (e instanceof Unauthorized) return t("reg.signedOut");
if (e instanceof HttpError) return e.detail;
return t("send.network");
}
/** A select of reasons and a note box, with the way to read them back. */
function reasonFields(): { nodes: HTMLElement[]; read: () => { category: string; note: string } } {
const select = h("select", { name: "category" }, ...REASONS.map((c) => h("option", { value: c }, reasonLabel(c))));
const note = h("textarea", { name: "note", rows: 3, maxlength: MAX_NOTE_BYTES, "aria-label": t("rep.note"), placeholder: t("rep.note") });
return {
nodes: [h("label", null, t("rep.reason"), " ", select), note],
read: () => ({ category: select.value, note: note.value.trim() }),
};
}
/** What this node makes of the reports about the listing, as a few lines of text. */
function summaryLines(sum: ReportSummary): HTMLElement[] {
const out: HTMLElement[] = [];
if (sum.hidden) out.push(h("p", { class: "note warn", role: "status" }, t("rep.hiddenNotice")));
const counted = Object.entries(sum.trusted).filter(([, n]) => n > 0);
if (counted.length) {
out.push(h("p", { class: "muted" }, t("rep.counts", { list: counted.map(([c, n]) => `${reasonLabel(c)} (${n})`).join(", ") })));
}
if (sum.others > 0) out.push(h("p", { class: "muted small" }, t("rep.others", { n: sum.others })));
if (sum.own) out.push(h("p", { class: "muted" }, t("rep.mine", { what: reasonLabel(sum.own) })));
return out;
}
/**
* The report section of a listing page. It fills in once the node has said what
* it makes of the reports, and works without that: the forms are always there.
*/
export function reportPanel(l: Listing): HTMLElement {
const lines = h("div", null);
const root = h("section", { class: "panel report" }, lines, visitorForm(l));
const refresh = () =>
void getReportSummary(l.author, l.id).then((sum) => {
if (!sum) return;
clear(lines);
append(lines, summaryLines(sum));
});
if (getToken()) root.append(operatorForm(l, refresh));
refresh();
return root;
}
function visitorForm(l: Listing): HTMLElement {
const fields = reasonFields();
const status = h("p", { class: "muted", role: "status" });
const problem = h("p", { class: "error", role: "alert" });
const button = h("button", { type: "submit", class: "btn" }, t("rep.send"));
const form = h(
"form",
{
class: "compose",
onsubmit: (ev: Event) => {
ev.preventDefault();
const { category, note } = fields.read();
problem.textContent = "";
if (utf8(note) > MAX_NOTE_BYTES) {
problem.textContent = t("rep.fail", { detail: t("rep.note") });
return;
}
button.disabled = true;
status.textContent = t("rep.working");
void sendTip(l.author, l.id, category, note)
.then(() => {
clear(form);
form.append(h("p", { role: "status" }, t("rep.thanks")));
})
.catch((e: unknown) => {
button.disabled = false;
status.textContent = "";
problem.textContent = t("rep.fail", { detail: describe(e) });
});
},
},
h("p", { class: "muted" }, t("rep.intro")),
...fields.nodes,
h("div", { class: "actions" }, button),
status,
problem,
);
return h("details", { class: "report-form" }, h("summary", null, t("rep.report")), form);
}
/** The operator's own signed report (or taking it back). Only offered with the admin token. */
function operatorForm(l: Listing, changed: () => void): HTMLElement {
const fields = reasonFields();
const status = h("p", { class: "muted", role: "status" });
const problem = h("p", { class: "error", role: "alert" });
const act = (category: string, note: string, done: Key) => {
problem.textContent = "";
void signReport(l.author, l.id, category, note)
.then(() => {
status.textContent = t(done);
changed();
})
.catch((e: unknown) => {
problem.textContent = t("rep.fail", { detail: describe(e) });
});
};
return h(
"details",
{ class: "report-form" },
h("summary", null, t("rep.operator")),
h(
"form",
{
class: "compose",
onsubmit: (ev: Event) => {
ev.preventDefault();
const { category, note } = fields.read();
act(category, note, "rep.done");
},
},
h("p", { class: "muted" }, t("rep.operatorIntro")),
...fields.nodes,
h(
"div",
{ class: "actions" },
h("button", { type: "submit", class: "btn primary" }, t("rep.operatorSend")),
h("button", { type: "button", class: "btn", onclick: () => act("withdrawn", "", "rep.withdrawn") }, t("rep.withdraw")),
),
status,
problem,
),
);
}
// --- the operator's queue -----------------------------------------------------------
/** The tips visitors left on this node, one card per listing. */
export async function showReports(): Promise<void> {
const root = document.getElementById("app")!;
clear(root);
if (!getToken()) {
renderLogin(false);
return;
}
const list = h("div", null);
const problem = h("p", { class: "error", role: "alert" });
append(root, [
h("a", { class: "back", href: "#/mine" }, t("rep.back")),
h("h1", null, t("rep.title")),
h("p", { class: "muted" }, t("rep.tipsIntro")),
problem,
list,
]);
const load = async (): Promise<void> => {
let tips: Tip[];
try {
tips = await getTips();
} catch (e) {
if (e instanceof Unauthorized) return renderLogin(true);
problem.textContent = describe(e);
return;
}
clear(list);
if (tips.length === 0) {
list.append(h("p", { class: "muted" }, t("rep.none")));
return;
}
const byListing = new Map<string, Tip[]>();
for (const tip of tips) byListing.set(`${tip.author}/${tip.listing}`, [...(byListing.get(`${tip.author}/${tip.listing}`) ?? []), tip]);
for (const group of byListing.values()) list.append(card(group, load, problem));
};
await load();
}
function card(group: Tip[], reload: () => Promise<void>, problem: HTMLElement): HTMLElement {
const first = group[0]!;
const fail = (e: unknown) => {
problem.textContent = describe(e);
};
const categories = [...new Set(group.map((g) => g.category))];
return h(
"section",
{ class: "panel" },
h("h2", null, h("a", { href: `#/l/${first.author}/${first.listing}` }, first.title || t("rep.open"))),
h(
"ul",
null,
...group.map((g) =>
h("li", null, `${reasonLabel(g.category)}: ${g.note || "–"} `, h("span", { class: "muted small" }, `(${t("rep.work", { n: g.work })})`)),
),
),
h(
"div",
{ class: "actions" },
...categories.map((c) =>
h(
"button",
{ type: "button", class: "btn", onclick: () => void signReport(first.author, first.listing, c, group.find((g) => g.category === c)?.note ?? "").then(reload).catch(fail) },
t("rep.sign", { what: reasonLabel(c) }),
),
),
h("button", { type: "button", class: "btn", onclick: () => void dismissTips(first.author, first.listing).then(reload).catch(fail) }, t("rep.dismiss")),
),
);
}