Skip to content

Parametrized queries #58

@tdammers

Description

@tdammers

It looks like postgresql-simple does not actually support parametrized queries.

When using ? syntax to inject values into queries, the values are converted to (query) strings (via the ToField class), and the query string is parsed on the client, and ?'s replaced with the encoded values.

From a security perspective, this is kind of bad - all it takes to create a potential opening for an SQLi attack is one incorrect ToField instance, or a particularly quirky query that the query parser isn't prepared to handle, or a bug in the escaping code. And this is a completely unnecessary risk, because postgres natively supports parametrized queries (see for example PQexecParams), keeping the query unchanged, and sending parameters separately; the parametrization happens on the server, and does not involve rewriting SQL source code (the value get injected into the query AST on the server). There is no risk of SQL injection here, because by the time postgres looks at the dynamic values, the SQL query source code has already been discarded.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions