Disabling `bif:` and `sql:` functions access from the Virtuoso default SPARQL endpoint

Disabling bif: and sql: functions access from the Virtuoso default SPARQL endpoint

Overview

Virtuoso SPARQL queries can call Virtuoso built-in SQL functions (BIFs) with the bif: prefix, for example bif:contains, and Virtuoso/PL procedures with the sql: prefix. For users who are not DBA, Virtuoso blocks a built-in list of dangerous functions, such as bif:system, bif:file_to_string and bif:http_get. All other functions are allowed.

On a public SPARQL endpoint this default can expose more than intended. Several file and configuration functions are not on the built-in list, for example bif:file_open, bif:file_stat and bif:cfg_item_value. With these, an anonymous /sparql request can read files and configuration values from the server.

The sql: prefix is a second route into internal functionality. It reaches not only Virtuoso/PL procedures (which need an EXECUTE grant) but also internal SQL-callable functions without any grant — including some that are on the bif: deny-list. For example sql:http_client("http://…") makes the server itself issue an outbound HTTP request (a server-side request forgery, SSRF) even though bif:http_client is blocked by default. sparql_all_bif_unsafe does not cover the sql: path; only sparql_all_sql_unsafe does.

Two server flags let an administrator block these extensions completely for non-DBA users:

  • sparql_all_bif_unsafe: blocks every bif: function in SPARQL query text.
  • sparql_all_sql_unsafe: blocks every sql: function in SPARQL query text, and every bif: function as well.

Both default to 0 (off), which keeps the existing behaviour.

Availability

  • Virtuoso Commercial Edition 8.3: both flags. Included in 8.3.14 (June 2026) and later, and in 08.03.3335 builds from 12 May 2026 onward.
  • Virtuoso Open Source Edition 7.2: sparql_all_bif_unsafe only. It is on the develop/7 branch from 19 May 2026, and is not in the 7.2.17 release (May 2026) or earlier.

To check whether a running server supports a flag, run sys_stat() on it as described in Checking the current setting. An unknown flag returns an error or NULL.

Configuration

Permanently, in virtuoso.ini

Add the flag(s) to the [Flags] section of virtuoso.ini, creating the section if it does not exist, then restart the server:

[Flags]
sparql_all_bif_unsafe = 1
; recommended too: blocks all sql: functions (e.g. the sql:http_client SSRF) and all bif: functions
sparql_all_sql_unsafe = 1

At run time, without a restart

As dba, in isql or any SQL client:

__dbf_set ('sparql_all_bif_unsafe', 1);
__dbf_set ('sparql_all_sql_unsafe', 1);

The change takes effect immediately for all new SPARQL queries. It is not saved: after a restart the value comes from virtuoso.ini again, so also add the setting to the ini file.

To switch a flag off again at run time:

__dbf_set ('sparql_all_bif_unsafe', 0);

Checking the current setting

SELECT sys_stat ('sparql_all_bif_unsafe'), sys_stat ('sparql_all_sql_unsafe');

Behaviour

Which users are affected

The flags apply only to users who are not dba or a member of the dba group. They cover:

  • anonymous requests to /sparql, which normally run as the SPARQL user;
  • authenticated requests, for example to /sparql-auth, by non-DBA users;
  • SPARQL queries sent through SQL clients (isql, ODBC, JDBC) by non-DBA users.

DBA users are never restricted. The account used by a public SPARQL endpoint must therefore not be a member of the dba group, or the flags have no effect for it.

What is blocked

With sparql_all_bif_unsafe = 1, every BIF call in SPARQL text is rejected at compile time, whichever way it is written:

