secret_in_shipped_file
Reports a secret in a file that ships with the app: the pubspec or a declared asset. Keep the secret on your backend, or out of the assets.
- Kind
- project-file check
- Tier
- advisory
- Host
- command-line program only (
assay project-files) - Lowest preset
- every preset (on unless switched off)
- Fix
- none
- Security class
- CWE-798, CWE-540 · mobile risk M1 (improper credential usage) · severity 7.8
What it reports
Section titled “What it reports”A secret in pubspec.yaml, or in any file Flutter’s tool bundles from the flutter: assets: list, dot files of a declared directory included (assets/config/.env). Four kinds:
- A credential whose shape is secret by itself, in any text file: a private key in PEM format, a GitHub, Stripe secret or OpenAI token, a Slack webhook URL, and the other shapes of
hard_coded_credential. - A secret-like value under a credential name, in a
.env,.propertiesor.inifile (API_SECRET=…), or in a JSON or YAML file, the pubspec included. - The password in a URL, in any text file:
https://reader:<password>@pub.example.org. - A key store, as a whole: a declared
.jks,.keystore,.p12or.pfxfile, and a.pemor.keyfile that holds a private key.
It does not report keys that are public by design, such as Google’s AIza… (the API key of a Firebase app) or Stripe’s publishable pk_live_…, nor the labels of a translation file, such as "password": "Şifre".
The message names the kind of secret and the name it is bound to, never the secret: “This is a secret bound to ‘API_SECRET’ in a file the app ships: whoever has the app has it.”
Every declared asset is in every copy of the app. An APK or an IPA unpacks in a minute, and its files read as they were written: a key in a shipped .env, a key-store password in a properties file or a Google service account in a JSON asset is no secret once the app is out, and you cannot change it without a release. The pubspec is in version control and, for a package, on pub.dev.
The same secret in Dart source is blocked by hard_coded_credential. Here it is advisory, as every project-file check is.
Example
Section titled “Example”- .env under flutter: assets:API_URL=https://api.shop.devAPI_SECRET=… # a real secretflutter build apk --dart-define-from-file=secrets.json # secrets.json is not declared and not committedIn the pubspec, give the secret to the tool that reads it from outside version control: dart pub token add <url> for a package repository, or the command line or the environment for the signing password of msix.
Configuration
Section titled “Configuration”Under assay.project_files of the project’s root analysis_options.yaml:
| Key | Default | Effect |
|---|---|---|
enabled |
true |
false (or the short form secret_in_shipped_file: false) switches the check off. |
exclude |
[] |
Path globs, from the project root, where the check places no result. |
assay: project_files: secret_in_shipped_file: exclude: ["assets/fixtures/**"]How to run it
Section titled “How to run it”assay project-filesruns it with the other project-file checks.assay project-files secret_in_shipped_fileruns it alone.- The gate and the baseline commands run it in every judgement (see In the gate).
Keeping a result
Section titled “Keeping a result”No suppression comment applies: a JSON file has no comments, and a key store no lines. Keep a value that is public by design, has no shape the check knows and sits under a credential name in the baseline. A key store is reported whatever it holds: keep a trust store, one of certificates alone, in the baseline as well. Put a file of test data in the check’s exclude.
Details
Section titled “Details”All cases
The four kinds in full
Section titled “The four kinds in full”-
A credential whose shape is secret by itself, anywhere in any text file. These are the shapes of
hard_coded_credential: a private key in PEM format, GitHub, GitLab, Slack, Stripe secret, Google OAuth, Firebase Cloud Messaging server, OpenAI, Anthropic, SendGrid, npm, PyPI, Shopify, Square, Telegram and Hugging Face tokens, Slack and Discord webhook URLs, and a JSON web token that bears Supabase’s service role. In a JSON or YAML file the values are read too, so a private key with JSON escapes is found at its value:"private_key": "-----BEGIN PRIVATE KEY-----\n…", the key of a Google service account. -
A secret-like value under a credential name, in:
- the lines of a
.envfile (.env,.env.production,prod.env), a.propertiesfile or an.inifile:KEY=value,export KEY=value,key = 'value',key: value. A line that starts with#,;or!is a comment, and one in brackets is a section name. An unquoted value ends before a#or;that follows white space. - the values of a JSON file (
.json,.arb) or a YAML file (.yaml,.yml), the pubspec included:msix_config: certificate_password: …is reported. Only text counts: a number, a list or a map under a credential name does not. A package name underdependencies,dev_dependenciesordependency_overridesbinds nothing:flutter_otp: 0.3.20-betais a version.
Credential names and secret-like values are those of
hard_coded_credential. - the lines of a
-
The password in a URL, in any text file:
https://reader:<password>@pub.example.org, also the address of a hosted dependency in the pubspec. The password has to look like a secret. A value filled in later (${PUB_TOKEN}), the user name again or a placeholder does not, and an address with a user and no password (a Sentry DSN) holds none. -
A key store, as a whole: a declared
.jks,.keystore,.p12or.pfxfile, whatever it holds, and a.pemor.keyfile that holds a private key. A.pemfile of certificates alone, such as one for certificate pinning, is not reported.
A secret found by its shape that is also under a credential name is one result, of its shape.
What it does not report
Section titled “What it does not report”- keys that are public by design, under any name: Google’s
AIza…(the API key of a Firebase app), Stripe’s publishablepk_live_…/pk_test_…, RevenueCat’s public SDK keysappl_…/goog_…/amzn_…/strp_…, Mapbox’s publicpk.…tokens, PostHog’s project tokensphc_…, a certificate pin (sha256/and the base64 digest of its public key), and every other JSON web token, such as Supabase’s anonymous key. Also, under names that say what they are, as inhard_coded_credential: a pin aftercertificate,cert,ssl,tls,spkiorpublic key("certificatePin"), Mixpanel’s project token (MIXPANEL_TOKEN) and a search-only API key (ALGOLIA_SEARCH_API_KEY). - the labels of a translation file:
"password": "Şifre","forgotPassword": "Şifremi unuttum","password": "password", a one-word label in a natural language ("confirmPassword": "ŞifreyiDoğrulayın","Passwortbestätigung"), or a key name in camelCase ("accessToken": "userAccessTokenKey"). - the scheme of a URL in the pubspec. An
http://address belongs to the SDK lintsecure_pubspec_urls. Anhttp://user:<password>@address is reported by both: two defects.
What you see
Section titled “What you see”The result stands at the secret: the value with its quotes, the password of an address, or the text of a shape. A key store or a key file is a result of the whole file, at line 1, column 1, which the console shows with — in the place of its line.
The message names the kind of secret and the name it is bound to, never the secret:
- “This is a secret bound to ‘API_SECRET’ in a file the app ships: whoever has the app has it.”
- “This is a password in the address of a URL, written into pubspec.yaml: whoever can read the project has it.”
- “This is a key store, shipped as an asset: whoever has the app has the keys in it.”
Neither the report nor the baseline holds the secret. A result’s fingerprint is a digest of its place (the keys down to the value, or the key of its line) and of the secret’s text, never of the rest of its line (see Project-file checks). So a comma added after the last key of a JSON file, or a comment after a value in a .env, keeps the result the same. A new value, or the value under other keys, is a new result.
What it reads
Section titled “What it reads”The package at the project root, as the asset checks read it (see Project-file checks):
- its
pubspec.yaml, which is in version control and in a published package; - every declared asset, each base file and each resolution variant, as
unused_assetsreads theflutter: assets:list. An entry written as a map is read by itspath, whatever itsflavors:orplatforms:say: a secret that one build ships is shipped. - the dot files of a declared directory, such as
assets/config/.env. Flutter’s tool bundles every file directly in a declared directory, dot files included. The asset checks leave them out, so this check lists them itself. A.envthatflutter_dotenvloads is declared (- .env), so it is read.
A subdirectory of a declared directory, or a directory that is not declared, ships nothing and is not read. A .env that only a code generator reads at build time (envied with assets/env/.env, not declared) is not a shipped file.
Files it does not judge. Each but the first two is listed under “Not checked”, with its reason:
- Images and fonts, by extension (
png,jpg,jpeg,gif,webp,bmp,wbmp,ttf,otf), are not read. - A binary file, one with a NUL byte in its first 8 KB or that is not UTF-8 text, is read and gives nothing: an audio file, a model, a database.
- A text file larger than 1 MB: “
assets/data.jsonis larger than 1 MB, so no check judged it.” Only its first 8 KB are read, to tell text from binary; a binary file of that size is silent. - A JSON or YAML file that cannot be parsed (a key written twice, an unclosed bracket), shapes included: “
assets/strings.jsonis not valid JSON, so no check judged it.” A file is parsed only where its text could hold what only its values show: a credential word, a backslash that may start an escape, or a Telegram bot token right after a colon. Any other file is judged by its text alone, whatever it holds. - A file that is not a regular file, such as a named pipe or a device, also through a link. It is never opened, since reading it could wait for ever: “
assets/pipe.envis no regular file, such as a named pipe or a device, so no check judged it.” - Every shipped file, where the pubspec is not valid YAML or holds no YAML map: “
pubspec.yamlis not valid YAML, so it is not known which files the app ships: no check judged them, and the baseline keeps the entries of secret_in_shipped_file.” The gate andbaseline updatethen keep every entry of the check, so a secret in the baseline is not handed over as new once the pubspec is fixed.
In the gate
Section titled “In the gate”On a change, the gate reads only the shipped files the change touched, or every one if the change touched the pubspec. Where the check is switched off, neither the mark nor the gate lists the shipped files or asks git which of them it ignores.
Security class
Section titled “Security class”In SARIF, the check’s descriptor carries the tags security, external/cwe/cwe-798, external/cwe/cwe-540 and external/owasp-mobile-2024/m1, and the security-severity 7.8. No other report changes. See Security.