Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/ja-JP/skills/gateguard/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ code クラスでは変更内容も読み、公開宣言に触れない Edit に

### Destructive Bash Gate (every destructive command)

Triggers on: `rm -rf`, `git reset --hard`, `git push --force`, `drop table`, etc.
Triggers on: `rm -rf`, `git reset --hard`, `git push --force`, `drop table`, `drop database`, `drop schema`, `alter table ... drop column`, etc.

```
1. List all files/data this command will modify or delete
Expand Down
2 changes: 1 addition & 1 deletion docs/zh-CN/skills/gateguard/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ LLM 的自我评估不起作用。问"你是否违反了任何策略?"答案

### 破坏性 Bash 门控(每个破坏性命令)

触发条件:`rm -rf`、`git reset --hard`、`git push --force`、`drop table` 等。
触发条件:`rm -rf`、`git reset --hard`、`git push --force`、`drop table`、`drop database`、`drop schema`、`alter table ... drop column` 等。

```
1. 列出此命令将修改或删除的所有文件/数据
Expand Down
2 changes: 1 addition & 1 deletion manifests/context-packs/skill-triggers@1.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"id": "hand-seeded",
"source": "manual-curation-pending-regeneration"
},
"registryDigest": "6f213dc845937b4093bc018d041b25b538d88d78451b9d799ad614989b360ee4",
"registryDigest": "bb9891dd197ceda96e6b4da38279e654a8e70e80f2c2c49891800f8ac2e2d451",
"schemaVersion": 1,
"triggers": {
"skill:agent-runtime-gateway-smoke-test": [
Expand Down
8 changes: 7 additions & 1 deletion scripts/hooks/gateguard-fact-force.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,13 @@ const ECC_ENABLE_VALUES = new Set(['1', 'true', 'on', 'enabled', 'enable', 'yes'
// `echo dd if=x` — which runs no dd at all — was gated. The boundary decided
// the verdict instead of the command position, so dd moved to isDestructiveDd()
// alongside the other token-based detectors (#2642).
const DESTRUCTIVE_SQL = /\b(drop\s+table|delete\s+from|truncate)\b/i;
// DROP DATABASE / DROP SCHEMA remove at least as much data as DROP TABLE, and
// ALTER TABLE ... DROP COLUMN discards a column's data across every row. The
// DROP COLUMN arm is bounded by `;` so it cannot join two separate statements,
// and it requires the explicit COLUMN keyword so `ALTER COLUMN ... DROP
// DEFAULT` / `DROP NOT NULL` (metadata-only changes) stay passive.
const DESTRUCTIVE_SQL =
/\b(drop\s+(?:table|database|schema)|delete\s+from|truncate|alter\s+table\b[^;]*?\bdrop\s+column)\b/i;
Comment on lines +131 to +132

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P1 SQL comments bypass the gate

psql -c "DROP /* cleanup */ DATABASE prod" and psql -c "ALTER TABLE users DROP /* cleanup */ COLUMN email" are valid SQL, but the new expressions require whitespace between those keywords. stripSqlLiterals leaves comments intact, so neither command matches. Once the routine gate is satisfied or disabled, these commands run without the destructive gate’s data-impact and rollback questions.

Replace SQL comments with whitespace before checking the keywords, while preserving quoted data, and add regression tests for these forms.

Prompt To Fix With AI
This is a comment left during a code review.
Path: scripts/hooks/gateguard-fact-force.js
Line: 131-132

Comment:
**SQL comments bypass the gate**

`psql -c "DROP /* cleanup */ DATABASE prod"` and `psql -c "ALTER TABLE users DROP /* cleanup */ COLUMN email"` are valid SQL, but the new expressions require whitespace between those keywords. `stripSqlLiterals` leaves comments intact, so neither command matches. Once the routine gate is satisfied or disabled, these commands run without the destructive gate’s data-impact and rollback questions.

Replace SQL comments with whitespace before checking the keywords, while preserving quoted data, and add regression tests for these forms.

---

For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.


// Operator-supplied additional destructive patterns. Lazily compiled from
// `GATEGUARD_BASH_EXTRA_DESTRUCTIVE` (regex source) on first use, then
Expand Down
2 changes: 1 addition & 1 deletion skills/gateguard/SKILL.md
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ may collapse, and that a sibling must share the first file's class.

### Destructive Bash Gate (every destructive command)

Triggers on: `rm -rf`, `git reset --hard`, `git push --force`, `drop table`, etc.
Triggers on: `rm -rf`, `git reset --hard`, `git push --force`, `drop table`, `drop database`, `drop schema`, `alter table ... drop column`, etc.

```
1. List all files/data this command will modify or delete
Expand Down
35 changes: 35 additions & 0 deletions tests/hooks/gateguard-fact-force.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2248,6 +2248,41 @@ function runTests() {
passed++;
else failed++;

if (
test('denies DROP DATABASE, DROP SCHEMA and ALTER TABLE ... DROP COLUMN passed to SQL clients', () => {
// Each of these destroys at least as much data as DROP TABLE.
expectDestructiveDeny('psql -c "DROP DATABASE prod"', 'psql drop database');
expectDestructiveDeny('psql -c "drop database if exists app_dev"', 'psql drop database if exists');
expectDestructiveDeny('mysql -e "DROP DATABASE app"', 'mysql drop database');
expectDestructiveDeny('psql -c "DROP SCHEMA public CASCADE"', 'psql drop schema cascade');
expectDestructiveDeny('mysql -e "DROP SCHEMA app"', 'mysql drop schema');
expectDestructiveDeny('psql -c "ALTER TABLE users DROP COLUMN email"', 'psql alter table drop column');
expectDestructiveDeny(
'psql -c "ALTER TABLE IF EXISTS ONLY public.users DROP COLUMN IF EXISTS email CASCADE"',
'psql alter table if exists only drop column'
);
expectDestructiveDeny('sqlite3 app.db "ALTER TABLE users DROP COLUMN email"', 'sqlite3 drop column');
expectDestructiveDeny('sudo -u postgres psql -c "drop database prod"', 'sudo psql drop database');
expectDestructiveDeny('psql -c "drop database prod"; echo done', 'drop database before a separator');
})
)
passed++;
else failed++;

if (
test('allows non-destructive ALTER TABLE forms and quoted DROP DATABASE mentions', () => {
expectAllow('psql -c "ALTER TABLE users ALTER COLUMN email DROP DEFAULT"', 'alter column drop default');
expectAllow('psql -c "ALTER TABLE users ALTER COLUMN email DROP NOT NULL"', 'alter column drop not null');
expectAllow('psql -c "ALTER TABLE users ADD COLUMN note text"', 'alter table add column');
expectAllow('psql -c "ALTER TABLE users ADD COLUMN note text; SELECT \'drop column\'"', 'drop column in a literal');
expectAllow('psql -c "SELECT \'drop database\' AS label"', 'drop database in a literal');
expectAllow('git commit -m "docs: explain drop database recovery"', 'drop database in -m');
expectAllow('echo "drop schema public cascade"', 'echo drop schema mention');
})
)
passed++;
else failed++;

if (
test('denies quoted destructive SQL through sudo/env wrappers', () => {
expectDestructiveDeny('sudo -u postgres psql -c "drop table users"', 'sudo -u psql');
Expand Down
Loading