T09 · Insecure Skill Coding Practices
Error
- Location
- references/diagnose.md:31
- Finding
- Command Injection Through Unvalidated Deployment State Values<![CDATA[ ## Vulnerability Details **File Location**: `references/workflow.md:8-19`, `references/diagnose.md:31-39`, `references/recover_app.md:1-24` **Vulnerability Type**: Shell command injection through state-derived values **Risk Level**: Critical ### Vulnerable Code The workflow reads `service_name`, `app_port`, and resource identifiers from the project-controlled deployment state: ```text 2. Parse and extract: `region_id`, `stack_id`, `topology`, `app_type`, `nginx_mode`, `app_port`, `outputs.public_ip`, `outputs.ecs_instance_ids[]`, `outputs.security_group_id`, `outputs.eip_allocation_id`, and RDS fields (`outputs.db_instance_id` / `db_connection_address` / `db_port` / `db_account`, `db_engine`). Also `service_name` (service name, used for service/log checks; falls back to `qwencloud-app` when missing). ``` Those values are interpolated directly into a privileged diagnostic shell script: ```bash aliyun ecs RunCommand --RegionId <region> --Type RunShellScript --InstanceId.1 <ecs-id> \ --ContentEncoding Base64 \ --CommandContent "$(printf '%s' 'systemctl is-active <service_name>; systemctl is-active nginx; ss -ltnp | grep -E ":80|:<app_port>"; nginx -t 2>&1 | tail -n 3; df -h /; uptime; top -bn1 | head -n 12; free -m; journalctl -u <service_name> --since "30 min ago" --no-pager | tail -n 80' | base64)" aliyun ecs DescribeInvocations --RegionId <region> --InvokeId <invoke-id> --IncludeOutput true ``` The recovery procedure uses the same unsafe construction: ```bash aliyun ecs RunCommand --RegionId <region> --Type RunShellScript --InstanceId.1 <ecs-id> \ --ContentEncoding Base64 \ --CommandContent "$(printf '%s' 'systemctl restart <service_name> && sleep 3 && systemctl is-active <service_name>' | base64)" aliyun ecs DescribeInvocations --RegionId <region> --InvokeId <invoke-id> --IncludeOutput true ``` ### Technical Analysis The Skill does not require strict syntactic validation of `service_name`, `app_port`, `region`, or ECS iden ...[truncated 1926 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Treat every value read from `.qwencloud-deploy` as untrusted input. 2. Validate `service_name` against a strict systemd-unit allowlist, such as a conservative character set with an expected `.service` suffix or a fixed set of deployment-generated names. 3. Require `app_port` to parse as an integer and remain within `1` through `65535`. 4. Validate regions, instance IDs, security-group IDs, disk IDs, and EIP IDs against documented Alibaba Cloud formats. 5. Reject values containing whitespace, shell metacharacters, control characters, command substitutions, or unexpected path separators. 6. Avoid interpolating data into a shell program. Pass validated values as positional parameters to a fixed script and quote every use, or deploy a fixed audited diagnostic script whose inputs are passed through a non-shell mechanism. 7. Separate diagnostic permission from recovery permission. A nominally read-only diagnosis should not possess general-purpose `ecs:RunCommand` capability where avoidable. 8. Verify that the selected instance belongs to the stack identified by the deployment state before executing any command. 9. Add negative tests using values containing semicolons, newlines, backticks, `$()`, redirections, quotes, and option-like prefixes. ]]>
