From f284dfe3d1caf0049267f333f62be7966210102a Mon Sep 17 00:00:00 2001 From: jonwiggins Date: Wed, 18 Nov 2026 14:34:48 -0700 Subject: [PATCH 1/3] fix: ignore redacted-only recovered text (PRO-7938) --- src/lib/analyzer/checks.ts | 2 ++ tests/checks.test.ts | 52 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 tests/checks.test.ts diff --git a/src/lib/analyzer/checks.ts b/src/lib/analyzer/checks.ts index bc47a4c..fc5f5ef 100644 --- a/src/lib/analyzer/checks.ts +++ b/src/lib/analyzer/checks.ts @@ -394,6 +394,8 @@ export function checkPage(extract: PageExtract, deadline?: number): Finding[] { // A mark with real text under it — a recoverable leak. const check = leakCheckId(cover.kind, extract.hasLargeImage) const recovered = recoverUnder(overlapping, cover.bbox) + // A REDACTED-only label is not recovered document content. + if (recovered.toLowerCase() === 'redacted') continue const {title, detail} = describeLeak(check, cover.kind) findings.push({ id: `${check}-${extract.page}-${idx++}`, diff --git a/tests/checks.test.ts b/tests/checks.test.ts new file mode 100644 index 0000000..7f927b6 --- /dev/null +++ b/tests/checks.test.ts @@ -0,0 +1,52 @@ +import {describe, it, expect} from 'vitest' +import {checkPage} from '@/lib/analyzer/checks' +import type {PageExtract} from '@/lib/analyzer/extract' +import type {BBox} from '@/lib/analyzer/types' + +function pageWithCoveredText(texts: string[]): PageExtract { + const boxes: BBox[] = texts.map((_, i) => [ + 72, + 100 + i * 28, + 272, + 114 + i * 28, + ]) + return { + page: 1, + width: 612, + height: 792, + hasLargeImage: false, + lightMarks: [], + runs: texts.map((str, i) => ({ + str, + bbox: boxes[i]!, + fontFamily: 'Helvetica', + fontClass: 'sans', + fontSizePt: 12, + isWhitespace: false, + dir: 'ltr', + })), + covers: boxes.map((bbox) => ({ + bbox, + kind: 'path-fill', + rgb: [0, 0, 0], + opIndex: 1, + })), + } +} + +describe('recovered redaction labels', () => { + it('ignores a label regardless of case and surrounding whitespace', () => { + expect(checkPage(pageWithCoveredText([' ReDaCtEd ']))).toEqual([]) + }) + + it('keeps a nearby leak whose text includes the word redacted', () => { + const findings = checkPage( + pageWithCoveredText(['REDACTED', 'redacted budget']) + ) + expect(findings).toHaveLength(1) + expect(findings[0]).toMatchObject({ + severity: 'leak', + recovered: {text: 'redacted budget'}, + }) + }) +}) From 4283d84d710a9831cf47c2de0e6dbda334363595 Mon Sep 17 00:00:00 2001 From: jonwiggins Date: Thu, 19 Nov 2026 18:27:16 -0700 Subject: [PATCH 2/3] fix: group redaction findings by page (PRO-7985) --- e2e/upload.spec.ts | 50 +++++ examples/12-page-findings.pdf | Bin 0 -> 1325 bytes examples/generate.mjs | 38 ++++ examples/manifest.json | 16 ++ src/components/results/FindingCard.tsx | 250 +++++++++++++++---------- src/components/results/ResultsView.tsx | 40 ++-- src/lib/analyzer/checks.ts | 33 +++- tests/merge-findings.test.ts | 49 +++++ 8 files changed, 360 insertions(+), 116 deletions(-) create mode 100644 examples/12-page-findings.pdf diff --git a/e2e/upload.spec.ts b/e2e/upload.spec.ts index faf0105..aca1fe7 100644 --- a/e2e/upload.spec.ts +++ b/e2e/upload.spec.ts @@ -87,4 +87,54 @@ test.describe('upload flow detects and alerts', () => { await page.getByRole('button', {name: /see your report/i}).click() await expect(page.getByText('Your redaction report')).toBeVisible() }) + + test('groups each page and shows every distinct finding in one preview', async ({ + page, + }) => { + await page.goto('/') + await page + .locator('input[type=file]') + .setInputFiles(`${examplesDir}/12-page-findings.pdf`) + const first = page.getByRole('region', { + name: 'Problems on page 1', + exact: true, + }) + const second = page.getByRole('region', { + name: 'Problems on page 2', + exact: true, + }) + await expect( + page.getByRole('region', {name: /Problems on page/}) + ).toHaveCount(2) + await expect(first.getByText('4 findings', {exact: true})).toBeVisible() + await expect(second.getByText('1 finding', {exact: true})).toBeVisible() + await expect( + first.getByText('This redaction leaks its length') + ).toBeVisible() + await expect(first.getByText('Northwind', {exact: true})).toHaveCount(0) + const reveal = first.getByRole('button', { + name: 'Reveal what was under the box', + }) + await expect(reveal).toHaveCount(3) + // Revealing one passage must not reveal the other passages. + await reveal.first().click() + await expect(first.getByText('Northwind', {exact: true})).toHaveCount(1) + await reveal.first().click() + await reveal.first().click() + await expect(first.getByText('Northwind', {exact: true})).toHaveCount(2) + await expect( + first.getByText('Project Cardinal', {exact: true}) + ).toBeVisible() + await first + .getByRole('button', {name: 'Show all findings on this page'}) + .click() + await expect( + first.getByRole('img', {name: 'Page 1', exact: true}) + ).toHaveCount(1) + await expect(first.locator('[aria-label^="Finding "]')).toHaveCount(4) + await expect(first.getByText(/Annotation marks are hidden/)).toBeVisible() + await expect( + second.getByRole('img', {name: 'Page 2', exact: true}) + ).toHaveCount(0) + }) }) diff --git a/examples/12-page-findings.pdf b/examples/12-page-findings.pdf new file mode 100644 index 0000000000000000000000000000000000000000..8287fac3684883ca535f7a53624f055782d873cb GIT binary patch literal 1325 zcmcIk%Wm5+5WMRv<`SSi)Dk68vVb5!?8a!(mtpH>^uSoOEyER4if+?QI8{QXQ^W?wm?IHdFXWjc#l-9TB*|DcOfjm#q!0pSx7BF#eLyR9nY zNG0j`XSz0fyQDI?{)r)mW*{ILLAv}>8I>dU8gUoxH^cM3n)kX|yA7f^;&N+ewff?X za-tOw5%Lw%a1bC30^|i=d^FZ=zL!<;68RQ)xyO|Tuxqb@C0R;fIUGm`39GUCZTv(d z3WGn1w9C(spOCZ_bcIf>+3KakSlObi)UL1hGDCJ5`9@=D3XQVHvuKfpgCTl2R>s0@ z2>j4W4f-SzGcInAg7?)Q1$n7E;LcUtuD%hi4Vz~A^ZmVRT**NJf23;NuDsE^Z`zeh zb!0BK#VJc;7#wKkU-x7*_%l9{MH)h8DMS)eo5*GC*w%6Z4c{J($F~qiLhSETA^r*e z*2Vwo+99bO|AIX4)jQXw$$v8KMW-IEUXj-`FZlH!kus84;SkHvtfD%^B$dt2QA~t% z{hY { ) } +// 12) Multiple findings per page, including a repeated drawing operation. +{ + const secret = 'Northwind' + const w = tw(secret, SIZE) + const first = `${textAt(X, 700, secret)}0 0 0 rg\n${blackBox(X, 700, w)} f\n` + let c = first + c += `${blackBox(X, 700, w)} f\n` // duplicate cover, not another leak + c += textAt(320, 700, secret) + c += `${blackBox(320, 700, w)} f\n` + c += textAt(X, 600, 'Project Cardinal') + c += textAt(X, 500, 'The code is ') + const gapX = X + tw('The code is ', SIZE) + c += textAt(gapX + 50, 500, ' for this project.') + c += `${blackBox(gapX, 500, 50)} f\n` + const objs = [ + '<< /Type /Catalog /Pages 2 0 R >>', + '<< /Type /Pages /Kids [3 0 R 7 0 R] /Count 2 >>', + page(' /Annots [6 0 R]'), + stream(c), + FONT, + `<< /Type /Annot /Subtype /Square /Rect [72 597 ${(X + tw('Project Cardinal', SIZE)).toFixed(1)} 612] /C [0 0 0] /IC [0 0 0] /CA 1 >>`, + page('', 8), + stream(first), + ] + add( + '12-page-findings.pdf', + 'Grouped pages with distinct and duplicate findings', + serialize(objs), + { + grade: 'F', + expectChecks: ['superficial-mark', 'removable-annotation', 'word-size'], + minLeaks: 4, + minWarnings: 1, + recoveredIncludes: ['Northwind', 'Project Cardinal'], + } + ) +} + writeFileSync(join(OUT, 'manifest.json'), JSON.stringify(fixtures, null, 2)) console.log(`Wrote ${fixtures.length} example PDFs + manifest.json to ${OUT}`) for (const f of fixtures) console.log(` ${f.file} — grade ${f.grade}`) diff --git a/examples/manifest.json b/examples/manifest.json index ef8baf2..36ee075 100644 --- a/examples/manifest.json +++ b/examples/manifest.json @@ -93,5 +93,21 @@ "recoveredIncludes": [ "2,750,000" ] + }, + { + "file": "12-page-findings.pdf", + "title": "Grouped pages with distinct and duplicate findings", + "grade": "F", + "expectChecks": [ + "superficial-mark", + "removable-annotation", + "word-size" + ], + "minLeaks": 4, + "minWarnings": 1, + "recoveredIncludes": [ + "Northwind", + "Project Cardinal" + ] } ] \ No newline at end of file diff --git a/src/components/results/FindingCard.tsx b/src/components/results/FindingCard.tsx index ef685d5..a061933 100644 --- a/src/components/results/FindingCard.tsx +++ b/src/components/results/FindingCard.tsx @@ -12,56 +12,52 @@ type RenderResult = {dataUrl: string; pageWidth: number; pageHeight: number} const SEVERITY_STYLE = { leak: { chip: 'bg-brand-vermillion/10 text-brand-vermillion border-brand-vermillion/30', - bar: 'bg-brand-vermillion', + ring: 'ring-brand-vermillion', label: 'Recoverable', }, warning: { chip: 'bg-brand-carrot/10 text-brand-pumpkin border-brand-carrot/40', - bar: 'bg-brand-carrot', + ring: 'ring-brand-carrot', label: 'Risky', }, info: { chip: 'bg-brand-blue/10 text-brand-blue border-brand-blue/30', - bar: 'bg-brand-blue', + ring: 'ring-brand-blue', label: 'Heads-up', }, } as const +/** One problem card per page, with all of its findings on a shared preview. */ export function FindingCard({ - finding, + findings, docTokens, onRenderPage, }: { - finding: Finding + findings: Finding[] docTokens: string[] onRenderPage?: ( page: number, opts?: {revealAnnotations?: boolean} ) => Promise }) { - const meta = CHECK_META[finding.check] - const sev = SEVERITY_STYLE[finding.severity] - const [revealed, setRevealed] = useState(false) + const page = findings[0]!.page const [render, setRender] = useState(null) const [rendering, setRendering] = useState(false) const [renderError, setRenderError] = useState(false) - - const revealText = finding.recovered?.text ?? null - - // For annotation-based redactions, render with annotations disabled so the - // cover is removed and the text it was hiding shows in the page image. - const isAnnotationCover = - finding.coverKind === 'redact-annot' || - finding.coverKind === 'square-annot' || - finding.coverKind === 'highlight-annot' + // Removing annotations exposes their contents; drawn covers remain in place. + const hasAnnotationCover = findings.some((finding) => + ['redact-annot', 'square-annot', 'highlight-annot'].includes( + finding.coverKind + ) + ) const handleViewInDoc = async () => { - if (!onRenderPage || finding.page < 1 || render || rendering) return + if (!onRenderPage || page < 1 || render || rendering) return setRendering(true) setRenderError(false) try { setRender( - await onRenderPage(finding.page, {revealAnnotations: isAnnotationCover}) + await onRenderPage(page, {revealAnnotations: hasAnnotationCover}) ) } catch { setRenderError(true) @@ -71,72 +67,31 @@ export function FindingCard({ } return ( -
-
+
-
-
- - - -
-

{finding.title}

-

- {meta.short} - {finding.page > 0 && <> · page {finding.page}} -

-
-
- - {sev.label} +
+

Page {page}

+ + {findings.length} {findings.length === 1 ? 'finding' : 'findings'}
-

- {finding.detail} -

+
    + {findings.map((finding, index) => ( +
  1. + +
  2. + ))} +
- {revealText && ( -
- -
- {revealed ? revealText : '•••••••••••••••••••'} - {finding.recovered && finding.recovered.text.length === 0 && ( - (no readable text) - )} -
-
- )} - - {finding.width && ( - - )} - - {onRenderPage && finding.page > 0 && finding.bbox && ( + {onRenderPage && page > 0 && findings.some((f) => f.bbox) && (
{!render && ( )} {renderError && ( @@ -159,28 +112,121 @@ export function FindingCard({ page.

)} - {render && finding.bbox && ( -
- {/* eslint-disable-next-line @next/next/no-img-element */} - {`Page - -
+ {render && ( + <> + {hasAnnotationCover && ( +

+ Annotation marks are hidden in this preview to show the + content underneath. +

+ )} +
+ {/* eslint-disable-next-line @next/next/no-img-element */} + {`Page + {findings.map( + (finding, index) => + finding.bbox && ( + + + {index + 1} + + + ) + )} +
+ )}
)}
-
+
+ ) +} + +function FindingDetail({ + finding, + number, + docTokens, +}: { + finding: Finding + number: number + docTokens: string[] +}) { + const meta = CHECK_META[finding.check] + const sev = SEVERITY_STYLE[finding.severity] + const [revealed, setRevealed] = useState(false) + const revealText = finding.recovered?.text + + return ( + <> +
+
+ + {number} + +
+

{finding.title}

+

+ {meta.short} +

+
+
+ + {sev.label} + +
+

+ {finding.detail} +

+ {revealText && ( +
+ +
+ {revealed ? revealText : '•••••••••••••••••••'} +
+
+ )} + {finding.width && ( + + )} + ) } diff --git a/src/components/results/ResultsView.tsx b/src/components/results/ResultsView.tsx index 6378ce1..0a329bd 100644 --- a/src/components/results/ResultsView.tsx +++ b/src/components/results/ResultsView.tsx @@ -2,7 +2,7 @@ import {useMemo, useState} from 'react' import {FiRefreshCw, FiShare2, FiCheckCircle} from 'react-icons/fi' -import type {AnalysisResult} from '@/lib/analyzer/types' +import type {AnalysisResult, Finding} from '@/lib/analyzer/types' import {GRADE_META} from '@/lib/checkMeta' import {RedactionGradeBadge} from '../share/RedactionGrade' import {ReportModal} from '../share/ReportModal' @@ -28,15 +28,26 @@ export function ResultsView({ const meta = GRADE_META[summary.grade] const [reportOpen, setReportOpen] = useState(false) - const findings = useMemo( - () => - [...result.findings].sort( + const pages = useMemo(() => { + const groups = new Map() + const sorted = [...result.findings].sort( + (a, b) => + SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity] || + a.page - b.page + ) + for (const finding of sorted) { + const group = groups.get(finding.page) + if (group) group.push(finding) + else groups.set(finding.page, [finding]) + } + return [...groups.values()].map((group) => + group.sort( (a, b) => - SEVERITY_ORDER[a.severity] - SEVERITY_ORDER[b.severity] || - a.page - b.page - ), - [result.findings] - ) + (a.bbox?.[1] ?? Infinity) - (b.bbox?.[1] ?? Infinity) || + (a.bbox?.[0] ?? Infinity) - (b.bbox?.[0] ?? Infinity) + ) + ) + }, [result.findings]) const clean = summary.totalFindings === 0 @@ -60,7 +71,7 @@ export function ResultsView({ {summary.leakCount} {' '} - recoverable ·{' '} + recoverable passages ·{' '} {summary.warningCount} {' '} @@ -114,10 +125,13 @@ export function ResultsView({
) : (
- {findings.map((finding) => ( +

+ Problems on {pages.length} {pages.length === 1 ? 'page' : 'pages'} +

+ {pages.map((findings) => ( diff --git a/src/lib/analyzer/checks.ts b/src/lib/analyzer/checks.ts index fc5f5ef..040ac66 100644 --- a/src/lib/analyzer/checks.ts +++ b/src/lib/analyzer/checks.ts @@ -255,6 +255,37 @@ function isVisibleLabelRun( * their own thing and pass through untouched. */ export function mergeAdjacentLeaks(findings: Finding[]): Finding[] { + // Repeated PDF drawing operations can detect the same box twice. Remove + // those before joining lines so the recovered passage and counts stay unique. + // Position is part of the key: the same words elsewhere are still a finding. + const seen = new Map() + const unique: Finding[] = [] + // An annotation's appearance can also be detected as a drawn cover. Prefer + // the annotation finding: it explains both the recovery and the removable mark. + const evidenceRank = (f: Finding) => + f.coverKind.endsWith('-annot') ? 3 : f.check === 'ocr-layer-leak' ? 2 : 1 + for (const f of findings) { + if (!f.bbox) { + unique.push(f) + continue + } + const key = JSON.stringify([ + f.page, + f.bbox, + f.severity, + f.severity === 'leak' ? null : f.check, + f.recovered?.text, + f.width, + ]) + const index = seen.get(key) + if (index === undefined) { + seen.set(key, unique.length) + unique.push(f) + } else if (evidenceRank(f) > evidenceRank(unique[index]!)) { + unique[index] = f + } + } + findings = unique const order = new Map() findings.forEach((f, i) => order.set(f, i)) @@ -290,7 +321,7 @@ export function mergeAdjacentLeaks(findings: Finding[]): Finding[] { const box = f.bbox as BBox let best: Group | null = null for (const g of groups) { - if (g.items[0]!.check !== f.check) continue + if (g.items[0]!.check !== f.check || g.items[0]!.page !== f.page) continue if (!continues(g.bbox, box)) continue // Prefer the closest open group (largest bottom edge above this box). if (!best || g.bbox[3] > best.bbox[3]) best = g diff --git a/tests/merge-findings.test.ts b/tests/merge-findings.test.ts index 87e0448..b580ae2 100644 --- a/tests/merge-findings.test.ts +++ b/tests/merge-findings.test.ts @@ -44,6 +44,55 @@ function other(bbox: BBox, severity: Severity = 'warning'): Finding { } describe('mergeAdjacentLeaks', () => { + it('removes repeated detections before joining a passage', () => { + const first = leak([72, 265, 540, 279], 'first line') + const merged = mergeAdjacentLeaks([ + first, + {...first, id: 'duplicate'}, + leak([72, 293, 540, 307], 'second line'), + ]) + expect(merged).toHaveLength(1) + expect(merged[0]!.recovered).toEqual({ + text: 'first line second line', + runCount: 2, + }) + }) + + it('keeps repeated words in different positions or on different pages', () => { + const first = leak([72, 265, 250, 279], 'same words') + const right = leak([320, 265, 500, 279], 'same words') + const nextPage = {...first, id: 'next-page', page: 2} + expect(mergeAdjacentLeaks([first, right, nextPage])).toEqual([ + first, + right, + nextPage, + ]) + }) + + it('keeps annotation evidence when its appearance also exposes the same text', () => { + const drawn = leak([72, 265, 250, 279], 'hidden text') + const annotation: Finding = { + ...drawn, + id: 'annotation', + check: 'removable-annotation', + coverKind: 'square-annot', + } + for (const input of [ + [drawn, annotation], + [annotation, drawn], + ]) { + expect(mergeAdjacentLeaks(input)).toEqual([annotation]) + } + }) + + it('deduplicates warnings without dropping different evidence at the same position', () => { + const warning = other([72, 265, 250, 279]) + const hidden = leak([72, 265, 250, 279], 'hidden text') + expect( + mergeAdjacentLeaks([warning, {...warning, id: 'duplicate'}, hidden]) + ).toEqual([warning, hidden]) + }) + it('merges consecutive double-spaced lines into one passage', () => { // 14pt-tall boxes stacked a full box-height apart (double-spaced), same // left column — the Manafort shape. Expect a single merged block. From 5f118f78e9ec9c3093bd8f328c0ab172fde0996b Mon Sep 17 00:00:00 2001 From: jonwiggins Date: Thu, 19 Nov 2026 19:01:12 -0700 Subject: [PATCH 3/3] fix: use a supported Playwright runner (PRO-7985) --- .github/workflows/ci.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index acce1fd..9127f79 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -24,7 +24,7 @@ jobs: e2e: name: Playwright e2e - runs-on: ubuntu-latest + runs-on: ubuntu-24.04 steps: - uses: actions/checkout@v4 - uses: actions/setup-node@v4