T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/create_address.py:54
- Finding
- Administrative credentials can be transmitted to an arbitrary network endpoint<![CDATA[ ## Vulnerability Details **File Location**: `scripts/create_address.py:23`, `scripts/create_address.py:54-56`, `scripts/create_address.py:212-237`, and `scripts/create_address.py:256-259` **Vulnerability Type**: Unrestricted credential destination and sensitive-header disclosure **Risk Level**: High ### Vulnerable Code ```python ENV_API_URL = "CLOUDFLARE_MAIL_API_URL" ``` ```python parser.add_argument( "--api-url", default=os.getenv(ENV_API_URL, DEFAULT_API_URL), help=f"Admin API URL. Defaults to {DEFAULT_API_URL}.", ) ``` ```python def build_headers(args: argparse.Namespace) -> tuple[Optional[dict], Optional[str]]: admin_auth = args.admin_auth or os.getenv(ENV_ADMIN_AUTH) if not admin_auth: return None, f"missing admin credential: provide --admin-auth or {ENV_ADMIN_AUTH}" headers = { "Content-Type": "application/json", "x-admin-auth": admin_auth, } bearer_token = args.bearer_token or os.getenv(ENV_BEARER_TOKEN) if bearer_token: token = bearer_token.strip() headers["Authorization"] = token if token.lower().startswith("bearer ") else f"Bearer {token}" fingerprint = args.fingerprint or os.getenv(ENV_FINGERPRINT) if fingerprint: headers["x-fingerprint"] = fingerprint lang = args.lang or os.getenv(ENV_LANG) if lang: headers["x-lang"] = lang user_token = args.user_token or os.getenv(ENV_USER_TOKEN) if user_token: headers["x-user-token"] = user_token return headers, None ``` ```python req = request.Request(api_url, data=body, headers=headers, method="POST") try: with request.urlopen(req, timeout=timeout) as response: ``` ### Technical Analysis The script permits the destination URL to be controlled through either the `--api-url` command-line argument or the `CLOUDFLARE_MAIL_API_URL` environment variable. It does not validate the URL scheme, hostname, port, path, or final redirect destination before attaching sensit ...[truncated 2147 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions 1. Remove `--api-url` and `CLOUDFLARE_MAIL_API_URL` if support for alternate servers is not operationally required. 2. If endpoint configuration is necessary, parse the URL and enforce an explicit allowlist: - Scheme must be `https` - Hostname must be `mail-api.suilong.online` - Port must be the expected HTTPS port - Path must be `/admin/new_address` - User information and fragments must be rejected 3. Disable automatic redirects for authenticated requests, or validate every redirect destination before forwarding any sensitive header. 4. Never forward authentication headers across origins. 5. Separate optional credentials so that only headers explicitly required by the selected trusted endpoint are transmitted. 6. Display the validated destination and require explicit confirmation when any nondefault endpoint is used. 7. Add automated tests proving that HTTP URLs, unexpected domains, deceptive subdomains, alternate ports, and cross-origin redirects are rejected. ]]>