SELECT (bif:file_open ('./x.txt') AS ?x) WHERE {}
SELECT (<http://www.openlinksw.com/schemas/bif#file_open> ('./x.txt') AS ?x) WHERE {}
PREFIX b: <http://www.openlinksw.com/schemas/bif#>
SELECT (b:file_open ('./x.txt') AS ?x) WHERE {}

All three fail with:

37000 Error SP031: SPARQL compiler: Function http://www.openlinksw.com/schemas/bif#file_open() cannot be used in text of SPARQL query due to security restrictions

With sparql_all_sql_unsafe = 1, every sql: function call (prefix http://www.openlinksw.com/schemas/sql#) is rejected, including procedures the user has been granted EXECUTE on. This flag also blocks all bif: functions, so it is a superset of sparql_all_bif_unsafe. Both kinds of call fail with:

37000 Error SQ074: Line 1: Raw SQL access to internal RDF functions is not allowed if user does not have SPARQL_SELECT_RAW priviledge at '('

Despite its wording, this message is caused by the flag. Granting SPARQL_SELECT_RAW is not the intended way to re-enable these calls.

How the two flags combine for a non-DBA user:

  • Both 0 (default): sql: procedures work if the user has EXECUTE on them, otherwise they fail with SR186: No permission to execute procedure. bif: functions work unless they are on the built-in deny-list.
  • sparql_all_bif_unsafe = 1 only: all bif: calls are rejected with SP031. Granted sql: procedures still work — and so do sql: calls to internal functions such as sql:http_client, so SSRF and other sql:-reachable functions remain open.
  • sparql_all_sql_unsafe = 1, alone or with the bif flag: all sql: and all bif: calls are rejected with SQ074.

Use sparql_all_bif_unsafe = 1 on its own only if the endpoint deliberately exposes Virtuoso/PL procedures through sql: and controls them with EXECUTE grants — but note this leaves the rest of the sql: path open, including internal functions like sql:http_client. For a public endpoint that does not need sql: procedures, set sparql_all_sql_unsafe = 1 (it blocks both sql: and bif:); setting both flags is fine.

When granting EXECUTE to the SPARQL account, quote its name, because SPARQL is a keyword in isql:

GRANT EXECUTE ON DB.DBA.MY_PROC TO "SPARQL";

What is not affected

  • Standard SPARQL 1.1 functions and operators: STR, STRLEN, REGEX, CONTAINS, CONCAT, NOW, aggregates, xsd: casts and so on.
  • SPARQL query features such as GRAPH, OPTIONAL, property paths, subqueries and VALUES.
  • Free-text search written as a triple pattern, ?o bif:contains "word" (see below).
  • Queries from DBA users.
  • SQL code executed directly, not as SPARQL query text.

Side effects to check before enabling

sparql_all_bif_unsafe = 1 blocks every bif: function call in SPARQL text, including commonly used, harmless ones:

  • the function-call form of free-text search, FILTER (bif:contains (?o, "word"));
  • geospatial functions called as functions, such as bif:st_distance (...) or bif:st_intersects (...) in a FILTER or BIND;
  • string, date and other utility BIFs, such as bif:sprintf, bif:datediff and bif:lower.

Before enabling the flag on a production endpoint, check whether applications send bif: functions to the endpoint. The HTTP access log is the easiest place to look: search for bif%3A (URL-encoded) or bif: in /sparql request lines. Then see Allowing specific functions below.

Allowing specific functions while the flag is on

There is no setting that lists allowed bif: functions: once sparql_all_bif_unsafe = 1 is set, every bif: name is rejected for non-DBA users. The following options keep common use cases working.

Free-text search with the triple-pattern form of bif:contains

Free-text search written as a triple pattern, which is the usual and recommended form, is not a function call and is not affected by the flag:

SELECT ?s WHERE { ?s rdfs:label ?o . ?o bif:contains "word" }

SELECT ?s ?sc WHERE { ?s rdfs:label ?o . ?o bif:contains "word" OPTION (score ?sc) }

Both forms, including OPTION (score ...) and the full IRI <http://www.openlinksw.com/schemas/bif#contains> as the predicate, return results with the flag on. Only the function-call form is rejected:

SELECT ?s WHERE { ?s rdfs:label ?o . FILTER (bif:contains (?o, "word")) }   # SP031

Applications using the function-call form should switch to the triple-pattern form. This is also the form that uses the free-text index efficiently.

Using another BIF name as a predicate, for example ?o bif:file_open "x", does not call the function. The name is treated as an ordinary predicate IRI that matches no data.

Note that the geospatial predicates (such as bif:st_intersects used as a triple pattern) were not tested with geospatial data, so check them before relying on them.

Wrapper procedures, granted to the SPARQL account

Other BIFs can be allowed one at a time by wrapping them in a Virtuoso/PL procedure, granting EXECUTE on it to the endpoint account, and calling it with sql::

CREATE PROCEDURE DB.DBA.APP_SPRINTF (IN fmt VARCHAR, IN a ANY)
{
  RETURN sprintf (fmt, a);
};
GRANT EXECUTE ON DB.DBA.APP_SPRINTF TO "SPARQL";
SELECT (sql:APP_SPRINTF ("n=%s", 5) AS ?x) WHERE {}

This works with sparql_all_bif_unsafe = 1 only. It does not work if sparql_all_sql_unsafe = 1 is also set, because that flag blocks all sql: calls. Only wrap functions that are safe for anonymous users: never wrap file, OS, network or configuration functions. This approach suits value functions (string, date, number formatting). It does not suit bif:contains or other functions that need special query compilation, which should use the triple-pattern form above.

DBA accounts (not recommended)

Users in the dba group are never restricted, for example applications that authenticate to /sparql-auth with a dba-group account. This removes all restrictions for those applications and gives them full DBA rights, so it is not recommended as a way to allow individual functions.

Default protection without the flag

Without the flags (value 0), Virtuoso still blocks these for non-DBA SPARQL users:

  • all internal BIFs whose names start with __;
  • a built-in deny-list of BIFs, including system, exec, file_to_string, file_to_string_output, string_to_file, http_get, http_client, soap_call, smtp_send, ses_connect, backup, the registry_*, sequence_* and ldap_* functions, and similar;
  • a built-in deny-list of sql: procedures.

All other BIFs are allowed. These include file_open, gz_file_open, file_stat, cfg_item_value and virtuoso_ini_item_value, which can expose file contents, file details and configuration values. file_open is limited by DirsAllowed, but file_stat and cfg_item_value are not. For any SPARQL endpoint reachable by untrusted users, we recommend sparql_all_bif_unsafe = 1.

This deny-list is applied to the bif: prefix. Several of the same functions (for example http_client, http_get, soap_call) are still reachable through the sql: prefix until sparql_all_sql_unsafe = 1 is set, so the bif flag alone does not close them. For any endpoint reachable by untrusted users we therefore recommend setting both flags unless sql: procedures are deliberately exposed.

Related hardening

  • Keep DirsAllowed minimal: in the [Parameters] section, list only the directories Virtuoso needs (database, backup and bulk-load directories). Do not include home directories, log directories, /etc or /tmp.
  • Do not store passwords in files inside the DirsAllowed directories.
  • Grant SPARQL roles deliberately: give the public SPARQL account no roles beyond SPARQL_SELECT unless needed. SPARQL_UPDATE, SPARQL_SPONGE and SPARQL_LOAD_SERVICE_DATA allow writing data and making outgoing requests.

Summary

  • [Flags] sparql_all_bif_unsafe: default 0. Set to 1 to block all bif: functions in SPARQL for non-DBA users. Can be changed at run time: yes, __dbf_set.
  • [Flags] sparql_all_sql_unsafe: default 0. Set to 1 to block all sql: and all bif: functions in SPARQL for non-DBA users. Commercial Edition only. Can be changed at run time: yes, __dbf_set.

Tested

Tested with Virtuoso Commercial 08.03.3335 builds 4201928ad9 (29 Jul 2026) and 603d42d531 (29 Oct 2026), with identical results:

  • anonymous /sparql requests with each flag combination: granted and ungranted sql: procedures, harmless and file-access bif: functions, and the full-IRI and custom-PREFIX forms;
  • a DBA user running SPARQL through isql, which was not restricted;
  • with both flags on, standard SPARQL 1.1 functions, xsd: casts, aggregates (GROUP_CONCAT, SAMPLE, AVG, COUNT) and FILTER expressions, which all worked normally;
  • with sparql_all_bif_unsafe = 1 (603d42d531 only): ?o bif:contains "word" with and without OPTION (score ?sc) and the full-IRI form returned results, FILTER (bif:contains (...)) was rejected, and a granted sql: wrapper procedure returned results.
  • with sparql_all_sql_unsafe = 1 (4201928ad9 and 603d42d531): sql:http_client(...) and the file bif: functions were rejected with SQ074, while triple-pattern ?o bif:contains "word" still returned results — the sql flag closes the SSRF and file-read routes without breaking free-text search.