T09 · Insecure Skill Coding Practices
Note
- Location
- scripts/test-scrpt.js:1
- Finding
- Hard-Coded and Ineffective API Credential Handling<![CDATA[ ## Vulnerability Details **File Location**: `scripts/test-scrpt.js`, lines 1-9 and 59-64 **Vulnerability Type**: Hard-coded credential and ineffective authentication **Risk Level**: Low ### Vulnerable Code ```javascript const API_KEY = 'abc'; const BASE = "http://localhost:4000/v1"; if (!API_KEY) { console.error("Missing"); process.exit(1); } ``` The subsequent request does not use `API_KEY`: ```javascript const res = await fetch(url, { method, headers: { "Content-Type": "application/json", }, ...(body ? { body } : {}), }); ``` ### Technical Analysis The script embeds a credential-like value directly in source code rather than reading the `TEST_API_KEY` environment variable declared in `SKILL.md`. The startup check only verifies that the hard-coded string is nonempty and therefore cannot detect a missing runtime credential. Furthermore, `API_KEY` is never included in the outbound request. Consequently, the script's credential check provides no authentication protection and creates a false impression that API authentication is enforced. The current value, `abc`, appears to be a placeholder; there is no evidence that it is a valid secret. Nevertheless, the implementation pattern is unsafe because replacing it with a valid key would expose that key to anyone with source-code access. ### Attack Path 1. An operator replaces the placeholder with a valid API credential while preserving the existing implementation. 2. The credential becomes part of the source file and may be exposed through package distribution, source control, backups, logs, or filesystem access. 3. A party that obtains the source can recover and reuse the credential against services where it is valid. 4. Independently, because the script never sends the key, requests are made without application-layer authentication. If the local endpoint accepts unauthenticated requests, callers can perform the supported payment-link operation without the intended credential c ...[truncated 495 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove the hard-coded value and load the credential from the declared environment variable: ```javascript const API_KEY = process.env.TEST_API_KEY; ``` - Fail closed when the environment variable is absent or empty. - Send the credential only through the authorization mechanism documented by the API, such as an `Authorization` header. - Never print the key or include it in error messages. - Keep real credentials out of source control and distributed Skill packages. - Use short-lived, sandbox-only credentials with narrowly scoped permissions. - Add automated secret scanning and a test verifying that authenticated requests contain the required authorization header. ]]>
