T09 · Insecure Skill Coding Practices
- Location
references/create-wallet-pin.md:201- Finding
Wallet credentials persisted in browser localStorage in the PIN workflow
- Content
View full analysis
{ if (!userId) return; const response = await fetch(`${apiBaseUrl}/api/wallet/get-token`, { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ userId }), }); const data = await response.json(); setCredentials({ userToken: data.userToken, encryptionKey: data.encryptionKey }); localStorage.setItem("userToken", data.userToken); localStorage.setItem("encryptionKey", data.encryptionKey); }; ``` ### Technical Analysis The example persists both `userToken` and `encryptionKey` in `localStorage`. Any JavaScript running under the application's origin can read these values. This includes injected scripts resulting from cross-site scripting, compromised third-party frontend packages, malicious analytics scripts, and potentially hostile browser extensions. These credentials are subsequently passed to `sdk.setAuthentication()` and are therefore security-sensitive wallet authorization material. Although `SKILL.md` warns that `localStorage` should not be used in production, the reference presents this behavior as part of a directly reusable implementation. ### Attack Path 1. A user authenticates through the PIN workflow. 2. The application saves the Circle `userToken` and `encryptionKey` in `localStorage`. 3. An attacker obtains same-origin script execution through an XSS vulnerability or compromised frontend dependency. 4. The attacker reads: ```js localStorage.getItem("userToken"); localStorage.getItem("encryptionKey"); ``` 5. The attacker exfiltrates the credentials and attempts to initialize the wallet SDK or execute available wallet challenges before the credentials expire. ### Impact Assessment Successful exploitation exp ...[truncated 377 chars]- Remediation
View remediation
