Skip to content
Info disclosure Write-up Beginner

Why Not To Use Dotenv On Flutter

The article shows that when the flutter_dotenv package is used, the .env file is bundled into the built APK as an asset, so anyone with the app package can extract it and read the environment variables. An attacker with access to the APK could recover secrets that were meant to stay private.

Samuel Loureiro Follow

Published on systemweakness.com

Almost all developers have used dotenv at least once. Environment variables really help us to manage projects when we have more than one possible environment and also when we need to put information in a more secure way into the code, not hardcoding it.

Samuel Loureiro, on systemweakness.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the flutter_dotenv package bundles the .env file as a plain asset inside the app package, so its contents ship with the app instead of staying server-side.

Impact

Anyone who obtains the app package could extract and read the environment variables, potentially exposing secrets that put the app and server at risk.

What the attacker needed

Access to the built APK

The fix

Secrets should not be shipped inside the app; keep sensitive values on a server and have the app fetch only what it needs.

How it was found

  1. Add the flutter_dotenv dependency to pubspec.yaml.
  2. Create a .env file at the project root with the variables.
  3. Declare the .env file as an asset in pubspec.yaml.
  4. Import dotenv in main.dart and load the .env file.
  5. Build the app for Android in debug mode.
  6. Open the generated APK, rename it to .rar, extract it, and read the .env file under the flutter_assets folder.

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 write-up has not been written yet. The Original tab links to the source.

Environment variables are settings or secrets kept outside the code, often in a file called .env. On a website these files stay on the server, but in a mobile app everything the app needs is packed into the installable file. This article shows that the .env file gets packed in too, so anyone who downloads the app can unpack it and read the secrets.

What is Info disclosure?

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.

Similar reports

View all

Same bug class and techniques, clearest first.

Information disclosure

The lesson behind this report.

Data the application should keep private (personal data, internal details, other users' records) reaches someone it should not.