You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The module level connect method is guarded by PySys_Audit(), but sqlite3.Connection.__init__() is not. It is possible to bypass the module level connect() method simply by creating a new sqlite3.Connection object directly.
Easily fixed by either moving the PySys_Audit() check to pysqlite_connection_init(), or by adding an extra check in pysqlite_connection_init().
>>> import sqlite3, sys
>>> defhook(s, e):
... if s =='sqlite3.connect':
... raisePermissionError
...
>>> sys.addaudithook(hook)
>>> sqlite3.connect(':memory:')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 3, in hook
PermissionError
>>> sqlite3.Connection(':memory:')
<sqlite3.Connection object at 0x7f94b0157a80>
New changeset c96cc08 by Erlend Egeberg Aasland in branch 'master': bpo-43434: Move sqlite3.connect audit events to sqlite3.Connection.__init__ (GH-25818) c96cc08
Thanks, Steve, that means a lot! Glad to help. Thank you for getting it into beta1. Having the new event out there with the wrong object passed to it would have been a tiny bit embarrassing :)
New changeset ad73d16 by Erlend Egeberg Aasland in branch '3.9': bpo-43434: Move sqlite3.connect audit event to sqlite3.Connection.__init__ (GH-25818) ad73d16
New changeset 10665ac by Erlend Egeberg Aasland in branch '3.8': bpo-43434: Move sqlite3.connect audit events to sqlite3.Connection.__init__ (GH-25818) 10665ac
Activity
erlend-aasland commentedon Mar 8, 2021
The module level connect method is guarded by PySys_Audit(), but sqlite3.Connection.__init__() is not. It is possible to bypass the module level connect() method simply by creating a new sqlite3.Connection object directly.
Easily fixed by either moving the PySys_Audit() check to pysqlite_connection_init(), or by adding an extra check in pysqlite_connection_init().
erlend-aasland commentedon Apr 30, 2021
Steve, is it worth it to improve this?
zooba commentedon May 2, 2021
Yes, let's move it into the init function.
erlend-aasland commentedon May 2, 2021
The PR accidentally fixes a bug in #69433 (bpo-43762):
The object passed to PySys_Audit() is now the connection object, not the module object.
erlend-aasland commentedon May 2, 2021
Steve, can we get this in before beta1 (bco. the bugfix)?
zooba commentedon May 2, 2021
New changeset c96cc08 by Erlend Egeberg Aasland in branch 'master':
bpo-43434: Move sqlite3.connect audit events to sqlite3.Connection.__init__ (GH-25818)
c96cc08
zooba commentedon May 2, 2021
We could get this one in after beta 1 anyway, but sure, it's in.
The backports are going to have to be manual, I suspect...
erlend-aasland commentedon May 2, 2021
Thanks! :) I'll fix the backports.
zooba commentedon May 2, 2021
Thanks, Erlend! Appreciate how quickly you got onto that, and the quality of your work.
zooba commentedon May 2, 2021
New changeset cbb7b9e by Erlend Egeberg Aasland in branch 'master':
bpo-43434: Clean up sqlite3.connect() after #70004 (GH-25823)
cbb7b9e
erlend-aasland commentedon May 2, 2021
Thanks, Steve, that means a lot! Glad to help. Thank you for getting it into beta1. Having the new event out there with the wrong object passed to it would have been a tiny bit embarrassing :)
zooba commentedon May 2, 2021
New changeset ad73d16 by Erlend Egeberg Aasland in branch '3.9':
bpo-43434: Move sqlite3.connect audit event to sqlite3.Connection.__init__ (GH-25818)
ad73d16
zooba commentedon May 2, 2021
New changeset 10665ac by Erlend Egeberg Aasland in branch '3.8':
bpo-43434: Move sqlite3.connect audit events to sqlite3.Connection.__init__ (GH-25818)
10665ac