Skip to content

fix: escape single quotes in timeline-db WHERE filters + files.ts tests - #256

Open
TerminalGravity wants to merge 3 commits into
mainfrom
fix/escape-where-filter-values
Open

fix: escape single quotes in timeline-db WHERE filters + files.ts tests#256
TerminalGravity wants to merge 3 commits into
mainfrom
fix/escape-where-filter-values

Conversation

@TerminalGravity

Copy link
Copy Markdown
Collaborator

What

  • Bug fix: buildWhereFilter in timeline-db.ts interpolated user-supplied values directly into WHERE clauses without escaping single quotes. Project paths or branch names with apostrophes would break queries. searchExact already escaped them — this brings buildWhereFilter in line.

  • Tests: 9 new unit tests for lib/files.ts covering readIfExists (missing files, text read, maxLines truncation, binary rejection) and findWorkspaceDocs (missing .claude dir, markdown discovery, nested dirs, skip node_modules/preflight-state, metadataOnly).

All 52 tests pass. Clean build.

Shows 4 concrete scenarios: vague prompt clarification, multi-step
scoping, correction pattern matching, and cross-service awareness.
Each example includes the prompt, triage classification, and the
actual output users can expect.
The README and examples/README.md referenced examples/.preflight/
but the actual config files didn't exist. Added:

- config.yml — profile, related projects, thresholds, embeddings
- triage.yml — keyword rules and strictness settings
- contracts/api.yml — manual contract definition examples

All files are heavily commented so users can copy them into their
project root and customize without needing to reference the docs.
buildWhereFilter was interpolating user-supplied values (project, branch,
etc.) directly into WHERE clauses without escaping single quotes. This
would break queries when paths or branch names contain apostrophes.

searchExact already escaped quotes — this brings buildWhereFilter in line.

Also adds 9 unit tests for lib/files.ts (readIfExists + findWorkspaceDocs).

@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.

Nice catch — the single-quote escaping in buildWhereFilter was a real injection vector. The escapeValue helper is clean and the doubling approach ('') is the standard SQL escape.

One thought: if we ever pass user-controlled values into these filters (e.g. from MCP tool args), we might want to consider parameterized queries down the line instead of string escaping. But for now this is solid and the files.test.ts coverage is a good addition. Ready to merge.

@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.

Good catch on the SQL injection surface. Single quotes in branch names happen more than you'd think. Fix is consistent with what searchExact already does. files.ts tests are welcome — the binary rejection edge case is easy to miss.

@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 — good catch on the SQL escape. The escapeValue helper is clean. One thought: might be worth adding a test that exercises the single-quote-in-project-name path specifically in a WHERE filter (the files.test.ts additions look solid but I didn't see that case covered). Otherwise ready to merge.

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