mirror of
https://github.com/affaan-m/ECC.git
synced 2026-12-01 12:45:15 +09:00
fix(gateguard): gate DROP DATABASE, DROP SCHEMA and ALTER TABLE ... DROP COLUMN
DESTRUCTIVE_SQL matched only DROP TABLE, DELETE FROM and TRUNCATE. `psql -c "DROP DATABASE prod"`, `DROP SCHEMA public CASCADE` and `ALTER TABLE users DROP COLUMN email` went to the routine gate instead of the destructive gate, even though each loses at least as much data as DROP TABLE. Add DROP DATABASE, DROP SCHEMA and an ALTER TABLE ... DROP COLUMN arm to the phrase check. The DROP COLUMN arm stops at `;` so it never matches across two statements. It requires the COLUMN keyword so ALTER COLUMN ... DROP DEFAULT / DROP NOT NULL stay passive. Existing literal and quote stripping keeps SQL strings, commit messages and echo mentions passive. Update the gateguard trigger list (en, ja-JP, zh-CN) and rebind the skill-triggers registry digest for the SKILL.md body edit. Skill descriptions and triggers are unchanged.
This commit is contained in:
1 parent
d2ef268059
commit
322e347a86
6 files changed
+46
-5
No files matched your search
@@ -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
|
||||
|
||||
@@ -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. 列出此命令将修改或删除的所有文件/数据
|
||||
|
||||
@@ -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": [
|
||||
|
||||
@@ -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;
|
||||
|
||||
// Operator-supplied additional destructive patterns. Lazily compiled from
|
||||
// `GATEGUARD_BASH_EXTRA_DESTRUCTIVE` (regex source) on first use, then
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in new issue
Block a user