-
Notifications
You must be signed in to change notification settings - Fork 16.1k
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
SQL block potential harmful commands #8583
Closed
Uranium2
wants to merge
12
commits into
langchain-ai:master
from
Uranium2:sql_detect_harmful_actions
Closed
SQL block potential harmful commands #8583
Uranium2
wants to merge
12
commits into
langchain-ai:master
from
Uranium2:sql_detect_harmful_actions
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Raise a `PermissionError` when a provided SQL keyword is provided to `SQLDatabase`.
add detect_harmful_actions
make format
Add test_sql_harmful_keywords
The latest updates on your projects. Learn more about Vercel for Git ↗︎ 2 Ignored Deployments
|
dosubot
bot
added
the
🤖:improvement
Medium size change to existing code to handle new use-cases
label
Aug 1, 2023
user is a table not a database
baskaryan
reviewed
Aug 1, 2023
More representative of the real usage of the feature.
ran make lint and pass my files for the feature, but other files are in error
14 tasks
Fix line too long
@baskaryan Could you, please, review it? |
Apologies for the slow review! Pr has a number of merge conflicts, happy to re-review if you'd like to resolve |
dosubot
bot
added
the
size:S
This PR changes 10-29 lines, ignoring generated files.
label
Feb 18, 2024
dosubot
bot
added
size:M
This PR changes 30-99 lines, ignoring generated files.
and removed
size:S
This PR changes 10-29 lines, ignoring generated files.
labels
Feb 18, 2024
eyurtsev
requested changes
Jun 18, 2024
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same logic as here: #22780 (review)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
🤖:improvement
Medium size change to existing code to handle new use-cases
size:M
This PR changes 30-99 lines, ignoring generated files.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description:
This PR aims to give a bit more control on the commands executed by the
SQLDatabase
. At the moment, if you ask "Drop the table X in database Y" withSQLDatabaseChain
, it will generate code to drop the table that will be run bySQLDatabase
. Today no checks are made on the commands inSQLDatabase
, it's free real estate.Ideally, rights on user must be set to perform or not this kind of action on the database. In real life, lot of people use full rights. To prevent this I added a feature that could, if provided a list of restricted actions, stop the execution of the SQL query.
It will raise a
PermissionError
when restricted keywords are in the command forSQLDatabase
Key Changes:
SQLDatabase
class namedrestricted_keywords
PermissionError
if keywords are found in the sql commandmake format
,make lint
andmake test
were tested locallyI think this could help for CVE-2023-36189 Where the developer could block any keywords that could be generated by
SQLDatabaseChain
. It can block any string, so he could also block the usage of wildcards, name of tables, databases. I think it can be powerfull, it gives control to the developer and protect the user doing unwanted actions or protect his database.@baskaryan