Skip to content

Identifier quote escaping #768

@alexandermalyga

Description

@alexandermalyga
Contributor

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'''

Activity

williambdean

williambdean commented on Nov 7, 2023

@williambdean
Contributor

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      Participants

      @alexandermalyga@williambdean

      Issue actions

        Identifier quote escaping · Issue #768 · kayak/pypika