T09 · Insecure Skill Coding Practices
Error
- Location
- assets/auth-server.js:821
- Finding
- Authentication Token Disclosure Through an Arbitrary Redirect<![CDATA[ ## Vulnerability Details **File Location**: `assets/auth-server.js`, lines 821–850 **Vulnerability Type**: Unvalidated redirect with session-token disclosure **Risk Level**: Critical ### Vulnerable Code ```javascript // ---- If already authenticated: auto-redirect to returnUrl with token ---- (function() { const sessionToken = ${session ? JSON.stringify(session.token) : 'null'}; if (sessionToken) { const params = new URLSearchParams(window.location.search); const returnUrl = params.get('returnUrl'); if (returnUrl) { const dest = new URL(decodeURIComponent(returnUrl)); dest.searchParams.set('max_auth_token', sessionToken); window.location.href = dest.toString(); return; } } })(); // ---- Post-login: set cookie + redirect ---- function handleLoginSuccess(token) { const params = new URLSearchParams(window.location.search); const returnUrl = params.get('returnUrl'); if (returnUrl) { // Pass token via query param so the target proxy can set the cookie server-side const dest = new URL(decodeURIComponent(returnUrl)); dest.searchParams.set('max_auth_token', token); window.location.href = dest.toString(); } else { setTimeout(() => location.reload(), 500); } } ``` ### Technical Analysis The `returnUrl` query parameter is controlled by the requester. The application neither validates its origin nor restricts it to approved callback paths before appending a valid authentication token. This occurs both when the user already has a session and immediately after successful authentication. Consequently, a URL supplied by an attacker can cause the browser to transmit the token to an arbitrary external host. Placing the token in a query string also exposes it to destination-server access logs, browser history, monitoring infrastructure, reverse proxies, and potentially referrer data. The network request flagged at line 860 posts the password to the relative same-origin `/auth/login` endpoi ...[truncated 1285 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Do not transmit session or bearer tokens in URLs. - Remove support for arbitrary `returnUrl` destinations. - Configure an allowlist containing exact HTTPS origins and callback paths; reject every other destination. - Replace direct token forwarding with a cryptographically random, short-lived, single-use authorization code. - Bind the code to the intended callback URI, requesting session, and expiration time. - Exchange the code for a session through a server-to-server request. - Set the resulting session in a `Secure`, `HttpOnly`, and appropriate `SameSite` cookie. - Add tests covering external origins, protocol-relative URLs, encoded URLs, user-info URL tricks, and alternate ports. - Revoke existing tokens after deploying the fix because previously issued tokens may have leaked. ]]>
