Skip to content
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

Mitigate issue #5923 (Prompt injection -> SQL injection in SQLChain) #6051

Closed

Conversation

boazwasserman
Copy link
Contributor

Add validation controls to the SQL chain to mitigate SQL injection issues.
Using sqlfluff to perform static analysis:

  1. Disallow non select statement (INSERT, DROP)
  2. Disallow wildcard select statement

Some dialects that are supported by langchain are not supported by sqlfluff. It is possible to disallow usage of such dialects as well.

Also fixed the SQL integration tests which were not working as expected

Fixes #5923

BTW, looks like there is a huge diff on poetry.lock which doesn't look OK to me, would appreciate any advice on how to resovle it (I was following the instructions found here https://github.com/hwchase17/langchain/blob/master/.github/CONTRIBUTING.md)

Who can review?

@hwchase17

@vercel
Copy link

vercel bot commented Jun 20, 2023

@boazwasserman is attempting to deploy a commit to the LangChain Team on Vercel.

A member of the Team first needs to authorize it.

@vercel
Copy link

vercel bot commented Jun 21, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
langchain ⬜️ Ignored (Inspect) Jun 21, 2023 6:58am

@boazwasserman boazwasserman changed the title Add validations to SQL chain to mitigate SQL injection issues Mitigate issue #5923 (Prompt injection -> SQL injection in SQLChain) Jul 3, 2023
@dosubot dosubot bot added the 🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature label Jul 14, 2023
@harsha89vyas
Copy link

@boazwasserman @hwchase17 any update on this PR? This is required to resolve a flagged mend vulnerability.

@obi1kenobi
Copy link
Collaborator

We ended up resolving this issue in a different way, and langchain versions since 0.0.247 onward are not vulnerable in this way.

Unfortunately, this fact was not picked up by the various vulnerability databases, so we're in the process of following up on that.

The full details of our fix are here but TL;DR:

Thanks for your help and for your patience as we polish up our processes for making our security fixes visible to the security tools used in the community.

@obi1kenobi obi1kenobi closed this Aug 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🤖:bug Related to a bug, vulnerability, unexpected error with an existing feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SQLDatabaseChain has SQL injection issue
3 participants