How do I make sure my API is only called by my own app, and not by someone with a copy of the requests?
Public API behind a mobile app and a web front end. I want to ensure only my clients can call it.
So far I have tried: a secret key compiled into the app, a custom header the server checks, and checking the user-agent. Someone on my team pointed out that all three are visible to anyone who looks at the traffic, which I now understand is true.
What I would like to know:
- Is there a way to actually do this, or is the goal itself wrong?
- If a secret cannot live in a client, what is the point of API keys at all?
- What should I be doing instead to stop abuse, which is the real thing I care about?
@chargeback_charu · 5h ago
Question 2 is a good one because API keys are widely misunderstood.
A key in a server-to-server context is a real secret: it lives on a machine you control, and nobody else sees it. That is the case they were designed for and there they work.
A key in a client is not a secret and was never treated as one by anyone who thought about it. What it is instead is an identifier: it tells you which application the traffic came from, so you can meter it, revoke it, and see when one integration starts behaving oddly. That is genuinely useful — it just is not authentication.
The failure comes from treating the second one as though it were the first. A public key with a rate limit attached is fine. A public key that grants privileged access is a credential you have published.
Reply
Report