high · M1 · MASVS-STORAGE-1 · PTKD-LEFTOVER-ENV-FILE

    A .env file ships inside the app

    An environment file (.env) is packaged into the app. Everything in it, including API keys and backend URLs meant to stay on a server, can be read by anyone who downloads the app.

    How it is exploited

    A Flutter app lists .env under assets so flutter_dotenv can read it. The file is copied into the APK at assets/flutter_assets/.env. An attacker unzips the APK and reads OPENAI_API_KEY and SUPABASE_SERVICE_ROLE_KEY in plain text.

    Why it matters

    Keys meant for servers are public: attackers bill your AI account, read or wipe your database, or send email as you.

    How to fix it

    1. Remove .env from the app assets (pubspec.yaml assets, Xcode Copy Bundle Resources, android assets).
    2. Rotate every key that was in the file: assume it is already copied.
    3. Move calls that need secret keys behind your own backend (an edge function or API route).
    4. Pass only public, restricted keys to the app (for example a Supabase anon key with RLS on).

    Does your app have this?

    PTKD checks your build or your source project for PTKD-LEFTOVER-ENV-FILE and every other check in this knowledge base.

    Scan your app

    References

    Related checks (M1)