DuckDB has a powerful extension mechanism, which has the same privileges as the user running DuckDB's (parent) process. This introduces security considerations. Therefore, we recommend reviewing the configuration options listed on this page and setting them according to your attack models.
DuckDB Signature Checks
DuckDB extensions are checked on every load using the signature of the binaries. There are currently four categories of extensions:
- Signed with a
corekey. Only extensions vetted by the core DuckDB team are signed with these keys. - Signed with a
communitykey. These are open-source extensions distributed via the DuckDB Community Extensions repository. - Signed with a key pinned by a custom extension repository. These keys are only trusted for extensions installed from that repository.
- Unsigned.
Overview of Security Levels for Extensions
DuckDB offers the following security levels for extensions.
| Usable extensions | Description | Configuration |
|---|---|---|
core |
Extensions can only be loaded if signed from a core key. |
SET allow_community_extensions = false |
core and community |
Extensions can only be loaded if signed from a core or community key. |
This is the default security level. |
| Any extension including unsigned | Any extensions can be loaded. | Set allow_unsigned_extensions = true at startup (e.g., duckdb -unsigned in the CLI). It cannot be changed while the database is running. |
Security-related configuration settings lock themselves, i.e., it is only possible to restrict capabilities in the current process.
For example, attempting the following configuration changes will result in an error:
SET allow_community_extensions = false;
SET allow_community_extensions = true;
Invalid Input Error:
Cannot change allow_community_extensions setting while database is running
Custom Extension Repositories
DuckDB 2.0.0 introduced trusted custom extension repositories, which serve extensions signed with the publisher's own keys. DuckDB checks that an extension from such a repository is signed with one of the keys it pinned when the repository was created, and nothing else: it does not review what the repository publishes. Registering a repository is a decision to trust its publisher.
By default, DuckDB does not restrict host-based repositories: any user can register one with CREATE EXTENSION REPOSITORY host, and extensions from every registered repository can be installed and loaded. Restricting this is an opt-in, through two settings:
allow_extension_repositories: which custom trusted extension repositories can be added, and which are trusted.'hosts'(the default) lets a repository be added by naming its host and keeps trusting existing repositories,'allowed'also permits adding a repository by prefix,'hosts_only'only adds and trusts repositories resolved from their host, and'forbidden'adds nothing and distrusts all custom repositories. While the database is running, the setting can only be tightened, in that order: once set, no later statement can loosen it. The'hosts'and'hosts_only'values require DuckDB 2.0.1; in 2.0.0 the default is'undecided', which blocks adding repositories and keeps trusting existing ones.extension_repository_directory: the directory in which trusted extension repositories are stored. This is the trust anchor for user-provided repositories, so while signature checking is enabled (allow_unsigned_extensions = false), it can only be set at startup, not while the database is running.
If only extensions signed by the DuckDB team should be loaded, forbid custom repositories:
SET allow_extension_repositories = 'forbidden';
If the repositories registered so far should stay usable but no repository may be added or dropped, lock the configuration instead. This freezes the trust store, along with every other setting:
SET lock_configuration = true;
Community Extensions
DuckDB has a Community Extensions repository, which allows convenient installation of third-party extensions. Community extension repositories like pip or npm are essentially enabling remote code execution by design. This is less dramatic than it sounds. For better or worse, we are quite used to piping random scripts from the web into our shells, and routinely install a staggering amount of transitive dependencies without thinking twice. Some repositories like CRAN enforce a human inspection at some point, but that’s no guarantee for anything either.
We’ve studied several different approaches to community extension repositories and have picked what we think is a sensible approach: we do not attempt to review the submissions, but require that the source code of extensions is available. We do take over the complete build, sign, and distribution process. Note that this is a step up from pip and npm that allow uploading arbitrary binaries but a step down from reviewing everything manually. We allow users to report malicious extensions and show adoption statistics like GitHub stars and download count. Because we manage the repository, we can remove problematic extensions from distribution quickly.
Despite this, installing and loading DuckDB extensions from the community extension repository will execute code written by third party developers, and therefore can be dangerous. A malicious developer could create and register a harmless-looking DuckDB extension that steals your crypto coins. If you’re running a web service that executes untrusted SQL from users with DuckDB, we recommend disabling community extensions. To do so, run:
SET allow_community_extensions = false;
Disabling Autoinstalling and Autoloading Known Extensions
By default, DuckDB automatically installs and loads known extensions. To disable autoinstalling known extensions, run:
SET autoinstall_known_extensions = false;
To disable autoloading known extensions, run:
SET autoload_known_extensions = false;
To lock this configuration, use the lock_configuration option:
SET lock_configuration = true;
Always Require Signed Extensions
By default, DuckDB requires extensions to be either signed as core extensions (created by the DuckDB developers) or community extensions (created by third-party developers but distributed by the DuckDB developers).
The allow_unsigned_extensions setting can be enabled on start-up to allow loading unsigned extensions.
While this setting is useful for extension development, enabling it will allow DuckDB to load any extensions, which means more care must be taken to ensure malicious extensions are not loaded.