T09 · Insecure Skill Coding Practices
- Location
scripts/route_whatsapp.sh:4- Finding
Arbitrary Local File Upload to a Configurable Destination
- Content
View full analysis
Vulnerability Details
File Location:
scripts/route_whatsapp.sh, lines 4–47
Vulnerability Type: Unrestricted local file upload and potential data exfiltration
Risk Level: HighVulnerable Code
bash BASE_URL="${BASE_URL:-http://localhost:8080}"bash decode) if [[ -z "$ARG" ]]; then echo '{"error":"missing image path argument for decode mode"}' exit 2 fi if [[ ! -f "$ARG" ]]; then printf '{"error":"image file not found: %s"}\n' "$ARG" exit 2 fi curl --silent --show-error --max-time "$TIMEOUT" \ -X POST "$BASE_URL/decode-qr" \ -F "image=@$ARG" ;;Technical Analysis
Decode mode accepts an arbitrary local path through
ARG. The only validation is[[ -f "$ARG" ]], which confirms that the supplied path refers to a regular file. The script does not require the file to reside in an approved WhatsApp attachment directory, validate that it is an image, enforce an allowed file extension or MIME type, restrict symbolic-link resolution, or impose a file-size limit.Curl's multipart syntax,
-F "image=@$ARG", causes curl to read the referenced local file and transmit its contents. Therefore, any readable regular file available to the script's operating-system account can be submitted instead of a QR image.The upload destination is also configurable through the inherited
BASE_URLenvironment variable. Although the default destination is loopback-only, a caller capable of controlling the execution environment can redirect the upload to an external HTTP endpoint. The combination creates a local-file disclosure and potential data-exfiltration primitive.Attack Path
- An attacker influences the decode argument directly or induces the agent to treat an attacker-selected local path as an image attachment.
- The attacker supplies a readable sensitive path, for example an application configuration or credential file.
- The
-fche ...[truncated 1243 chars]
- Remediation
View remediation
Remediation Suggestions
- Resolve the supplied path to its canonical absolute path and require it to remain inside a dedicated, trusted WhatsApp attachment directory.
- Reject symbolic links or verify the canonical target after link resolution to prevent path-boundary bypasses.
- Validate the file using an allowlist of supported image MIME types and verify its actual file signature rather than relying only on its extension.
- Enforce conservative file-size and image-dimension limits before upload.
- Do not inherit an unrestricted
BASE_URL. Prefer a fixed loopback endpoint, or parse and allowlist the exact scheme, host, port, and route. - Reject credentials, query strings, redirects, non-HTTP schemes, and non-loopback destinations. Consider using curl's
--proto,--proto-redir, and--max-redirs 0restrictions. - Run the script under a dedicated least-privileged account that cannot read application secrets or unrelated user files.
- Pass attachment metadata through a trusted interface rather than accepting an arbitrary filesystem path from user-controlled content.
