Skip to content

catch deeply nested CQL2 text filters#576

Merged
azahnen merged 2 commits into
masterfrom
nested-cql2
Jul 20, 2026
Merged

catch deeply nested CQL2 text filters#576
azahnen merged 2 commits into
masterfrom
nested-cql2

Conversation

@cportele

Copy link
Copy Markdown
Contributor

The cql2-text parser (ANTLR) and the subsequent tree visit both recurse with the nesting depth of the expression, and parse() only caught ParseCancellationException. A filter with a few thousand nested parentheses in the (uncapped) filter query parameter therefore overflowed the stack and crashed the request thread. The cql2-json path is already bounded by Jackson's nesting limit.

Add a complexity guard before parsing: reject filters over a maximum length and those nesting parentheses beyond a maximum depth (measured outside string literals, so parentheses in a literal value do not count). Also catch StackOverflowError at the parse boundary as a safety net and surface it as a CqlParseException instead of a crash.

Adds CqlTextParserComplexitySpec.

The cql2-text parser (ANTLR) and the subsequent tree visit both recurse with
the nesting depth of the expression, and parse() only caught
ParseCancellationException. A filter with a few thousand nested parentheses in
the (uncapped) `filter` query parameter therefore overflowed the stack and
crashed the request thread. The cql2-json path is already bounded by Jackson's
nesting limit.

Add a complexity guard before parsing: reject filters over a maximum length and
those nesting parentheses beyond a maximum depth (measured outside string
literals, so parentheses in a literal value do not count). Also catch
StackOverflowError at the parse boundary as a safety net and surface it as a
CqlParseException instead of a crash.

Adds CqlTextParserComplexitySpec.
@azahnen
azahnen enabled auto-merge (squash) July 20, 2026 17:04
@azahnen
azahnen merged commit ec87a83 into master Jul 20, 2026
3 checks passed
@azahnen
azahnen deleted the nested-cql2 branch July 20, 2026 17:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants