Skip to content

guard: jsqlparser 5.4.15, jsqltranspiler 1.13, single parse, second read-only net - #63

Merged
stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:fix/guard-jsqlparser-5.4
Sep 22, 2026
Merged

stbischof merged 1 commit into
eclipse-daanse:mainfrom
stbischof:fix/guard-jsqlparser-5.4

Conversation

@stbischof

Copy link
Copy Markdown
Contributor

Why

The guard ran on jsqlparser 5.3.167 and jsqltranspiler 1.8. Both are behind their current releases, and the newer parser brings syntax the guard has to know about.

What

  • Dependencies: jsqlparser 5.3.167 → 5.4.15 (the release jsqltranspiler 1.13 is built against), jsqltranspiler 1.8 → 1.13. With 1.13 correlated sub queries resolve against the enclosing query (previously rejected as TableNotDeclared), ORDER BY columns are recorded, UNION is handled by the column resolver and the OSGi imports for duckdb/h2/json are optional.
  • ReadOnlyStatementValidator: also rejects the MySQL SELECT .. INTO OUTFILE/DUMPFILE/@var clause, which jsqlparser 5.4 now parses, and every ForMode (FOR NO KEY UPDATE, FOR KEY SHARE, SKIP LOCKED, ...).
  • Script input: the guard parses with parseStatements and rejects more than one statement. CCJSqlParserUtil.parse() silently drops a trailing ; DROP TABLE .. (CCJSqlParserUtil.parse() silently ignores everything after the first statement's semicolon JSQLParser/JSqlParser#2681). A comment-only input is reported as empty.
  • Second net: after the own validator, jsqlparser's Statement.getFeatures(pureFunctions) must not report MODIFIES_DATA, MODIFIES_SCHEMA, MODIFIES_SESSION, MODIFIES_TRANSACTION or OPAQUE, and must report a result set. The function whitelist is the purity predicate. Note: upstream classifies INTO OUTFILE/DUMPFILE as a plain read, so the own check stays primary.
  • One parse per statement: the validated AST is handed to DeparserColumResolver.getResolvedStatementText(Statement). JSQLResolver expands * with the FROM item's full qualification while JSQLColumResolver uses the bare name, so the deparser normalises column qualifiers to table name or alias; the FROM item carries the schema. The matching upstream entry points are proposed in feat: Statement entry points for parse and resolved text starlake-ai/jsqltranspiler#153.

Tests

SqlGuardTest: INTO OUTFILE/DUMPFILE/@var/TEMP, row lock variants, trailing statements, comment-only input, correlated sub queries, window function, qualified column references. 300 tests, full build green.

…ead-only net

Upgrade the parser and the transpiler to their current releases and
close the gaps that come with them.

- jsqlparser 5.3.167 -> 5.4.15 (the release jsqltranspiler 1.13 is built
  against), jsqltranspiler 1.8 -> 1.13: correlated sub queries resolve
  against the enclosing query, ORDER BY columns are recorded, UNION is
  handled by the column resolver, OSGi imports for duckdb/h2/json are
  optional.
- ReadOnlyStatementValidator also rejects the MySQL SELECT .. INTO
  OUTFILE/DUMPFILE/@var clause, which jsqlparser 5.4 now parses, and every
  ForMode incl. FOR NO KEY UPDATE / FOR KEY SHARE / SKIP LOCKED.
- TranspilerSqlGuard parses the input as a script and rejects more than
  one statement: CCJSqlParserUtil.parse() silently drops a trailing
  "; DROP TABLE .." (JSQLParser#2681). A comment-only input is empty.
- Second net after the own validator: jsqlparser's
  Statement.getFeatures(pureFunctions) must not report MODIFIES_DATA,
  MODIFIES_SCHEMA, MODIFIES_SESSION, MODIFIES_TRANSACTION or OPAQUE, and
  must report a result set. The function whitelist is the purity
  predicate.
- One parse per statement: the validated AST is handed to
  DeparserColumResolver.getResolvedStatementText(Statement). JSQLResolver
  expands "*" with the FROM item's full qualification while
  JSQLColumResolver uses the bare name, so the deparser now normalises
  column qualifiers to table name or alias; the FROM item carries the
  schema.
- Tests: INTO OUTFILE/DUMPFILE/@var/TEMP, row lock variants, trailing
  statements, comment-only input, correlated sub queries, window
  function, qualified column references (300 tests).

Signed-off-by: Stefan Bischof <stbischof@bipolis.org>
@stbischof
stbischof merged commit 1d88586 into eclipse-daanse:main Sep 22, 2026
26 of 28 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