Skip to content

Commit c9a1597

Browse files
anandgupta42claude
andcommitted
fix: diff-scope safety on raw scans, redact after subtraction
Cursor review catch: redacting the head scan BEFORE the base subtraction rewrote `multi_statement` matched_patterns to "<redacted>", so base keys (raw) never matched and pre-existing threats resurfaced as newly introduced. Redaction now runs after diff-scoping — subtraction compares raw engine patterns on both sides. Regression test: identical base/head passwd-like input yields zero threats and safe:true. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent f34af2b commit c9a1597

2 files changed

Lines changed: 16 additions & 1 deletion

File tree

‎packages/opencode/src/altimate/native/altimate-core.ts‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ export function registerAll(): void {
207207
// occurrence, so a PR that ADDS a second identical injection still
208208
// reports it. Recompute safe/risk_score from the surviving threats so a
209209
// fully pre-existing threat set doesn't leave a stale unsafe verdict.
210-
let safety: Record<string, unknown> = redactScan(toData(core.scanSql(params.sql)))
210+
let safety: Record<string, unknown> = toData(core.scanSql(params.sql))
211211
if (params.base_sql) {
212212
try {
213213
const baseCounts = new Map<string, number>()
@@ -243,6 +243,10 @@ export function registerAll(): void {
243243
// Unscannable base — keep the full head scan (fail open to MORE findings).
244244
}
245245
}
246+
// Redact AFTER diff-scoping: subtraction must compare raw engine
247+
// matched_patterns on both sides (redacting first would rewrite head
248+
// multi_statement keys to "<redacted>" and never match the base).
249+
safety = redactScan(safety)
246250
// PII exposure for the composite check — the tool has always rendered a
247251
// PII section; previously nothing populated it. Additive: a PII failure
248252
// must not fail the whole composite.

‎packages/opencode/test/altimate/threat-redaction.test.ts‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,17 @@ describeIf("safety handlers redact raw-input echoes (real engine)", () => {
5858
expect(threats.toLowerCase()).not.toContain("root:x:0")
5959
})
6060

61+
test("diff-scoping still filters pre-existing multi_statement threats despite redaction", async () => {
62+
// Regression (cursor review on #1111): redacting BEFORE base subtraction
63+
// rewrote head matched_patterns to "<redacted>" so base keys never matched
64+
// and pre-existing threats resurfaced as introduced. Redaction now runs
65+
// after subtraction: identical base/head must yield zero threats.
66+
const { Dispatcher } = await import("../../src/altimate/native")
67+
const r = await Dispatcher.call("altimate_core.check", { sql: PASSWD, base_sql: PASSWD })
68+
expect((((r.data as any).safety?.threats ?? []) as any[]).length).toBe(0)
69+
expect((r.data as any).safety.safe).toBe(true)
70+
})
71+
6172
test("real SQL statement types are preserved in messages", async () => {
6273
const { Dispatcher } = await import("../../src/altimate/native")
6374
const r = await Dispatcher.call("altimate_core.safety", { sql: "SELECT 1; DROP TABLE users;" })

0 commit comments

Comments
 (0)