Skip to content

fix: sanitize SQL filter inputs in timeline-db to prevent injection - #234

Open
TerminalGravity wants to merge 1 commit into
mainfrom
fix/sanitize-query-filters
Open

fix: sanitize SQL filter inputs in timeline-db to prevent injection#234
TerminalGravity wants to merge 1 commit into
mainfrom
fix/sanitize-query-filters

Conversation

@TerminalGravity

Copy link
Copy Markdown
Collaborator

What

buildWhereFilter and searchExact in timeline-db.ts interpolated user-supplied values (project paths, branch names, timestamps, event types) directly into SQL WHERE clauses without proper sanitization.

Fix

  • escapeSQL() — escapes single quotes in string literals (project, branch)
  • isValidEventType() — whitelist validation against EVENT_TYPES
  • isValidTimestamp() — regex validation for ISO-8601 format
  • Throws on invalid type/timestamp instead of silently injecting

Tests

17 new tests covering all sanitization paths — escaping, validation, filter composition, and rejection of malicious inputs.

All 60 tests pass ✅

- Add escapeSQL() for string literal sanitization in buildWhereFilter
- Validate event types against EVENT_TYPES whitelist
- Validate timestamps with ISO-8601 regex before interpolation
- Export helpers for testability
- Add 17 tests covering all filter sanitization paths

Previously, buildWhereFilter interpolated user-supplied project, branch,
type, and timestamp values directly into SQL WHERE clauses without
escaping. A crafted project path or branch name containing single quotes
could break out of the string literal.
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