Skip to content

Security: ORDER/GROUP BY identifiers, parametrized paging plans, empty IN, request-end rollback - #5

Merged
DavidWilliamBalbino merged 1 commit into
mainfrom
security/hardening-2
Nov 23, 2026
Merged

DavidWilliamBalbino merged 1 commit into
mainfrom
security/hardening-2

Conversation

@DavidWilliamBalbino

Copy link
Copy Markdown
Contributor

Remaining Arcano findings from the 2026-11-20 security audit (M10, B8, B9).

Changes

  • M10: orderBy() and groupBy() accept a plain string only when it is a column, table.column, @.column, a role alias (user:credentials.id) or a JSON path (data->key[0]). Anything else (functions, spaces, quotes, comments) throws BuilderException; raw SQL goes through Fragment/Expression. orderBy($_GET['sort']) can no longer inject SQL. Column names passed to where()/columns() stay trusted input, documented in the README.
  • B8:
    • limit > 1 and offset > 0 are parameters of the cached shape plan instead of part of its key, so every page of a listing shares one plan (no more 1024-plan cap reached by pagination).
    • Negative limit/offset are refused (SelectQuery and ORM Select).
    • An empty IN list compiles to 1=0, an empty NOT IN to 1=1 (was a syntax error / 500).
    • fetchPage() reads the count column by position, so SQL Server paging without ORDER BY (which appends a ROW_NUMBER column) returns the right total.
  • B9: DatabaseManager::rollbackOpenTransactions() rolls back every transaction level left open on the drivers in use; long-lived workers call it with $orm->getHeap()->clean() at the end of each request (the Nimbus integration calls it).

Behaviour change

orderBy('RAND()') (string) now throws; use orderBy(new Fragment('RAND()'), null), as the docblocks already showed.

Tests

  • tests/Database/Unit/Query/UntrustedInputTest.php (injection strings for orderBy/array keys/groupBy, accepted forms, negative limit/offset)
  • QueryShapeTest (all drivers): pages share plans, page total without ORDER BY, negative limit/offset, empty IN/NOT IN, injected sort key
  • SelectQueryTest::testEmptyInListCompilesToFalseAndEmptyNotInToTrue, TransactionsTest::testOpenTransactionsAreRolledBackAtTheEndOfARequest

Locally: unit 911/911; sqlite 2591 with 1 error that also happens on main (SingleFileStrategyTest::testInit, order-dependent, passes alone).

…plans, empty IN, open transaction rollback

- orderBy()/groupBy() refuse strings that are not a column, table.column, @.column or JSON path;
  expressions must be a Fragment/Expression (audit M10).
- limit/offset above 1/0 are statement parameters of the cached shape plan, so every page shares
  one plan; negative limit/offset are refused (B8).
- An empty IN list compiles to 1=0 and an empty NOT IN to 1=1 instead of a syntax error (B8).
- fetchPage reads the count column by position, not as the last column, so SQL Server paging
  without ORDER BY (ROW_NUMBER column) returns the right total (B8).
- DatabaseManager::rollbackOpenTransactions() for long-lived workers to call at the end of each
  request, next to Heap::clean() (B9).
@DavidWilliamBalbino
DavidWilliamBalbino merged commit 02adc15 into main Nov 23, 2026
9 checks 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.

1 participant