Skip to content

Commit c9cfe17

Browse files
anandgupta42claude
andcommitted
fix(analyst): refuse every PostgreSQL large-object write path in read-only sql_check sources; drop a redundant read-only spread
`lo_from_bytea`, `lo_truncate`/`lo_truncate64`, `lo_open` and `lowrite` join the denied large-object group (the first creates or overwrites a large object from bytea; the others write through a descriptor), and the PostgreSQL-only `readOnly` spread that duplicated the unconditional `readOnly: true` is removed. Tests: the five large-object forms rejected before execution. Co-Authored-By: Claude Fable 5.1 <[email protected]>
1 parent 2f824cf commit c9cfe17

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

‎packages/opencode/src/altimate/tools/sql-check.ts‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export function readSql(sql: string, dialect?: string): string {
187187
body,
188188
) ||
189189
/\bREPLACE\b(?!\s*\()/i.test(body) ||
190-
/\b(nextval|setval|set_config|load_extension|writefile|dblink\w*|lo_import|lo_export|lo_create|lo_unlink|lo_put|pg_write_file|pg_append_file|pg_file_write|pg_file_rename|pg_file_unlink|pg_(?:try_)?advisory_\w*|pg_(?:stat_reset\w*|wal_replay_\w*|logical_\w*|switch_wal|switch_xlog|create_restore_point|(?:start|stop)_backup|backup_(?:start|stop)|\w*replication\w*|terminate_backend|cancel_backend|promote|reload_conf|rotate_logfile|log_backend_memory_contexts))\s*\(/i.test(
190+
/\b(nextval|setval|set_config|load_extension|writefile|dblink\w*|lo_import|lo_export|lo_create|lo_unlink|lo_put|lo_from_bytea|lo_truncate\w*|lo_open|lowrite|pg_write_file|pg_append_file|pg_file_write|pg_file_rename|pg_file_unlink|pg_(?:try_)?advisory_\w*|pg_(?:stat_reset\w*|wal_replay_\w*|logical_\w*|switch_wal|switch_xlog|create_restore_point|(?:start|stop)_backup|backup_(?:start|stop)|\w*replication\w*|terminate_backend|cancel_backend|promote|reload_conf|rotate_logfile|log_backend_memory_contexts))\s*\(/i.test(
191191
functions,
192192
)
193193
) {
@@ -330,7 +330,6 @@ export async function checkSql(input: SqlCheckPublicInput) {
330330
noLimit: true,
331331
readOnly: true,
332332
queryTimeoutMs: args.query_timeout_ms,
333-
...(dialect === "postgres" ? { readOnly: true } : {}),
334333
})
335334
if (response.truncated) throw new Error("sql_check received truncated aggregates; no verdict is available")
336335
return response.rows.map((row) => Object.fromEntries(response.columns.map((col, i) => [col, row[i]])))

‎packages/opencode/test/altimate/sql-check-postgres.test.ts‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,16 @@ describe("predicate_effect with mocked Postgres", () => {
131131
`public."dblink_close" -- close\n('remote', 'c')`,
132132
],
133133
],
134+
[
135+
"large-object-write",
136+
[
137+
"lo_from_bytea(0, '\\x00'::bytea)",
138+
'pg_catalog."lo_from_bytea" /* write */ (0, \'\\x00\'::bytea)',
139+
"LO_TRUNCATE(1, 0)",
140+
"lo_truncate64(1, 0)",
141+
"lowrite(lo_open(1, 131072), '\\x00'::bytea)",
142+
],
143+
],
134144
[
135145
"recovery-control",
136146
[

0 commit comments

Comments
 (0)