T09 · Insecure Skill Coding Practices
- Location
scripts/mssql_query.sh:4- Finding
Credential File Is Executed as Arbitrary Bash Code
- Content
View full analysis
Vulnerability Details
File Location:
scripts/mssql_query.sh, lines 4-9
Vulnerability Type: Unsafe execution of a credential configuration file
Risk Level: HighVulnerable Code
bash ENV_FILE_DEFAULT="${HOME}/.openclaw/credentials/mssql.env" ENV_FILE="${MSSQL_ENV_FILE:-$ENV_FILE_DEFAULT}" if [[ -f "$ENV_FILE" ]]; then # shellcheck disable=SC1090 source "$ENV_FILE" fiTechnical Analysis
The script uses Bash
sourceto load the MSSQL credential file.sourcedoes not treat the file as inert configuration data; it evaluates every line as Bash code in the current process.Consequently, a credential file can contain command substitutions, function calls, redirections, external command invocations, or arbitrary shell statements. The path is also selectable through the inherited
MSSQL_ENV_FILEenvironment variable. No path, ownership, permission, or content validation occurs before the file is evaluated.The credential access itself is necessary for the declared MSSQL functionality, but executing the credential file as code exceeds the privileges required. The script only needs to read an allowlisted set of connection parameters.
Attack Path
- An attacker gains the ability to influence the invoking environment or write a file accessible to the Agent.
- The attacker sets
MSSQL_ENV_FILEto the malicious file, or modifies the default file at~/.openclaw/credentials/mssql.env. - The victim or Agent invokes
scripts/mssql_query.sh. - The script evaluates the selected file through
source. - Commands embedded in the file execute before credential validation or the MSSQL connection.
- The malicious commands can access the invoking process's files, environment, and network capabilities.
Example malicious credential-file content could invoke an arbitrary local program while still defining the expected variables. Exploitation does not require SQL injection or a succes ...[truncated 710 chars]
- Remediation
View remediation
Remediation Suggestions
- Do not use
source,., orevalto read credential files. - Parse the file as inert data and allow only the exact supported keys:
MSSQL_HOSTMSSQL_DBMSSQL_USERMSSQL_PASSWORDMSSQL_PORTMSSQL_ENCRYPTMSSQL_TRUST_CERT
- Reject unknown keys, duplicate keys, malformed lines, command substitutions, shell expansions, and control characters.
- Prefer receiving credentials from a protected secret manager or a narrowly controlled process environment.
- If
MSSQL_ENV_FILEremains supported, resolve it to a canonical path and enforce an approved directory policy. - Verify that the credential file is a regular file, is owned by the expected user, and is not group- or world-writable.
- Document and enforce restrictive permissions such as
chmod 600 ~/.openclaw/credentials/mssql.env. - Validate each parsed value according to its expected type, including numeric ranges for ports and strict enumerations for boolean options.
- Do not use
