Split SQL batches correctly around dollar quotes and comments

splitStatements() only knew 'strings' and "identifiers", so a DO block
or function body ($$ ... ; ... $$) was cut at its inner semicolons and
failed, and a quote inside a comment (-- don't) opened a string that
never closed. It now also skips dollar-quoted bodies, E'...' strings
with backslash escapes, and comments. It moves to SqlGuard so it is
tested with the other checks.

OccController::run() now catches Throwable, so an Error thrown by a
command is logged and returned like an Exception instead of ending in
an HTTP 500.

Not changed on purpose: showing rows for statements with RETURNING or
data-modifying CTEs, and failure handling in the Makefile release
targets. Both came up in the same review but are unrelated to the
security fixes in this release.
This commit is contained in:
2026-09-30 03:32:58 +02:00
parent f68b1658be
commit f4b7484e2f
4 changed files with 97 additions and 55 deletions
+1 -1
View File
@@ -91,7 +91,7 @@ class OccController extends Controller
try {
$this->application->run($input, $this->output);
return $this->output->fetch();
} catch (Exception $ex) {
} catch (\Throwable $ex) {
$this->logger->error($ex->getMessage(), ['exception' => $ex]);
return "error: " . $ex->getMessage();
}