← 输入框|github.com|刷新
Skip to content

Add audit events for loading of sqlite3 extensions #87928

Closed

Description

@erlend-aasland
BPO 43762
Nosy @tiran, @berkerpeksag, @zooba, @erlend-aasland
PRs
  • bpo-43762: Add audit events for loading of sqlite3 extensions #25246
  • bpo-43998: Default to TLS 1.2 and increase cipher suite security (GH-25778) #25778
  • Files
  • patch.diff
  • Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

    Show more details

    GitHub fields:

    assignee = None
    closed_at = <Date 2021-04-26.23:17:04.808>
    created_at = <Date 2021-04-07.10:51:19.610>
    labels = ['type-security', 'library', '3.10']
    title = 'Add audit events for loading of sqlite3 extensions'
    updated_at = <Date 2021-05-01.11:12:07.693>
    user = 'https://github.com/erlend-aasland'

    bugs.python.org fields:

    activity = <Date 2021-05-01.11:12:07.693>
    actor = 'christian.heimes'
    assignee = 'none'
    closed = True
    closed_date = <Date 2021-04-26.23:17:04.808>
    closer = 'steve.dower'
    components = ['Library (Lib)']
    creation = <Date 2021-04-07.10:51:19.610>
    creator = 'erlendaasland'
    dependencies = []
    files = ['49982']
    hgrepos = []
    issue_num = 43762
    keywords = ['patch']
    message_count = 9.0
    messages = ['390414', '391740', '391821', '391822', '391823', '391941', '391973', '391997', '391998']
    nosy_count = 4.0
    nosy_names = ['christian.heimes', 'berker.peksag', 'steve.dower', 'erlendaasland']
    pr_nums = ['25246', '25778']
    priority = 'normal'
    resolution = 'fixed'
    stage = 'resolved'
    status = 'closed'
    superseder = None
    type = 'security'
    url = 'https://bugs.python.org/issue43762'
    versions = ['Python 3.10']

    Activity

    1. erlend-aasland commented on Apr 7, 2021

      @erlend-aasland
      ContributorAuthor

      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:

      • sqlite3.enable_load_extension
      • sqlite3.load_extension

      Ref.

    2. added
      3.10 (EOL)
      stdlib
      type-security
      on Apr 7, 2021
    3. zooba commented on Apr 23, 2021

      @zooba
      Member

      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?

    4. erlend-aasland commented on Apr 24, 2021

      @erlend-aasland
      ContributorAuthor

      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.

    5. erlend-aasland commented on Apr 24, 2021

      @erlend-aasland
      ContributorAuthor

      Something like the attached patch, if I understand you correctly?

    6. erlend-aasland commented on Apr 24, 2021

      @erlend-aasland
      ContributorAuthor

      Maybe it's better to send the event only if the connection succeeded:

      diff --git a/Modules/_sqlite/module.c b/Modules/_sqlite/module.c
      index 8dbfa7b38a..0220978cf2 100644
      --- a/Modules/_sqlite/module.c
      +++ b/Modules/_sqlite/module.c
      @@ -97,6 +97,12 @@ static PyObject* module_connect(PyObject* self, PyObject* args, PyObject*
       
           result = PyObject_Call(factory, args, kwargs);
       
      +    if (result) {
      +        if (PySys_Audit("sqlite3.connected", "O", self) < 0) {
      +            return -1;
      +        }
      +    }
      +
           return result;
       }
    7. zooba commented on Apr 26, 2021

      @zooba
      Member

      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.

    8. erlend-aasland commented on Apr 26, 2021

      @erlend-aasland
      ContributorAuthor

      Ah, yes thanks for the heads up! I'll update the PR.

    9. zooba commented on Apr 26, 2021

      @zooba
      Member

      New changeset 7244c00 by Erlend Egeberg Aasland in branch 'master':
      bpo-43762: Add audit events for loading of sqlite3 extensions (GH-25246)
      7244c00

    10. zooba commented on Apr 26, 2021

      @zooba
      Member

      Thanks for the PR!

    11. transferred this issue fromon Apr 10, 2022
    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

      3.10 (EOL)stdlibtype-security

      Projects

      No projects

        Milestone

        No milestone

        Relationships

        None yet

        Development

        No branches or pull requests

        Issue actions