T09 · Insecure Skill Coding Practices
Warning
- Location
- dndcharactergenerator.js:4
- Finding
- API Token Can Be Misclassified and Transmitted as Image Prompt Data<![CDATA[ ## Vulnerability Details **File Location**: `dndcharactergenerator.js:4-10` and `dndcharactergenerator.js:80-87` **Vulnerability Type**: Sensitive credential exposure through unsafe command-line argument parsing **Risk Level**: Medium ### Vulnerable Code ```js const args = process.argv.slice(2); const PROMPT = args.find(a => !a.startsWith('--')) || 'DnD fantasy character portrait, detailed armor and weapons, dramatic lighting, epic fantasy art style, highly detailed character design, tabletop RPG hero'; const tokenIndex = args.indexOf('--token'); const tokenFlag = tokenIndex !== -1 ? args[tokenIndex + 1] : null; ``` The resulting value is subsequently inserted into the API request body: ```js const body = { storyId: 'DO_NOT_USE', jobType: 'universal', rawPrompt: [{ type: 'freetext', value: PROMPT, weight: 1 }], width, height, meta: { entrance: 'PICTURE,VERSE' }, context_model_series: '8_image_edit', }; ``` The README explicitly documents a prompt-free invocation at `README.md:29`: ```bash node dndcharactergenerator.js --token YOUR_TOKEN ``` ### Technical Analysis The program identifies the prompt by selecting the first command-line argument that does not begin with `--`. This logic does not distinguish positional arguments from values belonging to named options. For the documented command `node dndcharactergenerator.js --token YOUR_TOKEN`, the argument array contains `--token` followed by `YOUR_TOKEN`. Because the token value does not begin with `--`, it is selected as `PROMPT`. The same value is also correctly selected as `TOKEN`. As a result, the credential is transmitted both as the authentication header and as the image-generation prompt: ```js const HEADERS = { 'x-token': TOKEN, 'x-platform': 'nieta-app/web', 'content-type': 'application/json', }; ``` Prompt data may be handled by additional backend components such as moderation, generation, telemetry, debugging, or prompt-retention systems. This unnecessarily e ...[truncated 1148 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions Use a command-line parser that distinguishes positional arguments from option values, or explicitly consume recognized options before selecting the prompt. A safe manual approach would be: 1. Iterate over the argument array. 2. When `--token`, `--size`, or `--ref` is encountered, consume both the option and its following value. 3. Treat only remaining arguments as positional prompt text. 4. Reject missing option values rather than allowing another flag to become the value. 5. Avoid including authentication values in errors, diagnostic output, request bodies, or generated content. 6. Add automated tests for: - Token-only invocation. - Prompt followed by token. - Token followed by prompt. - Missing token value. - Missing size or reference value. - Option values that begin with `--`. 7. Consider accepting the token through a protected environment variable or secret manager so it does not appear in process listings or shell history. For example, a dedicated argument parser should produce separate fields such as `options.token`, `options.size`, `options.ref`, and `positionals`, with only `positionals` used to construct `rawPrompt`. ]]>
