Use the parser to identify / prevent clauses #111
-
|
Hi, Examples:
It looks like I can run down the tree and do some relatively simple filtering, but I am not sure if I am overlooking something. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
In general I would advise using the access rights of your database to manage these sorts of restrictions. That being said, it's a question of doing static analysis on the syntax tree.
This is pretty trivial to achieve.
This is much harder. Especially if you want to avoid false positives. For example: WITH users AS (SELECT * FROM products)
SELECT * FROM users;That query doesn't touch the I can say though that the output of sql-parser-cst is probably too low-level for this. You can't easily tell from the output of this parser whether an identifier refers to a column, table, function or something else. You really want a proper Abstract Syntax Tree to begin your analysis with, not the low-level Concrete Syntax Tree, which this parser produces. I started work on sql-parser-ast, but it's nowhere close to finished. |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for your in-depth reply! |
Beta Was this translation helpful? Give feedback.
In general I would advise using the access rights of your database to manage these sorts of restrictions.
That being said, it's a question of doing static analysis on the syntax tree.
This is pretty trivial to achieve.
This is much harder. Especially if you want to avoid false positives. For example:
That query doesn't touch the
userstable, but when you only look at the FROM clause, it will look like it does. Similarly you need to account for aliases. Also you need to consider schemas, like do you want to restrict access topu…