Summary
Anyquery versions before 0.4.5 allow unauthenticated SQL submitted through the MySQL-compatible server port to direct SQLite's ATTACH DATABASE operation to arbitrary writable filesystem paths. A remote attacker may create or overwrite files with attacker-controlled database content, causing filesystem integrity loss or denial of service; remote code execution is conditional on another service interpreting the file or on access to a suitably privileged target.
Affected context
The issue occurs in Anyquery deployments that expose the MySQL-compatible server port and forward unauthenticated SQL to SQLite without restricting filesystem targets used by database attachment operations. Risk depends on the permissions of the Anyquery server process, the files and directories it can write, and whether other services consume files in those locations.
Exploit preconditions
- Attack surface: Anyquery's network-accessible MySQL-compatible server port
- Required access: Network reachability; authentication is not required by the affected interface
- Trigger point: SQLite database attachment through SQL handled by the Anyquery server
- Filesystem condition: The Anyquery process must have write permission to the selected target path
- Why exploitation is possible: User-controlled SQL can influence a filesystem destination without an effective allowlist or confinement policy
Why this happens
The underlying bug is insufficient restriction of filesystem paths accepted by SQLite database attachment functionality. Unauthenticated SQL is treated as trusted database control input, allowing a remote party to select writable locations outside the intended data directory and populate resulting files with controlled content. This behavior aligns primarily with CWE-22: Improper Limitation of a Pathname to a Restricted Directory, with related weaknesses involving externally controlled filenames and missing authorization checks.
Potential impact
- Arbitrary files may be created in locations writable by the Anyquery process.
- Existing writable files may be overwritten or corrupted.
- Filesystem integrity may be lost.
- The Anyquery host or service may experience denial of service.
- Other applications may consume attacker-controlled files.
- Remote code execution could occur if a written file is interpreted by another service or reaches a suitably privileged execution path.
General mitigation guidance
Mitigation generally focuses on removing unauthenticated database access and constraining all database-related filesystem operations.
Common defensive patterns include:
- Require authentication and authorization before accepting SQL over network interfaces.
- Disable or restrict database attachment functionality when it is not required.
- Resolve and validate paths against a dedicated, non-sensitive data directory.
- Apply canonicalization, allowlists, and filesystem sandboxing rather than trusting client-supplied paths.
- Run Anyquery with a dedicated least-privilege account and minimal write permissions.
- Separate service data from directories consumed by interpreters, loaders, or other privileged services.
- Use read-only mounts and operating-system confinement controls where feasible.
How teams detect issues like this
Detection can combine application, host, and source analysis:
- Monitor unauthenticated connections and unusual SQL activity on the MySQL-compatible port.
- Alert on database files or unexpected file types appearing outside approved Anyquery data directories.
- Review file creation and overwrite events performed by the Anyquery service account.
- Use static analysis and code review rules to identify unrestricted database attachment APIs, client-controlled paths, and missing authorization checks.
- Enforce policies that prohibit network-exposed unauthenticated SQL services and writes to sensitive or service-consumed directories.
- Neutral automated security review tools may help identify path-handling and authorization gaps during development.

