Capabilities
SurrealDB is secure by default and is suitable for all database use cases. While it offers powerful features like scripting, functions or network access from within your SurrealQL queries, most of these features are disabled by default unless an administrator allows them as needed per use case.
Important
When a query wants to use a capability that is not allowed, SurrealDB will reject it.
This rejection will also be logged in the SurrealDB server.
In production deployments, we recommend denying all capabilities by default and specifically allowing only those required.
You can learn more about best practices when using capabilities in our Security Best Practices guide.
Priority
By default, all capabilities are denied unless allowed. Some few capabilities (e.g. functions) are allowed by default.
Capabilities can be configured globally (e.g. --allow-all, --deny-all), generally (e.g. --allow-net, --deny-funcs) or specifically (e.g. --deny-net 192.168.1.1, --allow-funcs string::len).
When capabilities are configured, the more specific capabilities prevail over the less specific. At the same level of specificity, denies always prevail over allows.
Examples
Capabilities configured generally prevail over those defined globally:
Running with
--deny-all --allow-scriptingwill deny all capabilities except for scripting.Running with
--allow-all --deny-netwill allow all capabilities except for network.
Capabilities configured specifically prevail over those defined globally or generally:
Running with
--deny-all --allow-net example.comwill deny all capabilities except network connections toexample.com.Running with
--allow-all --deny-funcs httpwill allow all capabilities except for calling functions of thehttpfamily.Running with
--deny-funcs --allow-funcs string::lenwill deny all functions except forstring::len.Running with
--allow-net --deny-net 10.0.0.0/8will allow all network connections except to the10.0.0.0/8block.
Capabilities denied specifically prevail over those allowed specifically:
Running with
--deny-funcs crypto --allow-funcs md5will deny all functions of thecryptoincludingcrypto::md5.Running with
--allow-funcs crypto --deny-funcs md5will allow all functions of thecryptofamily except forcrypto::md5.
List
List of options for allowing capabilities:
| Option | Description | Default |
|---|---|---|
| -A, --allow-all | Allow all capabilities except for those more specifically denied like experimental features | False |
| -A, --allow-arbitrary-query | Denies arbitrary queries to be used by user groups. Possible user groups are: 'guest', 'record', and 'system'. | False |
| --allow-experimental |
Allow the usage of one or more experimental features. Possible values are surrealism and files, separated by a comma.
| None |
| --allow-funcs [<target>,...] | Allow execution of all functions except for functions that are specifically denied. Alternatively, you can provide a comma-separated list of function names to allow | None |
| --allow-guests | Allow non-authenticated users to execute queries when authentication is enabled | False |
| --allow-net [<target>,...] | Allow all outbound network access except for network targets that are specifically denied. Alternatively, you can provide a comma-separated list of network targets to allow | None |
| --allow-scripting | Allow execution of embedded scripting functions | False |
List of options for denying capabilities:
| Option | Description | Default |
|---|---|---|
| -D, --deny-all | Deny all capabilities except for those more specifically allowed | False |
| -D, --deny-arbitrary-query | Denies arbitrary queries from being used by user groups. Possible user groups are: 'guest', 'record', and 'system' | False |
| --deny-funcs [<target>,...] | Deny execution of all functions except for functions that are specifically allowed. Alternatively, you can provide a comma-separated list of function names to deny | None |
| --deny-guests | Deny non-authenticated users to execute queries when authentication is enabled | False |
| --deny-net [<target>,...] | Deny all outbound network access except for network targets that are specifically allowed. Alternatively, you can provide a comma-separated list of network targets to deny | None |
| --deny-scripting | Deny execution of embedded scripting functions | False |
Guest Access
Guest access is used when you want to expose certain parts of a database to non-authenticated users. It's useful when you want to serve datasets publicly and still require authentication for the rest of the system.
Even when this capability is allowed, a guest user can only execute functions or data operations like SELECT, CREATE, etc, and only if the PERMISSIONS clause for the resource being used in the query allows it.
Functions
SurrealDB offers built-in functions to perform common operations like string manipulation, math, etc. Users can also define their own functions with custom logic.
In certain environments, you may not want users to use specific functions (i.e. http::*) or execute any custom function at all. You can use the allow/deny lists to configure what functions are allowed and what functions are denied.
Network
SurrealDB offers http functions that can access external network endpoints.
If you want to allow or deny access to certain network target, you can configure the network options accordingly. Here are some examples:
SurrealDB will perform DNS lookups and prevent network access to a hostname that resolves to an IP network target defined within --deny-net.
Warning
It is strongly recommended that you deny by default by defining specific --allow-net targets and using additional layers of network security within your infrastructure.
Arbitrary queries
The --allow-arbitrary-query and --deny-arbitrary-query allows database administrators to allow or deny arbitrary quering by either guest, record or system users, or a combination of those. This capability settings affects the following: /sql endpoint, /key endpoints, /graphql endpoint and RPC methods use, select, create, update, merge, patch, delete, relate, insert, insert_relation, query and graphql.
Endpoints that do not accept arbitrary queries such as /version and authentication endpoints are not affected.
The --deny-arbitrary-query flag is often preceded with a DEFINE API statement to set up certain endpoints that users can use to access database resources in place of arbitrary queries.