T09 · Insecure Skill Coding Practices
Error
- Location
- references/embedding.md:29
- Finding
- Browser-Side Exposure of Trugen API Credentials<![CDATA[ ## Vulnerability Details **File Location**: `references/embedding.md`, lines 29-44 **Vulnerability Type**: Client-side credential exposure **Risk Level**: High ```html > **⚠️ Security Note**: The examples below follow the official Trugen docs pattern. In production, consider injecting the `apiKey` value server-side rather than hardcoding it in client-facing HTML, as it will be visible to anyone inspecting the page. **1. Configure the widget before the script tag:** ```html <script> window.TrugenWidget = { agentName: "Your agent name", agentId: "your-agent-id", apiKey: "x-api-key", heading: "Main heading of widget", subHeading: "Sub heading of widget", logoUrl: "https://yourdomain.com/logo.svg", displayAvatarUrl: "https://yourdomain.com/avatar.png" }; </script> <script src="https://dist.trugen.ai/trugen-chat.js"></script> ``` ``` ### Technical Analysis The example places an API credential in a global browser-side JavaScript object. If a developer replaces the placeholder with a real management key, the credential becomes accessible through page source, developer tools, browser extensions, injected scripts, and any third-party script executing in the page context. The remotely hosted `trugen-chat.js` script can also read the global object. Rendering the key into HTML through server-side template injection does not protect it because the resulting credential is still delivered to the browser. This contradicts the safer guidance in `SKILL.md`, which states that client-side embeds should use a server-side proxy. ### Attack Path 1. A developer copies the widget example and replaces `x-api-key` with a working Trugen API key. 2. The application delivers the key in client-facing HTML. 3. An attacker opens developer tools, views the source, reads `window.TrugenWidget`, or uses a script running in the same origin. 4. The attacker extracts the API key. 5. The attacker sends authenticated requests to Trugen API endpoints using ...[truncated 831 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Remove the `apiKey` property from all browser-side examples. - Do not inject long-lived API keys into server-rendered HTML; this still exposes them to the browser. - Route privileged Trugen API operations through an authenticated backend service. - If direct browser access is necessary, use narrowly scoped, short-lived session tokens created by the backend. - Restrict each token to the required agent and operations, with a short expiration and revocation support. - Apply Content Security Policy controls and minimize third-party scripts, while recognizing that these controls do not make browser-delivered secrets safe. - Document key rotation procedures and immediately rotate any key previously embedded in client-facing content. ]]>
