fix(security): prevent SQL injection via apostrophe in ATTACH DATABASE path (issue #324)#348
Merged
xlabtg merged 5 commits intoxlabtg:mainfrom Apr 23, 2026
Merged
Conversation
Adding .gitkeep for PR creation (default mode). This file will be removed when the task is complete. Issue: xlabtg#324
…e in path
- Escape single quotes in MAIN_DB_PATH before interpolation in the
ATTACH DATABASE statement in migrateFromMainDb() (module-db.ts:109)
- Validate TELETON_ROOT at startup to reject shell metacharacters
(`$\!|;&<>*?{}()[]\") that could be dangerous in subprocess or SQL
contexts (paths.ts)
- Add regression tests: confirm escaped path is syntactically valid SQL,
confirm an unescaped apostrophe does break SQL, confirm the unsafe
character regex catches metacharacters and allows apostrophes/normal paths
Fixes xlabtg#324
ATTACH DATABASE interpolates an unescaped TELETON_ROOT; apostrophe in home dir → SQL injection… path ATTACH DATABASE fails with 'unable to open database' when the parent directory does not exist. Create the o'brien temp directory explicitly so SQLite can actually write the file, proving escaping works end-to-end.
…or' prefix SQLite throws with just the bare message text (e.g. 'near "brien": syntax error'), not the class name. Use .toThrow() without a pattern to match any thrown error from the unescaped apostrophe test case.
Author
🤖 Solution Draft LogThis log file contains the complete execution trace of the AI solution draft process. 💰 Cost: $2.461840📊 Context and tokens usage:
Total: (82.5K + 6.2M cached) input tokens, 18.7K output tokens, $2.461840 cost 🤖 Models used:
📎 Log file uploaded as Gist (2357KB)Now working session is ended, feel free to review and add any feedback on the solution draft. |
Author
✅ Ready to mergeThis pull request is now ready to be merged:
Monitored by hive-mind with --auto-restart-until-mergeable flag |
This reverts commit ad7842a.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #324 — AUDIT-FULL-M4:
ATTACH DATABASEinterpolated an unescapedMAIN_DB_PATH, allowing a single quote inTELETON_ROOT(legal on POSIX, e.g./home/o'brien/) to break out of the SQL string literal and inject arbitrary SQL.Changes
src/utils/module-db.ts— escape before interpolationsrc/workspace/paths.ts— validateTELETON_ROOTat startupAdded a startup check that throws immediately if
TELETON_ROOTcontains shell metacharacters (` $\!|;&<>*?{}()[]"), so every downstream consumer (includingmodule-db.ts) gets a pre-validated value.src/utils/__tests__/module-db.test.ts— regression testsATTACH DATABASEdoes throw a syntax error (proof of the original bug)migrateFromMainDbreturns 0 when main DB is absent (happy path)`,$,;,|and accepts plain paths and paths with apostrophesHow to reproduce the original bug
Acceptance criteria
ATTACH DATABASETELETON_ROOTis validated at startup against shell metacharacters'→ATTACHsucceeds (no injection)'in path → SQL syntax error (demonstrating the original vulnerability)TELETON_ROOTare rejected at startupFixes #324