Cube AlgosBlog

· 6 min read · Deutsch

Why did the API key survive obfuscation?

A developer obfuscated their app to hide an API key, but the key still came out in one search. How, if the code was obfuscated? And what does keep a key out of the app? This post follows the key from the source code into the built file, through Dart's --obfuscate option, and out again.

The developer is an illustration, not a real incident. The builds are real: they ran with Dart 3.14.0 and dart compile exe on made-up names, and every output below comes from that run. It is a native Dart build, not a Flutter Android or iOS build; the Flutter docs quoted here cover that case.

A key in the code is a key in the file

App A calls Service A. Service A wants an API key with every request, so the key goes where it is easiest to reach: into the code, as a constant.

const apiKey = 'KEY-A-7Q2M9X4LP8';class ServiceAClient {  String authorizationHeader() => 'Bearer $apiKey';}

When the release build is made, the compiler turns this into machine code and data. The function needs the text Bearer KEY-A-7Q2M9X4LP8 at run time, so that text has to be somewhere in the file. In our run, the plain build was a file of 6,566,008 bytes, and the key was in it.

Anyone with the file can list its text

Finding it takes one standard command. strings is part of GNU Binutils. Its manual describes what it does: for each file, it prints the printable character sequences that are at least 4 characters long. Pipe that into grep, and you have a search:

$ strings app_plain | grep KEY-ABearer KEY-A-7Q2M9X4LP8

No decompiler, no special tool. Anyone who has the file can run this.

Obfuscation renames, it does not hide

So the developer turned on obfuscation. Flutter's docs describe what it does: "Obfuscation hides function and class names in your compiled Dart code, replacing each symbol with another symbol". The same page is plain about its limits:

  • "It is a poor security practice to store secrets in an app."
  • Obfuscating your code "does not encrypt resources nor does it protect against reverse engineering."
  • "It only renames symbols with more obscure names."

The run shows both halves. The docs explain how to save an obfuscation map, a JSON list of original and new names. Ours records the renaming:

ServiceAClient       -> UjauthorizationHeader  -> sG

The names changed. The text the function needs did not, because it is data, not a name. The same search on the obfuscated build:

$ strings app_obf | grep KEY-ABearer KEY-A-7Q2M9X4LP8

The key stayed, letter for letter. One detail from the run is worth knowing: neither ServiceAClient nor authorizationHeader showed up as plain text in strings, even without obfuscation. So the renaming is visible in the map, not in the search. What the search finds is exactly what obfuscation leaves alone.

Version two: the key moves to a server

The fix is to stop shipping the key. In version two, App A no longer calls Service A itself. It asks Server A, a server the developer runs. Server A holds the key and makes the call to Service A on the app's behalf.

const serverA = 'https://server-a.invalid/quote';class ServerAClient {  String requestLine() => 'GET $serverA';}

Same build command, same search:

$ strings app_v2 | grep KEY-A(no output)

Nothing comes out, because there is nothing to find. The key is not hidden better; it is not in the file.

The search, done properly

One trap from the run. Searching for the bare word KEY instead of the key itself is not a clean test: in each of the three builds, strings listed 87 other lines that contain KEY, such as ANY PRIVATE KEY. None of them is App A's key. They are in version two as well. Search for the secret itself, or for a part of it no other text would contain.

Check it yourself

You need the Dart SDK and GNU Binutils. Put the first snippet above in app.dart, add a main that calls authorizationHeader(), and build it twice:

dart compile exe app.dart -o app_plaindart compile exe app.dart -o app_obf \  --extra-gen-snapshot-options=--obfuscate \  --extra-gen-snapshot-options=--save-obfuscation-map=obf_map.jsonstrings app_plain | grep KEY-Astrings app_obf   | grep KEY-A

For a Flutter app, the docs give one command, with the target as a placeholder: flutter build <build-target> --obfuscate --split-debug-info=/<symbols-directory>, and the same --save-obfuscation-map option for the map. Where the Dart code sits inside an Android or iOS package was not part of this run.

What the fix does not do

  • Server A now needs its own guard. The key is off the app, but the server's endpoint is reachable by anyone who finds it. Who may call it, and how often, has to be checked there. This is reasoning about the example, not a sourced claim.
  • Old builds keep the key. Version two only changes new builds. Every copy of the old file still contains the line the search found, so a key that shipped should be treated as known. This, too, is reasoning, not a sourced claim.
  • Obfuscation still renames. The docs say the new names make it difficult for an attacker to reverse engineer an app. The run shows the limit: the names changed, the data the code carries did not.
  • Not every target is covered. According to the docs, obfuscation works only on a release build, and web apps don't support it.
  • This was not a mobile build. The run compiled native Dart for Linux. The Flutter docs carry the warning for Flutter's own targets; the run shows the mechanism, not every platform.

Get the next explainer

Every Cube Algos reel gets a post like this one: the mechanism worked through, with sources and limits. If you would like the next one by email, sign up below. You will first get an email with a confirmation link; you are only on the list after you click it, and every email has a link to unsubscribe.

Sources

  • Flutter docs, "Obfuscate Dart code": what obfuscation renames, the warning about secrets, no encryption of resources, release builds only, no web support, the build flags and the obfuscation map.
  • GNU Binutils documentation, "strings": printable character sequences of at least 4 characters.

All sources last opened on 1 December 2026. The builds ran on 1 December 2026 with Dart 3.14.0 (dart compile exe) and GNU strings 2.44; the file size, the map entries and the 87 other lines are our own counts from that run, not figures from the sources.