Skip to content

catch deeply nested CQL2 text filters#576

Open
cportele wants to merge 1 commit into
masterfrom
nested-cql2
Open

catch deeply nested CQL2 text filters#576
cportele wants to merge 1 commit 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.
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.

1 participant