Skip to content

Commit 389ff1a

Browse files
anandgupta42claude
andcommitted
fix: exact single-keyword statement-type allowlist (engine-faithful)
Two review comments pulled opposite directions — cubic wanted compound types like "DELETE FROM" preserved; Codex wanted exact statement types instead of any keyword-vocabulary ordering ("SELECT DELETE UPDATE" leaked verbatim). Live-probing the 0.7.0 engine across DDL/DML/DCL/TCL settles both: the engine emits SINGLE-WORD statement types only ({ALTER, BEGIN, CALL, CREATE, DELETE, DROP, EXPLAIN, GRANT, INSERT, SET, TRUNCATE, UPDATE}). The allowlist is now an exact single-keyword match — the strictest rule that never redacts anything the engine actually produces: multi-word input can only be non-engine content, so keyword-prefixed tails and keyword permutations both redact. Vocabulary-ordering and multi-word tests updated with the probe rationale inline. Co-Authored-By: Claude Fable 5 <[email protected]>
1 parent 5b9b6ae commit 389ff1a

2 files changed

Lines changed: 16 additions & 20 deletions

File tree

‎packages/opencode/src/altimate/native/engine-coerce.ts‎

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,17 @@ const SQL_STATEMENT_KEYWORDS = new Set([
7878
"DESC", "EXECUTE", "EXEC", "REPLACE", "VALUES", "LOCK", "UNLOCK", "COMMENT",
7979
"RENAME", "START", "SAVEPOINT", "RELEASE", "PREPARE", "DEALLOCATE",
8080
])
81-
// Auxiliary words allowed AFTER a statement keyword ("ALTER TABLE",
82-
// "DROP INDEX IF EXISTS"). Every word of a preserved phrase must come from
83-
// the keyword vocabulary — checking only the first word would preserve
84-
// attacker tails like "SET SECRET PASSWORD" verbatim.
85-
const SQL_AUX_KEYWORDS = new Set([
86-
"TABLE", "INDEX", "VIEW", "DATABASE", "SCHEMA", "COLUMN", "TRIGGER",
87-
"FUNCTION", "PROCEDURE", "SEQUENCE", "MATERIALIZED", "TEMPORARY", "TEMP",
88-
"IF", "NOT", "EXISTS", "OR", "INTO", "TRANSACTION", "WORK", "CASCADE",
89-
"UNIQUE", "ROLE", "USER", "EXTENSION", "TYPE",
90-
])
81+
// The engine emits SINGLE-WORD statement types only — probed against the
82+
// live 0.7.0 binary across DDL/DML/DCL/TCL second statements, the full
83+
// observed set is {ALTER, BEGIN, CALL, CREATE, DELETE, DROP, EXPLAIN, GRANT,
84+
// INSERT, SET, TRUNCATE, UPDATE}. Exact single-keyword matching is therefore
85+
// both engine-faithful and the strictest rule: multi-word input can only be
86+
// non-engine content (kills keyword-permutation leaks like
87+
// "SELECT DELETE UPDATE" without redacting anything the engine produces).
9188
function isSqlStatementType(token: string): boolean {
9289
const t = token.trim()
9390
if (!SQL_TOKEN_SHAPE.test(t)) return false
94-
const words = t.split(/\s+/).map((w) => w.toUpperCase())
95-
if (!SQL_STATEMENT_KEYWORDS.has(words[0])) return false
96-
return words.slice(1).every((w) => SQL_STATEMENT_KEYWORDS.has(w) || SQL_AUX_KEYWORDS.has(w))
91+
return SQL_STATEMENT_KEYWORDS.has(t.toUpperCase())
9792
}
9893
export function redactThreatText(text: string): string {
9994
return (

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

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ try {
99
const describeIf = coreAvailable ? describe : describe.skip
1010

1111
describe("redactThreatText", () => {
12-
test("keeps SQL-statement-keyword types", () => {
12+
test("keeps single SQL-statement-keyword types (the only shape the engine emits)", () => {
1313
expect(EngineCoerce.redactThreatText("Disallowed statement type: DROP")).toBe("Disallowed statement type: DROP")
14-
expect(EngineCoerce.redactThreatText("Statement type 'ALTER TABLE' is not in the allowed list")).toBe(
15-
"Statement type 'ALTER TABLE' is not in the allowed list",
14+
expect(EngineCoerce.redactThreatText("Statement type 'ALTER' is not in the allowed list")).toBe(
15+
"Statement type 'ALTER' is not in the allowed list",
1616
)
1717
})
1818

@@ -35,16 +35,17 @@ describe("redactThreatText", () => {
3535
expect(EngineCoerce.redactThreatText("Statement type 'PRIVATE NOTE' is not in the allowed list")).toBe(
3636
"Statement type '<non-SQL content redacted>' is not in the allowed list",
3737
)
38-
// A keyword PREFIX must not preserve an arbitrary tail.
38+
// ANY multi-word phrase redacts — the engine only emits single-word
39+
// statement types (live-probed), so multi-word input is never engine
40+
// vocabulary: keyword-prefixed tails and keyword permutations both die.
3941
expect(EngineCoerce.redactThreatText("Disallowed statement type: SET SECRET PASSWORD")).toBe(
4042
"Disallowed statement type: <non-SQL content redacted>",
4143
)
4244
expect(EngineCoerce.redactThreatText("Disallowed statement type: DROP DEAD FRED")).toBe(
4345
"Disallowed statement type: <non-SQL content redacted>",
4446
)
45-
// Compound statement types made purely of keywords stay useful.
46-
expect(EngineCoerce.redactThreatText("Disallowed statement type: DROP INDEX IF EXISTS")).toBe(
47-
"Disallowed statement type: DROP INDEX IF EXISTS",
47+
expect(EngineCoerce.redactThreatText("Disallowed statement type: SELECT DELETE UPDATE")).toBe(
48+
"Disallowed statement type: <non-SQL content redacted>",
4849
)
4950
})
5051

0 commit comments

Comments
 (0)