GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Enhancement request: Add "entrypoint" as an option to `sqlite3.load_extension()` · Issue #103015 · python/cpython

Enhancement request: Add "entrypoint" as an option to sqlite3.load_extension() #103015

New issue
Copy link
New issue
Copy link
Closed
#103073
Closed
Enhancement request: Add "entrypoint" as an option to sqlite3.load_extension()#103015
#103073
Copy link
Assignees
erlend-aasland
Labels
topic-sqlite3type-featureA feature request or enhancementA feature request or enhancement

Description

@asg017
asg017
opened on Mar 24, 2023
Issue body actions

Enhancement Request:

The current version of sqlite3.Connection.load_extension() takes in a single parameter path. However, the underlying C API sqlite3_load_extension has an additional entrypoint argument that I think should be added to the Python load_extension function.

Currently in connection.c, the entrypoint parameter is ignored with a null pointer:

cpython/Modules/_sqlite/connection.c

Line 1624 in f2e5a6e

rc = sqlite3_load_extension(self->db, extension_name, 0, &errmsg);

Pitch

We add a new second optional entrypoint parameter to the load_extension() Python function. If it is provided, it's passed along to the underlying sqlite3_load_extension C function as the extension entrypoint.

import sqlite3
db = sqlite3.connect(":memory:")
db.enable_load_extension(True)

# Currently, only a single path argument is supported on load_extension()
db.load_extension("./lines0")

# In this proposal, an optional 2nd entrypoint parameter would be added
db.load_extension("./lines0", "sqlite3_lines_no_read_init")

db.enable_load_extension(False)

I've been building several SQLite extensions, some of which use different entrypoints to enable/disable security sensitive features. For example, in sqlite-lines (A SQLite extension for reading files line-by-lines), there will be a secondary entrypoint called sqlite3_lines_no_read_init that disables all functions that read the filesystem, for use in Datasette or other security-sensitive environments.

Many of these extensions are also distributed as Python packages, so any extra customizable APIs for loading SQLite extensions is greatly appreciated!

Workaround

There technically is a workaround for this: A user can use the load_extension() SQL function to load an extension with an entrypoint, like so:

db = sqlite3.connect(":memory:")
db.enable_load_extension(True)
db.execute("select load_extension(?, ?)", ["path/to/extension", "entrypoint"])

However, doing so will circumvent the sqlite3.load_extension auditing event, as that's only trigged on calls to the python Connection.load_extension() function.

There's also some limitations to the pure SQL load_extension() function, mentioned here:

The load_extension() function will fail if the extension attempts to modify or delete an SQL function or collating sequence. The extension can add new functions or collating sequences, but cannot modify or delete existing functions or collating sequences because those functions and/or collating sequences might be used elsewhere in the currently running SQL statement. To load an extension that changes or deletes functions or collating sequences, use the sqlite3_load_extension() C-language API.
Source: https://www.sqlite.org/lang_corefunc.html#load_extension

Also in general, it's recommended to avould the SQL load_extension() function altogether:

Security warning: It is recommended that extension loading be enabled using the SQLITE_DBCONFIG_ENABLE_LOAD_EXTENSION method rather than this interface, so the load_extension() SQL function remains disabled. This will prevent SQL injections from giving attackers access to extension loading capabilities.
Source: https://www.sqlite.org/c3ref/enable_load_extension.html

It's also just a little awkward, having to "eject" to SQL to do something that the Python API could readily support.

Linked PRs

  • gh-103015: Add entrypoint parameter to sqlite3.Connection.load_extension #103073

Activity

  1. asg017
    added
    type-featureA feature request or enhancementA feature request or enhancement
    on Mar 24, 2023
  2. AlexWaygood
    added
    topic-sqlite3
    on Mar 24, 2023
  3. erlend-aasland
    self-assigned this
    on Mar 27, 2023
  4. erlend-aasland commented on Mar 27, 2023

    @erlend-aasland
    erlend-aasland
    on Mar 27, 2023
    Contributor
    More actions

    This sounds like a reasonable feature request to me. Adding entrypoint as a keyword only argument would be ok to me. If you have the time and resources, please create a PR. If not, I'll try to get it done before the feature freeze in May.

  5. erlend-aasland
    added this to sqlite3 issueson Mar 27, 2023
  6. erlend-aasland
    moved this to TODO: Feature in sqlite3 issueson Mar 27, 2023
  7. erlend-aasland
    moved this from TODO: Feature to In Progress in sqlite3 issueson Mar 28, 2023
  8. erlend-aasland
    added a commit that references this issue on Apr 26, 2023

    gh-103015: Add entrypoint keyword param to sqlite3.Connection.load_ex…

    222c63f
  9. erlend-aasland
    linked a pull request that will close this issuegh-103015: Add entrypoint parameter to sqlite3.Connection.load_extension #103073on Apr 26, 2023
  10. erlend-aasland commented on Apr 26, 2023

    @erlend-aasland
    erlend-aasland
    on Apr 26, 2023
    Contributor
    More actions

    Thanks for the nice suggestion, @asg017!

  11. erlend-aasland
    closed this as completedon Apr 26, 2023
  12. github-project-automation
    moved this from In Progress to Done in sqlite3 issueson Apr 26, 2023
  13. itamaro
    added a commit that references this issue on Apr 26, 2023

    pythongh-103015: Add entrypoint keyword param to sqlite3.Connection.l…

    ffc55c4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @erlend-aasland
    erlend-aasland

Labels

topic-sqlite3type-featureA feature request or enhancementA feature request or enhancement

Projects

  • sqlite3 issues
    Status
    Done
    Show more project fields

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

You are visitor 01402503 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.