Network Security Interview Questions

SECURITY › Security

How do you make network communication secure in an Android app?

What a strong answer covers: Use HTTPS everywhere; cleartext HTTP is blocked by default since Android 9. Configure a Network Security Config to disallow cleartext and optionally pin certificates. Never disable certificate validation (no trust-all TrustManagers). Don't put secrets in requests that can be extracted, authenticate with short-lived tokens, and validate everything on the server.

What is certificate pinning, and what are the risks of using it?

What a strong answer covers: Pinning means the app only trusts specific certificates or public keys for your domain, so a compromised certificate authority or a user-installed proxy certificate can't intercept traffic. Risks: if the server's certificate or key changes and the app isn't updated, every user loses connectivity. Pin public keys, include backup pins, set an expiry, have a rollout plan, and consider whether the threat model needs it.

What is a Network Security Config, and what can you set in it?

What a strong answer covers: An XML file referenced from the manifest that configures network security without code: whether cleartext is allowed (globally or per domain), which certificate authorities to trust (system, user-added, or bundled custom CAs), certificate pins with expiry dates, and debug-only overrides, such as trusting user CAs in debug builds for proxy tools like Charles.

Why shouldn't API keys be embedded in an app, and what can you do instead?

What a strong answer covers: Anything in the APK can be extracted by decompiling or by watching traffic, however you obfuscate it. For keys that grant access to paid or sensitive services, route requests through your own backend which holds the key, restrict client-side keys (by package name and SHA-1 for Google keys), use per-user authentication tokens, and use Play Integrity or App Check to verify requests come from your genuine app.

How would you design the security of an app's API communication from the threat model up?

What a strong answer covers: Identify what you're protecting (user data, payments, accounts) and from whom (network attackers, malicious users, modified clients). Then: TLS with sensible pinning if warranted, short-lived access tokens with refresh rotation, server-side authorisation on every request (never trust the client), rate limiting, Play Integrity or App Check for client attestation, avoiding sensitive data in URLs and logs, and monitoring for abuse. Assume the client can be fully controlled by an attacker.

Back to Network Security