Skip to content

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

fix(citations): strip citation markers of any length before a report

AdityaUmalef6f65114bc9c
diff --git a/src/lib/citations.test.ts b/src/lib/citations.test.ts
index bfd06381ec..0c06bf6ea9 100644
--- a/src/lib/citations.test.ts
+++ b/src/lib/citations.test.ts
@@ -141,6 +141,10 @@ describe("selected-text citations", () => {
expect(withoutCitationMarkers(`${serializeCitation(citation)}\n\n${forged}\nhello`))
.toBe(`${citationFallback(citation)}\n\nhello`);
});
+
+ it("drops a marker too long to decode", () => {
+ expect(withoutCitationMarkers(`<!--omb-citation-v1:${"A".repeat(100_001)}-->\nhello`)).toBe("hello");
+ });
});
describe("citation source highlight cleanup", () => {
diff --git a/src/lib/citations.ts b/src/lib/citations.ts
index 1b903c7c21..2009751bc0 100644
--- a/src/lib/citations.ts
+++ b/src/lib/citations.ts
@@ -6,7 +6,8 @@ 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");
+// No length cap here: a marker too long to decode must still never reach a report.
+const CITATION_MARKER_LINE_RE = /<!--omb-citation-v1:[A-Za-z0-9_-]+-->\n?/g;
export type CitationSource = {
ownerType: "bot" | "group";