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

Identifier quote escaping #768

Open
alexandermalyga opened this issue Nov 5, 2023 · 1 comment · May be fixed by #771
Open

Identifier quote escaping #768

alexandermalyga opened this issue Nov 5, 2023 · 1 comment · May be fixed by #771

Comments

@alexandermalyga
Copy link

SQL identifier names are not being escaped, thus enabling SQL injection attacks.

Here is a minimal example to reproduce:

import pypika

table = pypika.Table('my_table"--')
field = getattr(table, 'my_field"--')
builder = (
    pypika.Query.from_(table, dialect=pypika.Dialects.POSTGRESQL)
    .select(field)
    .where(table.name == "value'")
)

print(builder)

This code produces the following SQL, where single quotes are correctly being escaped but double quotes are not:

SELECT "my_field"--" FROM "my_table"--" WHERE "name"='value'''
@wd60622
Copy link
Contributor

wd60622 commented Nov 7, 2023

Doesn't seem ideal. Would you like to make a PR and write some tests against this behavior?

@alexandermalyga alexandermalyga linked a pull request Nov 24, 2023 that will close this issue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants