sqlite: reject connection access from authorizer callbacks · nodejs/node@be849bc · GitHub
Skip to content

Commit be849bc

Browse files
TrevorBurnhamaduh95
authored andcommitted
sqlite: reject connection access from authorizer callbacks
SQLite requires that an authorizer callback not modify the connection that invoked it, and counts sqlite3_prepare_v2() and sqlite3_step() as modifications. node:sqlite let the callback call prepare(), exec(), the statement execution methods, and other connection-mutating APIs on the same DatabaseSync. Track authorizer depth on DatabaseSync with an RAII guard around the callback and throw ERR_INVALID_STATE from the affected entry points while it is on the stack. Covering every authorizer invocation, including the re-prepare that SQLite can run during sqlite3_step(), exposed a second and distinct hazard: reentering a statement that is currently being stepped is a use-after-free rather than a contract violation, since finalizing it frees the virtual machine under sqlite3_step() and re-running it resets that machine mid-execution. Any callback SQLite invokes during execution can reach it, so a user-defined function is enough. Track the statements currently being stepped and reject reentry into only those, which leaves a user-defined function free to prepare, run, and finalize its own helper statements. Signed-off-by: Trevor Burnham <trevorburnham@gmail.com> Fixes: #63207 PR-URL: #65156 Backport-PR-URL: #66128 Reviewed-By: Antoine du Hamel <duhamelantoine1995@gmail.com>
1 parent 41161dd commit be849bc

5 files changed

Lines changed: 711 additions & 3 deletions

File tree

‎doc/api/sqlite.md‎

Lines changed: 30 additions & 0 deletions

0 commit comments

Comments
 (0)