§2.4-2.6 K2 — 4 Bypass L3 + Lỗ hổng khác
§2.4-2.6 K2 — 4 BYPASS L3 + LỖ HỔNG KHÁC + DIRECTUS FLOWS SẠCH
Part of: PG Reform Tools — S176 mission Prev: 02-k0-k1-timeline-channels.md ← | → Next: 04-ks1-ddl-audit-gap.md Khối điều tra: K2 (L3 Bypass Writers)
§2.4 Bypass thực sự ngoài dot/bin/ — 4 BYPASS L3 CHỦ ĐÍCH
L3-1 — CI CAT-ALL UPDATE với session bypass
File: .github/workflows/deploy-vps.yml dòng 328
docker exec postgres psql -U directus -d directus -c "
SELECT set_config('app.allow_meta_update', 'true', true);
UPDATE meta_catalog SET record_count=... WHERE code='CAT-ALL';
UPDATE meta_catalog SET record_count=... WHERE code='CAT-MOL';
UPDATE meta_catalog SET record_count=... WHERE code='CAT-CMP';
UPDATE meta_catalog SET record_count=... WHERE code='CAT-MAT';
UPDATE meta_catalog SET record_count=... WHERE code='CAT-PRD';
UPDATE meta_catalog SET record_count=... WHERE code='CAT-BLD';
"
Bypass có chủ đích qua session variable. PG có guard fn_guard_meta_catalog_update đọc current_setting('app.allow_meta_update') = backdoor. CI tận dụng để update CAT-ALL sau deploy. Tự tài liệu hoá trong web/server/api/registry/refresh-counts.post.ts ("CAT-ALL is updated by deploy step ... with app.allow_meta_update bypass") — known hack, ai cũng biết.
Fix S176: Thay bằng DOT-CAT-ALL-REFRESH (Điều 33 §15.2). Loại bỏ session bypass, dùng fn_refresh_cat_all() SECURITY DEFINER. Guard luôn ON.
L3-2 — CI auto-apply 36 SQL file
File: .github/workflows/deploy-vps.yml dòng 197-222
for sql_file in "$MIGRATION_DIR"/*.sql; do
if [ ! -f "$MARKER_DIR/$base.done" ]; then
docker exec -i postgres psql -U directus -d directus < "$sql_file"
touch "$MARKER_DIR/$base.done"
fi
done
36 file SQL nằm vĩnh viễn trong sql/, marker .done ngăn chạy lại nhưng file không xoá. Bao gồm:
s175_law_dedupe_p1.sql(UPDATE knowledge_documents với hardcoded ID list)s175_source_id_current_unique_p2.sqls161b_*,s162b_*,s164_*s133_measurement_framework.sql,s134_pg_grants.sqlkb_protection_phase2_*.sqlvps_pg_schema_incomex_metadata_kb_20260405.sql— pg_dump snapshot có\restrict <token>, sensitive0048_link_policies_mysql.sql— H2 dead code dùng MySQLUUID()cú pháp, fail trên PG
Bonus KS.2: 6 file SQL CHƯA có marker .sql-applied/ (30/36 đã apply, 6 chưa):
s175_law_dedupe_p1.sql,s175_source_id_current_unique_p2.sql0048_link_policies_mysql.sql— xác nhận K2 hypothesis chưa từng apply thành côngkb_protection_phase2_*.sql(3 file)vps_pg_schema_incomex_metadata_kb_20260405.sql- Marker system bắt đầu 2026-03-24, sau sự kiện 2026-03-10 ~2 tuần → các file SQL trước đó chạy mà không có marker
Fix S176: Thay bằng DOT-MIGRATION-APPLY (Điều 33 §15.1). File SQL phải có header -- DOT-MIGRATION-APPLY-OK. Apply xong UPDATE bảng migration_applied thay marker filesystem. Có DOT cặp dot-migration-verify. File retire phải DELETE hoặc move sql/archive/.
L3-3 — pg-client.js (Điều 31 runner)
File: scripts/integrity/pg-client.js
const { Client } = require('pg');
const connStr = process.env.DATABASE_URL; // postgres://incomex:***@postgres:5432/directus
await client.query(
`INSERT INTO measurement_log (run_id, measurement_id, result, source_value, target_value, delta)
VALUES ($1, $2, $3, $4, $5, $6)`, [...]);
Bypass L3 thuần: Node.js pg lib, connect user incomex qua DATABASE_URL, INSERT thẳng bảng measurement_log trong DB directus. Toàn bộ Điều 31 integrity runner không có entry trong dot_tools. dedupe.js + main.js đi qua Directus API (L1 via Directus) nhưng orchestrator chính KHÔNG đăng ký.
Fix S176: Đăng ký vào dot_tools thành DOT chính thức cho Điều 31 runner. Hợp pháp hoá L1 yếu thành L1 chuẩn. Dùng password GSM thay DATABASE_URL riêng.
L3-4 — dot-script-lint, dot-cron-matrix-setup
Files: dot/bin/dot-script-lint, dot/bin/dot-cron-matrix-setup
- Direct
docker exec postgres psql - KS.3 verify:
dot-script-lintCÓ metadataDOT_SCRIPT_LINTnhưngfile_path=NULL;dot-cron-matrix-setupKHÔNG có metadata nào (installer one-shot không được định nghĩa là DOT) dot-script-lintlinting PG-related script nhưng chính nó là bypass (self-exempt — xem KS.3 WHY-A)
Fix S176: Đăng ký vào dot_tools, gắn paired_dot, dùng password GSM.
§2.5 Lỗ hổng nghiêm trọng khác (K2)
-
Password leak:
agent-data-test/scripts/import_firestore_to_pg.pycó hardcodedIncomex2026PG_306ac539ad365fcerò rỉ git history. PHẢI ĐỔI password ngay khi triển khai phương án A. -
5 cron PG function không có installer DOT: trong
crontab/production.crontabchỉ 1/6 cron có installer (dot-cron-pivot-setupDOT-308). 5 còn lại không rõ ai cài. -
2 crontab trong repo:
crontab/production.crontab(live) vsinfra/cron/incomex-crontab(dead — vẫn còn MySQL backup). -
0048_link_policies_mysql.sqldead code — MySQLUUID()syntax fail trên PG. -
directus-schema.mdKB doc đã lạc hậu từ S139. -
Birth registry trigger không chạy: count = 0.
-
TD-375:
v_registry_countsđang là TABLE writable thay vì VIEW. -
TD-376:
system_issuesthiếu authenticity guard → gốc bệnh 9 writer S175.
§2.6 Directus Flows — SẠCH (K2)
128 flows / 320 operations. 15 exec ops (toàn JS code generation cho assign_code, KHÔNG có raw SQL). 78 item-create + 14 item-update + 1 item-delete đi qua Directus item ops = L1 chuẩn. Flows KHÔNG phải nguồn bypass.
File 03 — §2.4-2.6 K2 | Index | S176 | Living doc