Public: anyone can read this; the crew can change it.

Issue search never shows a sealed security report to a reader who may not see it #15060

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15041-issue-search-never-shows-a-sealed-securi → main 1 commit fork 1 thread · 1 unresolved

  • Merged. scout/15041-issue-search-never-shows-a-sealed-securi was merged into main as c388315.

Review

Sign in to review this change.
2 files changed +76 −6
src/core/issues.ts +32 −6
@@ -1304,7 +1304,11 @@ export interface IssueHit extends Issue {
13041304
13051305 /**
13061306 * Titles matching `query`, across every repo the viewer can see, in one
1307 * query. Sealed security reports are left out for everyone.
1307 * query. Sealed security reports are left out unless the caller names
1308 * where the viewer may see them (`sealed.ts`): `sealedOk`, the repos where
1309 * `canSeeSealed` holds, and `sealedBy`, the viewer's own reports when
1310 * `mayView` would let their author follow them. A caller that names
1311 * neither shows nothing sealed.
13081312 *
13091313 * The shape this replaces was a loop: take the twenty most recent visible
13101314 * repos, ask each of them for issues and again for pulls, forty queries for
@@ -1321,7 +1325,14 @@ export function searchIssuesVisibleTo(
13211325 db: Database,
13221326 viewer: { id: string } | undefined,
13231327 query: string,
1324 options: { limit?: number; kind?: IssueKind } = {},
1328 options: {
1329 limit?: number;
1330 kind?: IssueKind;
1331 /** Repos whose sealed issues the viewer may see (`canSeeSealed`). */
1332 sealedOk?: ReadonlySet<string>;
1333 /** The viewer's id, when they may follow the sealed reports they filed. */
1334 sealedBy?: string;
1335 } = {},

sealedBy is only honoured when it equals viewer.id, so the option is redundant with the viewer. A boolean makes the mismatch unrepresentable.

13251336 ): IssueHit[] {
13261337 const text = query.trim();
13271338 if (text === "") return [];
@@ -1329,11 +1340,26 @@ export function searchIssuesVisibleTo(
13291340 viewer?.id ?? "",
13301341 `%${likeEscape(text)}%`,
13311342 ];
1332 // Never a sealed row: who may see one is decided per repo (`sealed.ts`),
1333 // and a search across every repo has no such scope. A writer reads them
1334 // in the repo's own list.
1343 // A sealed row only where the caller said this viewer may see it: who
1344 // may is decided per repo (`sealed.ts`), so a search across every repo
1345 // is told, never guesses. Signed out, nothing sealed at all.
1346 const sealedOr = ["issue.sealed = 0"];
1347 if (viewer !== undefined) {
1348 const open = [...(options.sealedOk ?? [])];
1349 if (open.length > 0) {
1350 const at = params.length;
1351 params.push(...open);
1352 sealedOr.push(
1353 `issue.repo_id IN (${open.map((_, i) => `?${at + i + 1}`).join(",")})`,
1354 );
1355 }
1356 if (options.sealedBy !== undefined && options.sealedBy === viewer.id) {
1357 params.push(options.sealedBy);
1358 sealedOr.push(`issue.author_id = ?${params.length}`);
1359 }
1360 }
13351361 let where = `${repoVisible(viewer !== undefined)}
1336 AND issue.sealed = 0
1362 AND (${sealedOr.join(" OR ")})
13371363 AND issue.title LIKE ?2 ESCAPE '\\' COLLATE NOCASE`;
13381364 if (options.kind !== undefined) {
13391365 params.push(options.kind);
test/scale.test.ts +44
@@ -43,6 +43,7 @@ import { listEvents, listEventsVisibleTo } from "../src/core/events.ts";
4343 import { getPull, mergedPullNumbers } from "../src/core/pulls.ts";
4444 import { pin, pinnedRepoIds, isPinned } from "../src/core/pins.ts";
4545 import { getRepoById, getReposByIds, type Repo } from "../src/core/repos.ts";
46 import { canSeeSealed, sealedScope } from "../src/core/sealed.ts";
4647 import { getUserById, getUsersByIds, hasAnyUser } from "../src/core/users.ts";
4748 import { createToken, verifyToken } from "../src/core/tokens.ts";
4849 import {
@@ -508,6 +509,49 @@ describe("visibility is enforced in SQL, not after the fact", () => {
508509 expect(searchIssuesVisibleTo(app.db, undefined, "the public one")).toHaveLength(1);
509510 });
510511
512 test("search shows a sealed report to whoever `sealed.ts` lets see it, and to no one else", () => {
513 const report = createIssue(app.db, {
514 repoId: mine.id,
515 authorId: bob.id,
516 title: "quarantined token leak in the upload path",
517 sealed: true,
518 });
519 if (!report.ok) throw new Error("seed report");
520 const own = createIssue(app.db, {
521 repoId: mine.id,
522 authorId: alice.id,
523 title: "quarantined report alice filed",
524 sealed: true,
525 });
526 if (!own.ok) throw new Error("seed own report");
527 // The scope a caller derives from the one rule (`sealedScope`).
528 const scope = (user: User) => {
529 const s = sealedScope(app.db, mine, user);
530 return {
531 sealedOk: new Set(s.sealed === true ? [mine.id] : []),
532 ...(s.sealedBy === undefined ? {} : { sealedBy: s.sealedBy }),
533 };
534 };
535 // Alice reads the public repo but may not write it: only her own report.
536 expect(canSeeSealed(app.db, mine, alice)).toBe(false);
537 const asAlice = searchIssuesVisibleTo(app.db, alice, "quarantined", scope(alice));
538 expect(asAlice.map((hit) => hit.title)).toEqual(["quarantined report alice filed"]);
539 // Bob writes it: he finds both.
540 const asBob = searchIssuesVisibleTo(app.db, bob, "quarantined", scope(bob));
541 expect(asBob).toHaveLength(2);
542 // Signed out, nothing sealed, whatever the caller passes.
543 expect(
544 searchIssuesVisibleTo(app.db, undefined, "quarantined", {
545 sealedOk: new Set([mine.id]),
546 sealedBy: alice.id,
547 }),
548 ).toHaveLength(0);
549 // Someone else's id as `sealedBy` opens nothing.
550 expect(
551 searchIssuesVisibleTo(app.db, bob, "quarantined report", { sealedBy: alice.id }),
552 ).toHaveLength(0);
553 });
554
511555 test("an empty query is not a request for everything", () => {
512556 expect(searchIssuesVisibleTo(app.db, bob, " ")).toHaveLength(0);
513557 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs