T09 · Insecure Skill Coding Practices
Error
- Location
- scripts/api_client.js:6
- Finding
- Credentials and Bearer Tokens Can Be Sent to an Arbitrary or Plaintext Backend## Vulnerability Details **File Location**: `scripts/api_client.js:6-7, 51-52, 65` **Vulnerability Type**: Unrestricted backend override and insecure transport of authentication material **Risk Level**: High ### Vulnerable Code ```javascript constructor() { this.baseUrl = process.env.BACKEND_URL || 'https://javatoarktsapi.uctoo.com'; this.accessToken = null; } ``` ```javascript const isHttps = fullUrl.startsWith('https://'); const client = isHttps ? https : http; ``` ```javascript if (requireAuth && this.isAuthenticated()) { options.headers['Authorization'] = `Bearer ${this.accessToken}`; } ``` ### Technical Analysis The client accepts `BACKEND_URL` directly from the process environment without validating its scheme, hostname, port, or origin. It explicitly supports both HTTPS and plaintext HTTP. The `login()` method sends the supplied username and password to this configured backend, and authenticated API calls automatically attach the stored bearer token. Environment configuration is a legitimate deployment mechanism, but authentication material should not be forwarded to an unrestricted origin. Supporting plaintext HTTP also exposes credentials and tokens to interception and modification by network-adjacent attackers. This behavior exceeds minimum privilege because the declared Skill only needs access to the UCTOO backend, not arbitrary network destinations. ### Attack Path 1. An attacker influences the runtime environment, deployment configuration, wrapper script, or service definition. 2. The attacker sets `BACKEND_URL` to an attacker-controlled URL or a plaintext HTTP endpoint. 3. A user invokes `login(username, password)`. 4. The client sends the supplied credentials to the configured destination. 5. If the destination returns a response containing `data.access_token`, the client stores that value. 6. Subsequent authenticated calls automatically send the bearer token ...[truncated 524 chars]
- Remediation
- ## Remediation Suggestions 1. Require `https:` for every non-development backend and reject plaintext HTTP before sending a request. 2. Validate the parsed URL against an explicit allowlist of approved UCTOO hostnames, ports, and schemes. 3. Reject URLs containing embedded credentials, fragments, or unexpected ports. 4. Bind stored tokens to the exact origin that issued them. Never forward a token after an origin change. 5. Separate development support for localhost from production behavior and require an explicit insecure-development flag. 6. Avoid following cross-origin redirects for requests containing credentials or authorization headers. 7. Add tests proving that HTTP, unapproved hosts, malformed URLs, and origin changes are rejected.
