Skip to content

bug(sql): injectSqlLimit must not rewrite LIMIT inside string literals #464

Description

@ZhuchkaTriplesix

Parent

Part of #463

Severity

High

Problem

injectSqlLimit / clamp path uses regex _limitCount.firstMatch + replaceFirst on raw SQL. A LIMIT n sequence inside a string literal (e.g. WHERE note = 'Use LIMIT 999999 rows') is treated as a real clause and rewritten. Query still parses but filters return wrong rows with no error.

Evidence

  • lib/core/database/sql_limit.dart (~55–65)
  • Bugbot review dev vs main (2026-07-27)

Acceptance

  • LIMIT inside single-quoted (and preferably dollar-quoted) literals is not clamped/replaced
  • Real top-level / trailing LIMIT / FETCH still clamped
  • Unit tests covering string-literal false positive + real LIMIT clamp

Suggested fix

SQL-aware scan (skip quoted spans) before applying limit regex; or only rewrite the last statement’s trailing LIMIT outside quotes.

Metadata

Metadata

Labels

bugSomething isn't workingcoreCore library logic and services

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions