Skip to content

[codex] Escape Windows Rewind search wildcards#8574

Merged
kodjima33 merged 3 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-rewind-search-query
Jul 3, 2026
Merged

[codex] Escape Windows Rewind search wildcards#8574
kodjima33 merged 3 commits into
BasedHardware:mainfrom
tianmind-studio:codex/windows-rewind-search-query

Conversation

@tianmind-studio

@tianmind-studio tianmind-studio commented Jun 29, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Escape SQLite LIKE wildcard characters in Windows Rewind search terms so %, _, and backslashes are treated as literal user input.
  • Split whitespace-separated Rewind queries into capped tokens and require every token to match OCR text, window title, or app name.
  • Trim before applying the pre-tokenization character cap so leading/trailing whitespace cannot consume the scan budget or erase valid search terms.
  • Add focused unit coverage for tokenization, input-size capping, leading-whitespace capping, LIKE escaping, empty queries, and generated SQL params.

Review follow-up

  • Addressed cubic feedback that the character cap must run after .trim() but before .split().

Refresh

  • Rebased on main at b781d91767ac96a20f2305614eb50c7744a8a6c3.
  • Current head: dcb92038f0ece15575743f75f42e1e7c493e3fdc.
  • GitHub currently reports this PR as mergeable.

Tests

  • npm run test -- src/main/rewind/rewindSearchQuery.test.ts src/main/rewind/rewindGrouping.test.ts -> 2 files, 10 tests passed
  • npm run typecheck -> passed
  • targeted npx eslint --quiet on changed Windows files -> no errors
  • git diff --check origin/main...HEAD -> passed
  • git diff --check -> passed
  • scripts/pre-commit with PYTHONUTF8=1 -> passed
  • scripts/pre-push with PYTHONUTF8=1 -> passed

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 3 files

Confidence score: 4/5

  • In desktop/windows/src/main/rewind/rewindSearchQuery.ts, the token cap is applied after tokenization, so very large queries can still trigger expensive tokenization work and cause avoidable latency or CPU spikes when searching; add a pre-tokenization input-size guard (or early truncation) before merging to de-risk performance impact.

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread desktop/windows/src/main/rewind/rewindSearchQuery.ts Outdated

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread desktop/windows/src/main/rewind/rewindSearchQuery.ts Outdated

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Nice work — this is a solid, focused security hardening of the Windows Rewind search path.

Verified:

  • All user input reaches SQLite exclusively via parameterized placeholders (?); the WHERE clause string is built only from the hardcoded SEARCH_FIELDS list, so SQL injection is not possible.
  • LIKE wildcard escaping (%, _, \) with an explicit ESCAPE '\' clause is correct — literal % and _ in user terms no longer act as wildcards.
  • Token and character limits (REWIND_SEARCH_TOKEN_LIMIT, REWIND_SEARCH_QUERY_CHAR_LIMIT) cap both the token count and scanned input size, preventing unbounded clause/parameter growth from large queries.
  • Placeholder and param array lengths stay in sync (3 fields × N tokens on both sides).
  • Good unit coverage: tokenization/whitespace normalization, input-size capping, LIKE escaping, multi-token SQL shape, literal wildcard handling, and empty-query null return.

The multi-token AND semantics (every token must match at least one field) is a sensible search-quality improvement on top of the escaping fix.

Thanks for the contribution!

@tianmind-studio tianmind-studio force-pushed the codex/windows-rewind-search-query branch from 8d568e6 to f81bc4e Compare July 3, 2026 04:57

@Git-on-my-level Git-on-my-level left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Re-reviewed the latest head. The follow-up keeps the Rewind SQL generation constrained to hardcoded columns, binds all user terms as parameters, correctly escapes LIKE wildcards with an explicit ESCAPE clause, and caps both scanned input length and token count.\n\nI also ran the focused Vitest file and node TypeScript check locally; both passed. ESLint reports only existing/prettier line-ending warnings in db.ts, no errors. This looks safe to merge from code review.

@tianmind-studio tianmind-studio force-pushed the codex/windows-rewind-search-query branch from f81bc4e to dcb9203 Compare July 3, 2026 10:26

@kodjima33 kodjima33 left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Desktop bug fix (owner-override): escape SQLite LIKE wildcards in Windows Rewind search; token matching.

@kodjima33 kodjima33 merged commit f6410ee into BasedHardware:main Jul 3, 2026
1 check passed
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.

3 participants