T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/obs_target_switch.sh:7
- Finding
- SQL Injection in OBS Target Configuration Update## Vulnerability Details **File Location**: `scripts/obs_target_switch.sh`, lines 7-30 **Vulnerability Type**: SQL injection through unvalidated command-line arguments **Risk Level**: High **Vulnerable Code**: ```bash HOST="${1:-}" PORT="${2:-4455}" DB="${3:-}" ACK="${4:-}" if [[ -z "$HOST" || -z "$DB" ]]; then echo "Usage: ./scripts/obs_target_switch.sh <obs-host> [obs-port] <agentic-obs-db-path> --allow-cross-component-write" echo "Example: ./scripts/obs_target_switch.sh 192.168.1.50 4455 \"$HOME/.agentic-obs/db.sqlite\" --allow-cross-component-write" exit 1 fi if [[ ! -f "$DB" ]]; then echo "ERROR: DB file not found: $DB" exit 1 fi if [[ "$ACK" != "--allow-cross-component-write" ]]; then echo "ERROR: This script writes to an external agentic-obs DB." echo "Add explicit acknowledgement flag: --allow-cross-component-write" exit 1 fi sqlite3 "$DB" "update config set value='$HOST', updated_at=datetime('now') where key='obs_host';" sqlite3 "$DB" "update config set value='$PORT', updated_at=datetime('now') where key='obs_port';" ``` ### Technical Analysis The `HOST` and `PORT` command-line arguments are inserted directly into SQL string literals. Neither value is validated nor escaped before being passed to the SQLite command-line client. Shell quoting does not prevent this vulnerability because the injection occurs in the generated SQL statement rather than at the shell parsing layer. A value containing a single quote can terminate the intended SQL literal and append additional SQLite statements. For example, a malicious host shaped like: ```text x'; DELETE FROM config; -- ``` can transform the first update into multiple statements, including an attacker-supplied operation. The explicit `--allow-cross-component-write` acknowledgement controls whether the script proceeds, but it does not ensure that the resulting database operation is limited to the intended conf ...[truncated 1477 chars]
- Remediation
- ## Remediation Suggestions 1. Replace SQL string interpolation with parameterized queries. A small Python helper using the standard `sqlite3` module can bind values safely: ```python import sqlite3 with sqlite3.connect(database_path) as connection: connection.execute( "UPDATE config SET value=?, updated_at=datetime('now') WHERE key=?", (host, "obs_host"), ) connection.execute( "UPDATE config SET value=?, updated_at=datetime('now') WHERE key=?", (str(port), "obs_port"), ) ``` 2. Validate `PORT` as an integer from 1 through 65535 before accessing the database. 3. Validate `HOST` as an IPv4 address, IPv6 address, or hostname using a strict parser. Reject quotes, control characters, whitespace, SQL metacharacters, and unexpected URL components. 4. Resolve the database path to a canonical path and, where practical, restrict it to the expected agentic-obs configuration location. 5. Verify the expected database schema and confirm that the `config` table and target keys exist before making changes. 6. Execute both updates within one transaction and roll back if either update fails. 7. Retain the acknowledgement flag as a defense against accidental cross-component writes, but do not treat it as an input-sanitization control.
