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
{{ message }}
Repository navigation
Add audit events for loading of sqlite3 extensions #87928
If Python is configured with --enable-loadable-sqlite-extensions, it is possible to load third party SQLite extensions (shared libraries/DLL’s) via the sqlite3 extension module. When enabled, the sqlite3.Connection.enable_load_extension() class method will enable the loading of third party extensions via SQL queries, using the SQL function load_extension(). It also enables loading extension via C, using the sqlite3.Connection.load_extension() class method.
Suggesting to add the following audit event names to respectively the sqlite3.Connection.enable_load_extension() and sqlite3.Connection.load_extension() methods:
Left some minor suggestions on the PR, but wanted to copy this comment here as well:
I wonder if it's worth returning the connection object when it's created (through a new event in module.c) and then reference it in these events? That can then correlate these (and other) events with the file - we do this already for sockets.
After some thought, I think it's probably not worth it for these ones. The important information is in the extension being loaded, and it doesn't really relate to the connection at all. However, if we wanted to add it later, we couldn't. So might be worth doing now?
Good question. sqlite3_load_extension() loads an extension into a database connection, so it would make sense to also pass the connection object. I'd say we do it; it's a small change, and as you say: if we wanted to add it later, we couldn't.
Activity
erlend-aasland commentedon Apr 7, 2021
If Python is configured with --enable-loadable-sqlite-extensions, it is possible to load third party SQLite extensions (shared libraries/DLL’s) via the sqlite3 extension module. When enabled, the sqlite3.Connection.enable_load_extension() class method will enable the loading of third party extensions via SQL queries, using the SQL function load_extension(). It also enables loading extension via C, using the sqlite3.Connection.load_extension() class method.
Suggesting to add the following audit event names to respectively the sqlite3.Connection.enable_load_extension() and sqlite3.Connection.load_extension() methods:
Ref.
zooba commentedon Apr 23, 2021
Left some minor suggestions on the PR, but wanted to copy this comment here as well:
I wonder if it's worth returning the connection object when it's created (through a new event in module.c) and then reference it in these events? That can then correlate these (and other) events with the file - we do this already for sockets.
After some thought, I think it's probably not worth it for these ones. The important information is in the extension being loaded, and it doesn't really relate to the connection at all. However, if we wanted to add it later, we couldn't. So might be worth doing now?
erlend-aasland commentedon Apr 24, 2021
Good question. sqlite3_load_extension() loads an extension into a database connection, so it would make sense to also pass the connection object. I'd say we do it; it's a small change, and as you say: if we wanted to add it later, we couldn't.
Ref.
erlend-aasland commentedon Apr 24, 2021
Something like the attached patch, if I understand you correctly?
erlend-aasland commentedon Apr 24, 2021
Maybe it's better to send the event only if the connection succeeded:
zooba commentedon Apr 26, 2021
Yeah, along those lines. I believe the event is ".../result" in other places, just to be clear that it's not a function with that name.
Also, don't forget to clean up when returning early from the connected event. We don't want to leak the connection object if the hook raises an error.
erlend-aasland commentedon Apr 26, 2021
Ah, yes thanks for the heads up! I'll update the PR.
zooba commentedon Apr 26, 2021
New changeset 7244c00 by Erlend Egeberg Aasland in branch 'master':
bpo-43762: Add audit events for loading of sqlite3 extensions (GH-25246)
7244c00
zooba commentedon Apr 26, 2021
Thanks for the PR!