Conversation
ebd9f0c to
35246b3
Compare
pgnotify/__init__.py
Outdated
| """ | ||
| connection = get_dbapi_connection(connection) | ||
| cursor = connection.cursor() | ||
| cursor.execute("NOTIFY %s, '%s';" % (channel, payload)) |
There was a problem hiding this comment.
This is vulnerable to SQL-injection (correct me if I'm wrong 😉). Is there a way to fix this? If not, it should be explicitly stated in the documentation that untrusted payloads / channels aren't supported.
There was a problem hiding this comment.
As far as I know Psycopg2’s execute method will sanitizes the arguments if passed as a tuple to the method.
For example
conn.execute(“NOTIFY %s, %s”, (channel, payload))
I’m not sure about sqlalchemy though :)
Look forward to this PR be merged! Looks neat and the library can be more complete with this change.
There was a problem hiding this comment.
Also it seems to be better to use the pg_notify function in Postgres for sending notifications to non-constant channel names and payloads?
Refer to the Notes section in the doc: https://www.postgresql.org/docs/9.0/sql-notify.html
|
Thank you kindly for this PR! Definitely a much-needed addition to this library. Some things will need changing before we merge:
|
This patch adds a method for sending a PostgreSQL notify with a payload to a specific channel.
670651d to
bc7c6be
Compare
This patch adds a method for sending a PostgreSQL notify with a payload
to a specific channel.