Isaac Emmanuel

2026.11.23

Trusted server context does not belong on a mobile client

A mobile application cannot safely hold a gateway credential or assert its own user scope. Let the backend own identity translation and minimise what crosses the boundary.

A mobile application can contain a string called a secret. That does not make the string secret.

The application package can be inspected. Traffic can be proxied. Runtime state can be instrumented. A determined user controls the device on which the code runs.

This becomes especially dangerous when a backend integration expects two things from a trusted caller:

  • A server credential proving which system is calling.
  • A user or account context saying whose data should be accessed.

If both are placed in the mobile client, the client can impersonate the trusted system and may be able to change the asserted subject.

Trust the session, not a client-supplied identity header

The safe path starts with the application's existing authenticated session.

text
mobile app -> product backend or BFF -> internal service

The mobile app presents the token intended for the product backend. The backend verifies it, resolves the authorised user and account context, and then calls the internal service using its own server credential.

The internal identity context is derived from the authenticated session. It is not accepted as a free-form value from the mobile request.

This is an important difference:

text
unsafe: client says "I am account X" safe: backend session resolves to account X

The BFF is a security boundary

A backend-for-frontend is sometimes described as an API convenience layer. In this design it has a more important job.

It owns:

  • Session authentication.
  • Product-level authorisation.
  • User and account selection.
  • Consent checks or consent initiation.
  • Server-to-server credentials.
  • Response minimisation for the mobile experience.
  • Stable client-facing error semantics.

The internal service does not need to understand every mobile navigation detail. The mobile client does not need access to internal trust material.

Minimise identity propagation

Passing an entire customer profile between services increases the number of places private data can leak or become stale.

The internal service often needs a smaller context:

  • A stable, scoped subject identifier.
  • The authorised account type or tenant context.
  • The purpose or consent scope.
  • A correlation identifier for the request.

In some systems, the internal service can derive a one-way subject key from the transient external identifier and avoid storing the raw profile identifier at all.

The derivation must include the dimensions that separate security contexts. If personal and business accounts share the same profile identifier, deriving only from that identifier can collapse two contexts into one internal subject.

Identity design is not finished when the value is unique. It must be unique within the boundaries the product promises to keep separate.

Logout has an architecture consequence

The server can enforce the correct subject and the mobile interface can still display stale data from the previous session.

On logout, account switch, or tenant switch, the client should clear cached protected screens and request fresh data through the new authenticated context.

This applies to query caches, local databases, navigation state, downloaded reports, and background requests that may complete after the session changes.

The response handler should verify that the result still belongs to the active session before displaying it.

Keep consent current

The BFF should not turn a historical consent into permanent access.

For a protected refresh or analysis, the path should verify current consent before reading or returning the data. Revocation should prevent future refreshes and may also affect whether cached results can be disclosed.

The client can guide the user through the approved consent journey. It should not manufacture the internal consent signal or call a protected service directly.

Document two different contracts

The mobile team needs the client-facing contract: routes, request bodies, response states, errors, loading behaviour, and account-switch rules.

The service team needs the server-to-server contract: authentication, scoped identity, consent semantics, timeouts, retries, and data minimisation.

Exposing the internal OpenAPI document directly to the mobile application can encourage dependence on internal headers and fields. A deliberate BFF contract keeps the security boundary visible.

Test the boundary negatively

Happy-path integration tests are not enough. I want to verify that:

  • Missing server credentials fail.
  • Invalid credentials fail.
  • A client cannot override the subject resolved from its session.
  • Personal and business contexts remain isolated.
  • Revoked consent blocks another protected refresh.
  • Account switching clears or invalidates cached results.
  • Internal credentials never appear in mobile bundles, logs, or analytics.

The goal is not to hide the name of an internal header. The goal is to make possession of the mobile application insufficient to cross the trusted boundary.

A mobile client is a capable user interface running in an untrusted environment. Architecture should respect both halves of that sentence.