Open
Conversation
The database tools truncate handler interpolated user-supplied table names directly into DELETE FROM statements without validation, allowing SQL injection. Now validates each table name against sqlite_master before executing, rejecting any name not present as an actual table.
Tests validate that table names are checked against sqlite_master before DELETE execution. Covers valid tables, invalid tables, mixed lists, empty input, and various SQL injection payloads.
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
Security hotfix: prevents SQL injection in the database tools truncate handler. Table names from the request body were interpolated directly into
DELETE FROMstatements without validation, allowing arbitrary SQL execution if an admin session is compromised.Changes
1. Table Name Validation via
sqlite_mastersqlite_masterfor the set of real database tables before executing anyDELETE FROM{ success: false, error: 'Table not found' }sqlite_masterinstead of a hardcoded allowlist so tables from plugins and user migrations are included.prepare().bind()doesn't support parameterized table names, so theDELETE FROM ${tableName}interpolation remains — but is now safe because only validatedsqlite_masterentries pass through2. Unit Tests
Technical Details
Core Changes:
packages/core/src/routes/admin-settings.ts—sqlite_masterlookup + Set-based validation beforeDELETE FROMexecution (+14 lines)New Tests:
packages/core/src/routes/admin-settings.test.ts— 6 unit tests with mocked D1 and Hono route testing (+199 lines)Testing
✅ Type Check: PASSED
✅ Unit Tests: PASSED (6 new, all existing passing)
✅ E2E Tests: PASSED (no regression)
New Unit Test Coverage:
users; DROP TABLE content--) rejectedPerformance Impact
sqlite_masterlookup)Breaking Changes
None — the only behavioral change is that invalid table names now return an error instead of attempting (and likely failing) the SQL execution.
Migration Notes
No action required. The fix activates immediately.
Known Issues
None.
Checklist