Summary
Anyquery contains a path traversal vulnerability in the clear_plugin_cache(plugin) SQL function. A low-privileged bearer-token holder who can submit queries to the /v1/query endpoint may cause the server to recursively delete directories writable by its process, resulting in data loss or denial of service.
Affected context
The vulnerability occurs in Anyquery deployments before the affected fix where the plugin-cache cleanup function accepts caller-controlled names. Risk is present when:
- The
/v1/queryendpoint is reachable by a user with a valid low-privileged bearer token - The SQL function is available to that user
- The Anyquery process can write to directories outside its intended plugin-cache location
- User-supplied path components are joined and passed to recursive deletion without traversal checks
Exploit preconditions
- Attack surface: The
/v1/queryHTTP endpoint and its SQL function interface - Required access: A valid bearer token with permission to submit queries
- Trigger point: Invocation of the
clear_plugin_cache(plugin)scalar function - Why exploitation is possible: Caller-controlled path components are resolved with
path.Join, allowing traversal segments to escape the intended cache directory beforeos.RemoveAllperforms recursive deletion
Why this happens
The underlying bug is insufficient canonicalization and validation of an attacker-controlled filesystem path. The application treats a value intended to identify a plugin as a safe path component, but path joining can interpret traversal segments as directory navigation. Passing the resulting path to a recursive removal operation permits deletion beyond the designated cache root. This behavior maps to CWE-22: Improper Limitation of a Pathname to a Restricted Directory ('Path Traversal').
Potential impact
- An attacker may delete files or directories writable by the Anyquery server process
- The service could experience denial of service
- Persistent data loss could occur
- Plugin or application state may be disrupted
- Recovery operations could require restoration from backups
General mitigation guidance
Mitigation generally focuses on enforcing a strict filesystem trust boundary before any deletion operation.
Common defensive patterns include:
- Accepting only opaque, allowlisted plugin identifiers rather than path fragments
- Resolving candidate paths and verifying that they remain beneath the intended cache root
- Rejecting traversal components, absolute paths, symbolic-link escapes, and unexpected separators
- Using narrowly scoped deletion APIs that operate only on known plugin directories
- Running the service with a dedicated least-privileged account and minimal writable filesystem access
- Separating cache storage from persistent application data and applying filesystem protections where practical
- Restricting which authenticated roles may invoke maintenance-oriented SQL functions
How teams detect issues like this
Detection approaches can include:
- Static analysis rules for user-controlled values passed to path-joining and recursive deletion APIs
- Code review checks for filesystem operations reachable through SQL functions or HTTP request handlers
- Tests that verify canonicalized paths cannot escape an approved directory
- Runtime audit logging for cache-clearing calls and recursive deletion failures
- Policy enforcement that blocks maintenance functions from low-privilege query roles
- Automated security review tools that identify path traversal and dangerous file-operation patterns

