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
- Remove .env from the app assets (pubspec.yaml assets, Xcode Copy Bundle Resources, android assets).
- Rotate every key that was in the file: assume it is already copied.
- Move calls that need secret keys behind your own backend (an edge function or API route).
- 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 appReferences
Related checks (M1)
- Secret returned in an API response
- App code calls Supabase admin APIs, so the service-role key ships in the app
- Hardcoded secret in the app
- Credential passed in a URL
- Hardcoded secret sent on the wire
- Secret written in eas.json
- Secret .env file is not ignored by git
- Secret in the Expo app config `extra`, which ships inside the app