-
Notifications
You must be signed in to change notification settings - Fork 383
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Improvement] Potential SQL injection point in generateDropDatabaseSql #2179
Comments
Hello @justinmclean, I would like to work on this issue, but may I request more hints on how to go about fixing this issue? Thank you! |
These links may help: In this case, I would check if the name is in an expected format with a regular expression or similar. |
Has the issue been resolved after merging #3053? |
I saw #3053 which originally seems to fix this issue is causing bug report for listing MySQL schema '//' in #3101. So currently we do not Should we still verify the naming before dropping using the capability framework? |
Although
Is there any other way to prevent potential SQL injection in If not, I think we can verify the naming before dropping using the capability framework firstly to resolve this issue. If there are other users who need to use special characters in real scenarios, we will gradually relax restrictions or make the name spec capability configurable for users. WDYT? |
Prepared statement seems to be designed to handle data values, not for SQL identifiers like table names or database names. |
This regular expression already contains the special characters that are known to be used by the user |
Got it, thanks! I think we can add separate regex name pattern for the 4 JDBC catalog and validate naming when creating and dropping table/database for now. What do you think? :) |
…g schemas and tables (apache#2335) ### What changes were proposed in this pull request? Improve security when creating and dropping schemas and tables. This PR adds the following checks for identifier names using the capability framework - Regex check - As a best practice, it's generally advised to avoid including spaces in database names. In this PR, database names that include space will be considered illegal. - String length check, since SQL injection usually requires using longer string - Mysql: at most 64 characters - Postgresql: at most 63 characters We refer to specifications of the earliest version of DB that gravitino currently supports: - Postgresql identifier rules: https://www.postgresql.org/docs/12/sql-syntax-lexical.html#SQL-SYNTAX-IDENTIFIERS - Mysql identifier naming: https://dev.mysql.com/doc/refman/5.7/en/identifiers.html - Mysql identifier length limit: https://dev.mysql.com/doc/refman/5.7/en/identifier-length.html ### Why are the changes needed? Fix: apache#2179 ### Does this PR introduce _any_ user-facing change? Add name identifier checks before attempting to create or drop schemas and tables. ### How was this patch tested? Add IT tests.
What would you like to be improved?
The database name is passed into generateDropDatabaseSql and is passed on to executeQuery without checking or validating it's contents.
How should we improve?
Verify the database name before calling executeQuery.
The text was updated successfully, but these errors were encountered: