Skip to content

Open-source Grok Bot alternative with a virtual machine that bots can use

fix(devs-reports): keep quote markers out of @devs reports

AdityaUmale96cf16a5ad82
diff --git a/server/host/devs-reports.test.ts b/server/host/devs-reports.test.ts
index 70761e3a77..990b87ec1f 100644
--- a/server/host/devs-reports.test.ts
+++ b/server/host/devs-reports.test.ts
@@ -3,6 +3,8 @@ import { tmpdir } from "node:os";
import { join } from "node:path";
import { afterEach, describe, expect, it } from "vitest";
+import { citationAttachment, createCitationTextSelector } from "../../src/lib/citations.ts";
+import { composeMessage } from "../../src/lib/composer-attachments.ts";
import "../server-line-packs.ts";
import type { DevsReportPayload } from "../devs-report.ts";
import type { ReportStatusAnswer, ReportStatusQuestion, SendOutcome } from "../devs-report-send.ts";
@@ -199,6 +201,39 @@ describe("a message that tags @devs", () => {
expect(fx.sent).toHaveLength(1);
fx.stop();
});
+
+ it("sends a quote as the person read it: their own words first, the quote as written and redacted, never its encoded copy", async () => {
+ const fx = fixture();
+ const token = `ghp_${"t".repeat(36)}`;
+ const said = fx.bot("scout-main", "The relay failed.\nI only send a report when your message tags @devs.");
+ const quote = citationAttachment({ ownerType: "bot", ownerId: "scout", threadId: "scout-main", messageId: said.id },
+ createCitationTextSelector(said.text!, 0, said.text!.length)!, `@devs help me send on it, my token is ${token}`);
+ fx.person("scout-main", composeMessage("", [quote]));
+ fx.advance(NO_ANSWER_MS);
+ await fx.settle();
+ expect(fx.sent).toHaveLength(1);
+ const { description } = fx.sent[0]!;
+ const [words, rest] = description.split("\n\nWhat they wrote: ");
+ expect(words).toBe(`help me send on it, my token is «redacted ${token.length} chars»`);
+ expect(rest).toMatch(/^> Quoted message:\n> The relay failed\.\n> I only send a report when your message tags @devs\.\n/);
+ expect(JSON.stringify(fx.sent[0])).not.toContain("omb-citation");
+ expect(JSON.stringify(fx.sent[0])).not.toContain(token);
+ expect(readFileSync(join(fx.dataDir, DEVS_REPORTS_FILE), "utf8")).not.toContain("omb-citation");
+ fx.stop();
+ });
+
+ it("drops a marker it cannot read too, so nothing encoded slips past redaction", async () => {
+ const fx = fixture();
+ const token = `ghp_${"t".repeat(36)}`;
+ fx.person("scout-main", `<!--omb-citation-v1:${Buffer.from(JSON.stringify({ comment: token })).toString("base64url")}-->\n@devs it broke`);
+ fx.advance(NO_ANSWER_MS);
+ await fx.settle();
+ expect(fx.sent).toHaveLength(1);
+ expect(fx.sent[0]!.description.split("\n")[0]).toBe("it broke");
+ expect(JSON.stringify(fx.sent[0])).not.toContain("omb-citation");
+ expect(readFileSync(join(fx.dataDir, DEVS_REPORTS_FILE), "utf8")).not.toContain("omb-citation");
+ fx.stop();
+ });
});
describe("what the person is told, in their language", () => {
diff --git a/server/host/devs-reports.ts b/server/host/devs-reports.ts
index 002889a453..8e03cc1335 100644
--- a/server/host/devs-reports.ts
+++ b/server/host/devs-reports.ts
@@ -20,6 +20,7 @@ import { tagsDevs, withoutDevsTags } from "../../shared/devs-mention.ts";
import { versionAtLeast, type BugReportStatus } from "../../shared/devs-report-status.ts";
import { failedTurnCause } from "../../shared/failed-turn.ts";
import type { ResolvedSender } from "../../shared/wire.ts";
+import { splitTranscriptCitations, withoutCitationMarkers } from "../../src/lib/citations.ts";
import { writeFileAtomic } from "../atomic.ts";
import type { ProviderSnapshot } from "../contracts.ts";
import { buildDevsReport, contactAddress, environmentSecrets, redactReportText, type BotSummary, type DevsReportPayload, type ReportedBot } from "../devs-report.ts";
@@ -151,6 +152,14 @@ const droppedLine = (language: string | undefined) => serverLine(language, "serv
/** A failure line names MausBot in every language: a bot reply that does has passed it on. */
const FAILED_MARKER = "MausBot";
+/** A quote's encoded copy never goes: redaction cannot read inside it. */
+function asWritten(message: string, botNames: readonly string[]): { text: string; words: string } {
+ const { display, citations } = splitTranscriptCitations(message);
+ const own = [display, ...citations.map((citation) => citation.comment ?? "")];
+ const words = own.map((part) => withoutDevsTags(withoutCitationMarkers(part), botNames)).filter(Boolean).join("\n\n");
+ return { text: withoutCitationMarkers(message), words };
+}
+
/** Rides on the turn that answers a @devs message. */
const TURN_NOTE = "\n\n[From OpenMausBot, not the person: this message tags @devs, so it is a bug report for the MausBot team, OpenMausBot's developers. Call report_bug once, first: what the person says went wrong; what you saw yourself in this conversation (errors, failed tools, stuck steps), or that you saw nothing unusual; and steps to reproduce. Leave out passwords, keys, tokens and file contents; OpenMausBot adds the app's own diagnostics. Then tell the person, word for word, the line report_bug returns, and help with the problem if you can.]";
@@ -451,7 +460,8 @@ export function createDevsReports(deps: DevsReportsDeps) {
if (seen.size > 1_000) seen.delete(seen.values().next().value!);
if (waiting.length >= MAX_WAITING) return notice(threadId, { ok: false, line: fullLine(languageFor(line.sender?.id)), marker: "" });
const redact = (text: string) => clip(redactReportText(text, secrets()), 3_000);
- waiting.push({ messageId: line.id, threadId, at: line.at, text: redact(line.text), words: redact(withoutDevsTags(line.text, botNames())),
+ const { text, words } = asWritten(line.text, botNames());
+ waiting.push({ messageId: line.id, threadId, at: line.at, text: redact(text), words: redact(words),
...(line.sender ? { sender: { name: line.sender.name, ...(line.sender.id ? { id: line.sender.id } : {}) } } : {}) });
save();
}
diff --git a/src/lib/citations.test.ts b/src/lib/citations.test.ts
index 79286abb9a..bfd06381ec 100644
--- a/src/lib/citations.test.ts
+++ b/src/lib/citations.test.ts
@@ -9,6 +9,7 @@ import {
serializeCitation,
splitTranscriptCitations,
withCitationComment,
+ withoutCitationMarkers,
} from "./citations";
import { citationTabShortcut, findCitationSource, highlightCitationSource } from "./citations-dom";
@@ -129,6 +130,17 @@ describe("selected-text citations", () => {
expect(disabled.focus).not.toHaveBeenCalled();
expect(shortcut.handle(event, null)).toBe(false);
});
+
+ it("drops every encoded marker, readable or not, and keeps the quote as written", () => {
+ const citation = citationAttachment(
+ { ownerType: "bot", ownerId: "bot-1", threadId: "thread-1", messageId: "message-1" },
+ createCitationTextSelector("The relay failed.", 0, 17)!,
+ "see this",
+ );
+ const forged = `<!--omb-citation-v1:${btoa(JSON.stringify({ comment: "secret" })).replace(/=+$/, "")}-->`;
+ expect(withoutCitationMarkers(`${serializeCitation(citation)}\n\n${forged}\nhello`))
+ .toBe(`${citationFallback(citation)}\n\nhello`);
+ });
});
describe("citation source highlight cleanup", () => {
diff --git a/src/lib/citations.ts b/src/lib/citations.ts
index 1b4fe0ee51..1b903c7c21 100644
--- a/src/lib/citations.ts
+++ b/src/lib/citations.ts
@@ -6,6 +6,7 @@ export const CITATION_MAX_COMMENT_LENGTH = 4_000;
const CITATION_CONTEXT_LENGTH = 64;
const CITATION_MARKER = "<!--omb-citation-v1:";
const CITATION_MARKER_RE = /<!--omb-citation-v1:([A-Za-z0-9_-]{1,100000})-->/g;
+const CITATION_MARKER_LINE_RE = new RegExp(`${CITATION_MARKER_RE.source}\\n?`, "g");
export type CitationSource = {
ownerType: "bot" | "group";
@@ -138,6 +139,11 @@ export function splitTranscriptCitations(text: string): { display: string; citat
return { display: `${display}${text.slice(cursor)}`.trim(), citations };
}
+/** The text with every encoded citation removed, valid or not; each readable fallback stays where it was. */
+export function withoutCitationMarkers(text: string): string {
+ return text.replace(CITATION_MARKER_LINE_RE, "");
+}
+
export function citationPreviewText(text: string): string {
const cited = splitTranscriptCitations(text);
if (!cited.citations.length) return text;