Summary
SurrealDB before version 3.1.5 contains an arbitrary file read flaw in the DEFINE ANALYZER mapper filter, where user-controlled paths can be used to access files visible to the SurrealDB process.
When the SURREAL_FILE_ALLOWLIST is empty or not configured, database users with EDITOR or OWNER roles can cause path-based reads and surface file contents via query error messages.
Affected context
This vulnerability occurs in SurrealDB deployments that expose DEFINE ANALYZER functionality to users with elevated database roles (EDITOR or OWNER).
It is relevant when the SURREAL_FILE_ALLOWLIST environment configuration is missing, empty, or otherwise not restricting which files can be opened by the analyzer mapper filter.
The impacted context includes any SurrealDB instance that processes analyzer mapper filters with filesystem access and runs under a service account that has read permissions to sensitive files.
Exploit preconditions
- Attack surface: SurrealDB query interface where DEFINE ANALYZER mapper filters are accepted.
- Required access: Database-level EDITOR or OWNER privileges to define or modify analyzers.
- Trigger point: Execution of a mapper filter that references a file path during analysis or query processing.
- Why exploitation is possible: User-controlled file paths are passed to underlying file access logic without effective restriction when SURREAL_FILE_ALLOWLIST is unset or empty, enabling path traversal-style reads of arbitrary files accessible to the SurrealDB process. Returned error messages can accidentally disclose portions of file contents.
Why this happens
The underlying bug belongs to CWE-22: Improper Limitation of a Pathname to a Restricted Directory (Path Traversal).
The DEFINE ANALYZER mapper filter allows specifying file paths that are used by the database engine to access local files, but those paths are not consistently constrained to a safe directory or validated against a robust allowlist.
In the absence of a properly configured SURREAL_FILE_ALLOWLIST, the system effectively trusts user-supplied paths, allowing analyzers to traverse the filesystem and read files that should never be exposed through the database interface.
This insecure pattern reflects a failure to enforce clear boundaries between application-level configuration paths and arbitrary user input.
Potential impact
- Attackers with EDITOR or OWNER roles may read configuration files containing secrets or credentials.
- Sensitive operating system files (e.g., logs, service configs) could be exposed if readable by the SurrealDB process.
- Application source code or SQL scripts may be disclosed, aiding further exploitation.
- Internal error messages can leak file contents and filesystem structure, improving an attacker's knowledge of the environment.
General mitigation guidance
Effective mitigation focuses on strictly constraining filesystem interactions and reducing trust in user-controlled paths.
Recommended defensive patterns include:
- Enforcing a robust allowlist of directories or files that analyzers are permitted to access, with configuration defaults that deny access when not explicitly set.
- Normalizing and validating any user-provided path against this allowlist, rejecting inputs that attempt traversal or reference unexpected locations.
- Designing analyzer functionality so that file-based configuration is controlled and immutable by regular database users, using static configuration instead of runtime path parameters where possible.
- Running the SurrealDB process under a least-privilege service account that cannot read sensitive system or application files, reducing the blast radius of any file read issue.
- Applying secure-by-default settings so that an absent or empty allowlist results in no file access, rather than unrestricted access.
How teams detect issues like this
Organizations can identify and monitor this type of vulnerability using a combination of code and configuration review:
- Static analysis rules or manual code review focused on places where user input influences filesystem paths, checking for missing normalization and allowlist enforcement.
- Configuration audits to ensure SURREAL_FILE_ALLOWLIST (or equivalent path restrictions) is defined, non-empty, and points only to safe directories.
- Query logging and anomaly detection looking for suspicious analyzer definitions that reference unexpected or system-level file paths.
- Security policies that flag or block features granting filesystem access through database interfaces, combined with automated checks in CI/CD to prevent introduction of unsafe path-handling patterns.

