DEV Community

Daniel Pertu
Daniel Pertu

Posted on

Our app asks for one permission, and the 23-word sentence under it is a promise the code has to keep

Munchable scans a barcode and tells you whether a product fits your gut. When it does not hold a product yet, you photograph the ingredients panel and it reads the label. So it needs the camera, and asking for the camera on Android and iOS means writing a sentence that the operating system shows to the user, once, at the moment they decide.

Ours is 23 words:

[
  "expo-camera",
  {
    "cameraPermission": "Munchable uses your camera to scan barcodes and photograph ingredient labels. Photos are used only to read the label and are never stored.",
    "microphonePermission": false,
    "recordAudioAndroid": false
  }
]
Enter fullscreen mode Exit fullscreen mode

That is the whole of app.json's camera configuration, and the second sentence is not a description of the feature. It is a promise, in a string, in a config file, which also appears in public prose at munchable.app/privacy and munchable.app/licenses.

This post is about what has to be true in the code for that sentence to stay true, and about the fact that most of what makes it true is not code at all.

One permission, and the two it does not drag in

The Android block asks for exactly one thing:

"permissions": ["android.permission.CAMERA"]
Enter fullscreen mode Exit fullscreen mode

microphonePermission: false and recordAudioAndroid: false are in the plugin config for a reason. A camera library that can record video wants audio, and if you let it, RECORD_AUDIO arrives in the merged manifest without appearing anywhere in your own configuration. Then the store listing says the app can use the microphone, which it cannot, and you have broken a promise nobody wrote down by accident.

An app that cannot record audio should say so to the build system, not just to itself.

What "never stored" has to mean

Four audiences read that sentence: the operating system that displays it, the person deciding whether to tap allow, the privacy notice that repeats it, and, eventually, a regulator who treats it as a representation. None of them care about implementation. All of them are asking the same thing in four different registers: after the label is read, is the picture gone?

There are four places it could fail to be gone. The device, the upload, the server, and the logs.

On the device: the only file that exists is one the OS owns

The shutter is one line, and it takes exactly one option:

const photo = await camRef.current?.takePictureAsync({ quality: 1 });
Enter fullscreen mode Exit fullscreen mode

That writes a JPEG into the OS-managed cache directory and hands back a file:// URI. At that moment there is no other copy, and the second one, made below, lands in the same OS-managed cache. Keeping a reference to it has a type of its own, and the type's comment is the rule rather than a description:

/**
 * A frame straight off the shutter, before any crop or downscale.
 *
 * It is the same OS managed cache file `takePictureAsync` always wrote, kept
 * for a few seconds longer, and it is still never written to the photo library
 * and never logged.
 */
export interface RawPhoto { uri: string; width: number; height: number }
Enter fullscreen mode Exit fullscreen mode

"Kept for a few seconds longer" is the interesting part. The capture flow shoots the whole panel from a distance the lens can actually focus at, then has the user draw a box on the still, and only the box is uploaded. So the full-resolution frame has to survive the crop step, which is the longest any image lives in this app. It is held in one useState, and that state is set back to null at four separate exits: after a successful crop, after a cancel, after a failure, and when the screen resets.

Then the upload copy is made:

const context = ImageManipulator.manipulate(uri);
if (crop) context.crop(crop);
if (Math.max(w, h) > UPLOAD_LONG_EDGE) context.resize(/* 1568 */);
const image = await context.renderAsync();
const saved = await image.saveAsync({ base64: true, compress: 0.75, format: SaveFormat.JPEG });
Enter fullscreen mode Exit fullscreen mode

Crop first, then resize, which is a quality decision: a small selection keeps every sensor pixel it has instead of being shrunk along with the whole frame. But it is also a privacy decision, and I did not design it as one. The bytes that leave the phone are decoded pixels re-encoded into a new JPEG. They are not the file the camera wrote. The only option the shutter call passes is quality, so the app never even asks for the exif field, and nothing downstream of it has a field to drop.

The guarantee that is an absence

Here is the part I would argue is the strongest line in this whole post, and it is not a line.

expo-media-library is not a dependency. The mobile app has 40 runtime dependencies, and not one of them can write to the camera roll. There is no saveToLibraryAsync call to review, no flag to get wrong in a refactor, and no way for a well-meaning change to add "save a copy so the user can retry" without also adding a package, which is a visible diff in package.json that a human reads.

Compare the two ways of keeping this promise:

  • a code path that chooses not to save, which anybody can edit
  • no installed capability to save, which requires a dependency change to break

The second one is auditable by someone who does not read the app at all. That is worth more than a comment.

The same shape covers the logs. A photo URI or a base64 string leaks through logging far more often than through storage, and the audit for that is one grep:

$ grep -rn "console\." apps/mobile/app apps/mobile/src --include="*.ts*" | wc -l
0
Enter fullscreen mode Exit fullscreen mode

Zero, across 104 TypeScript files and about 19,000 lines. No crash reporter either: no Sentry, no analytics SDK, nothing in the app that batches state off the device. There is no sink that could receive an image path, so no review is needed to check whether one does.

In flight and on the server

The upload is a plain POST with the base64 in the body, capped at three images per request and four mebibytes each. The route that receives it is a Next.js route handler with dynamic = 'force-dynamic', and its longest comment is a rule rather than an explanation:

// PRIVACY (hard rule): photos are transient. Images exist in this request's
// memory only - never written, never logged, never persisted; every response
// carries Cache-Control: no-store.
Enter fullscreen mode Exit fullscreen mode

no-store matters more than it looks on a route that returns no image. The response carries the text read off the label, and a cached response is a stored read of a picture of your shopping. The image itself never touches a disk, a bucket or a queue: the request holds it, the OCR processor named in the privacy notice reads it, the extracted words come back, and the buffer goes out of scope with the request. Nothing about the image is written anywhere, and the small amount this route does record carries no account identifier and no product identifier at all.

What would actually break it

Writing this out, the realistic regressions are not sinister. Every one of them is a convenience.

  1. A crash reporter. Drop in any error tracker with default settings and it will collect breadcrumbs, and a breadcrumb containing a file:// path to a cache image is both useful for debugging and a contradiction of the sentence in the manifest.
  2. Retry support. "Keep the shot so a failed upload can resume" is an obviously good feature. It means writing the image somewhere durable, and the promise says never stored.
  3. A share or save button. One dependency away, and the dependency is the only thing standing in the way.

None of the three is wrong as a product decision. All three are a privacy notice change before they are a code change, and the notice has a version number, currently 1.3, that exists so that changing it is a visible event rather than an edit.

The rule I would keep: when a permission string makes a claim, treat it as part of the public interface of the app, and prefer guarantees that are missing capabilities over guarantees that are careful code. Careful code is one refactor from being careless. A package you never installed is not.

If you want to read what this is all in service of, the short version at the top of munchable.app/privacy is four sentences, and the label capture promise is repeated on munchable.app/licenses. The screen itself is in the app, linked from munchable.app, and it is the one you reach by scanning something nobody has added yet.

Top comments (0)