Repository navigation
Commit 96e59ba
fix(check): reject non-SQL files by extension (#1131)
* fix(check): reject non-SQL files by extension — plug v0.9.6 sanity regression
The Verdaccio sanity suite's path-traversal security test
(test/sanity/phases/security.sh:96-103, present + passing since PR #844
in June 2026) regressed on v0.9.6. Not the test's fault: the altimate-
core 0.7.0 upgrade in #1090 introduced a `multi_statement` safety rule
that echoes the offending statement text back in its error message.
When `altimate check ../../../../etc/passwd` runs, the CLI reads the
file, parses each line as SQL, fails, and the engine emits:
ERROR ... [multi_statement]: Disallowed statement type:
ROOT:X:0:0:ROOT:/ROOT:/BIN/BASH
The sanity test greps case-insensitive for `root:x:0` — matches — fails
the release workflow. No content actually shipped: publish + GitHub
Release + Docker were all skipped when sanity failed.
Fix: honor the "SQL file" claim in check.ts:479's own comment. The
prior filter only checked existence — non-`.sql` files were parsed
happily. Now rejects anything without a `.sql`/`.ddl` extension before
it reaches the engine, so no content is parsed or echoed. Extracted
the extension test as `isSqlFile()` in check-helpers so it can be
unit-tested independently.
Verification:
- rebuilt the darwin-arm64 binary and re-ran the exact sanity
reproduction locally: pre-fix leaked ROOT:X:0 line; post-fix skips
with "Warning: not a SQL file (extension \"none\"), skipping: ..."
- 82/82 tests in test/cli/check-e2e.test.ts pass (9 new isSqlFile
cases + 73 pre-existing)
- typecheck clean; marker guard clean
Follow-ups (not in this PR):
- The engine-side fix — altimate-core's multi_statement rule should
use statement TYPE NAMES, not raw content — file with core team
- Consider capping message length in check.ts finding-mappers as
belt-and-braces against similar future engine-echo bugs
Co-Authored-By: Claude Opus 4.7 <[email protected]>
* fix(check): address bot review — .ddl in default glob, dotfile edge, isFile check, handler test + close #1130
Round 2 on the release/v0.9.6 hotfix — addresses the 5 bot findings on
PR #1131 and rolls in the follow-up filed as issue #1130.
- coderabbit MAJOR + cubic P2 (default-discovery gap): `**/*.sql` glob at
check.ts:462 missed `.ddl` files that the new SQL_EXTENSIONS filter
accepts. Now scans both extensions and dedupes.
- cubic P2 (bare-extension dotfile): `isSqlFile` accepted files named
literally `.sql` and `.ddl` as if the leading dot were an extension
separator. Node's `path.extname` treats those as dotfiles with NO
extension. Fixed to match: bare-`.sql`/`.ddl` filenames are rejected.
- cubic P2 (directory with .sql suffix): a directory named `foo.sql`
passed the extension filter. Added a `statSync(f).isFile()` gate that
rejects directories (and symlinks-to-directories, since statSync
follows symlinks) with a clear warning.
- cubic P2 (test coverage gap): the `isSqlFile` tests only exercised
the pure helper; if the CLI handler stopped calling the filter the
tests would still pass. Added a handler-level integration test with
mixed SQL/non-SQL input that asserts the warning is printed and no
content leaks. Also added handler tests for the directory + bare
dotfile cases. Updated the pre-existing "handles directory with .sql
extension" test to match the new isFile behavior (was expecting
"Error reading" from the downstream readFile crash).
- #1130 follow-up (drop env-var mutation from dispatcher test files):
removed the `beforeAll`/`afterAll` that mutated
`process.env.ALTIMATE_TELEMETRY_DISABLED` in
`test/altimate/dispatcher.test.ts` and
`test/skill/release-v0.9.6-adversarial.test.ts`. Dispatcher.call
already wraps every Telemetry.track in try/catch that swallows errors
— the env-var was defensive against nothing and wasn't parallel-safe.
Closes #1130.
Verification:
- 101/101 tests in check-e2e + dispatcher + release-adversarial pass
- rebuilt darwin-arm64 binary; sanity reproduction still shows no leak
- typecheck clean; marker guard clean
Closes #1130
Co-Authored-By: Claude Opus 4.7 <[email protected]>
* fix(check): reject symlinks whose target isn't SQL + test hygiene
Round 3 on the release/v0.9.6 hotfix — addresses 3 new bot findings on
PR #1131:
- coderabbit MAJOR (real leak surface): the extension filter and
statSync isFile check both see the SYMLINK target, not the link. So
`ln -s /etc/passwd passwd.sql` sailed through — link's .sql extension
passed, statSync followed the link, /etc/passwd IS a regular file,
readFileSync then read its content, and the safety renderer echoed
the first line. Exact leak class this PR exists to close.
Fix: `lstatSync` to detect symlinks; when one is present, `realpathSync`
to resolve the target and require ITS extension to also be SQL.
Preserves `link.sql -> real.sql` (both SQL); rejects `passwd.sql ->
/etc/passwd`. Two new handler-level regression tests:
• "handler rejects symlink whose target is NOT a SQL file"
• "handler ACCEPTS symlink whose target IS a SQL file"
Reproduced the attack locally with the built binary: pre-fix leaked
the file's first line; post-fix skips cleanly.
- coderabbit MAJOR (spy hygiene in check-e2e.test.ts): the spyOn calls
on process.stdout.write / process.stderr.write / console.error in
beforeEach were never restored. Bun doesn't auto-restore spyOn
across test files. Added `mock.restore()` in afterEach.
- coderabbit MAJOR (dispatcher singleton isolation): same class of
finding as the env-var one — the tests mutate module-wide
`nativeHandlers`/`_ensureRegistered`. Not fixable without an
instance-per-test refactor of the whole Dispatcher module. Documented
the concurrency contract in-file: safe under bun's default sequential
test-file execution; #1130 already tracks the broader parallel-safety
cleanup this class of finding calls for. Same disposition as the
release-adversarial file.
Verification:
- 103/103 tests pass (2 new symlink cases)
- rebuilt darwin-arm64 binary; symlink attack repro shows the warning
and no content leak
- typecheck clean; marker guard clean
Co-Authored-By: Claude Opus 4.7 <[email protected]>
* fix(check): reject all symlinks — close TOCTOU race
coderabbit MAJOR on prior round: my "resolve symlink target + check
extension" approach opened a TOCTOU race. Between validation
(realpathSync + isSqlFile) and readFileSync(f), an attacker with write
access to the parent directory can swap ``passwd.sql`` from pointing at
``real.sql`` to pointing at ``/etc/passwd``. The read then follows the
new link and echoes the file's content — the exact leak class this PR
closes.
Closing the race properly requires open-once + fstat + read-from-fd
plumbed through every caller — a big refactor for a CLI most invocations
don't hit. Simpler + secure: refuse symlinks entirely. Users who need to
check a linked file pass the resolved target directly.
Reverses cubic's earlier "accept link-to-SQL" request. The tradeoff
(lose the accept-link-to-SQL convenience) favors simplicity + security
over convenience — noted in the coderabbit thread reply.
Also updates the pre-existing "handles symlinked SQL files" test to
match the new rejection behavior.
103/103 tests pass; typecheck + marker guard clean.
Co-Authored-By: Claude Opus 4.7 <[email protected]>
---------
Co-authored-by: Haider <[email protected]>
Co-authored-by: Claude Opus 4.7 <[email protected]>1 parent 07e3674 commit 96e59ba
5 files changed
Lines changed: 293 additions & 34 deletions
File tree
- packages/opencode
- src/cli/cmd
- test
- altimate
- cli
- skill
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
47 | 47 | | |
48 | 48 | | |
49 | 49 | | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
50 | 70 | | |
51 | 71 | | |
52 | 72 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
5 | | - | |
| 5 | + | |
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
11 | 11 | | |
12 | 12 | | |
| 13 | + | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
| |||
460 | 461 | | |
461 | 462 | | |
462 | 463 | | |
463 | | - | |
464 | | - | |
| 464 | + | |
| 465 | + | |
| 466 | + | |
| 467 | + | |
465 | 468 | | |
466 | 469 | | |
467 | 470 | | |
| |||
476 | 479 | | |
477 | 480 | | |
478 | 481 | | |
479 | | - | |
| 482 | + | |
| 483 | + | |
| 484 | + | |
| 485 | + | |
| 486 | + | |
| 487 | + | |
| 488 | + | |
| 489 | + | |
| 490 | + | |
| 491 | + | |
480 | 492 | | |
481 | 493 | | |
482 | 494 | | |
483 | 495 | | |
484 | 496 | | |
| 497 | + | |
| 498 | + | |
| 499 | + | |
| 500 | + | |
| 501 | + | |
| 502 | + | |
| 503 | + | |
| 504 | + | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
| 509 | + | |
| 510 | + | |
| 511 | + | |
| 512 | + | |
| 513 | + | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
| 540 | + | |
| 541 | + | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
| 545 | + | |
| 546 | + | |
| 547 | + | |
| 548 | + | |
| 549 | + | |
485 | 550 | | |
486 | 551 | | |
487 | 552 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | | - | |
| 1 | + | |
2 | 2 | | |
3 | 3 | | |
4 | | - | |
5 | | - | |
6 | | - | |
7 | | - | |
8 | | - | |
9 | | - | |
10 | | - | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
11 | 21 | | |
12 | 22 | | |
13 | 23 | | |
| |||
0 commit comments