Skip to content

fix: sanitize SQL string interpolation in timeline-db WHERE clauses - #139

Open
TerminalGravity wants to merge 3 commits into
mainfrom
fix/sanitize-where-clauses
Open

fix: sanitize SQL string interpolation in timeline-db WHERE clauses#139
TerminalGravity wants to merge 3 commits into
mainfrom
fix/sanitize-where-clauses

Conversation

@TerminalGravity

Copy link
Copy Markdown
Collaborator

Problem

buildWhereFilter and searchExact in timeline-db.ts interpolated user-supplied strings directly into SQL WHERE clauses without escaping. A crafted project name, branch, or search query containing single quotes could break queries or inject arbitrary SQL.

Fix

  • Added escapeSqlString() — doubles single quotes, strips null bytes
  • Added isValidEventType() — validates type field against the EVENT_TYPES enum instead of trusting the input
  • Applied escaping to all string interpolation sites in buildWhereFilter and searchExact
  • 6 unit tests for the escaping function

Tests

All 49 tests pass.

buildWhereFilter and searchExact were interpolating user-supplied strings
directly into SQL WHERE clauses without escaping, allowing potential
injection via project, branch, since/until, and search query fields.

- Add escapeSqlString() to double single quotes and strip null bytes
- Validate event type against known EVENT_TYPES enum
- Replace raw interpolation in searchExact with escapeSqlString
- Add 6 unit tests for escapeSqlString

@TerminalGravity TerminalGravity left a comment

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed — this is solid. The escapeSqlString helper with null byte stripping + quote doubling handles the key injection vectors. Type validation via enum whitelist is the right call. Tests cover the edge cases well. If LanceDB ever supports parameterized queries we should migrate, but this is good to merge now. 🚢

@TerminalGravity

Copy link
Copy Markdown
Collaborator Author

Reviewed — SQL injection fix is solid. Escaping with doubled single-quotes plus enum validation for event types covers the attack surface. Tests are thorough. Merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant