How do I make sure only my own front end can call my API, when the page has no login?
I pay per request for a third-party service. My site calls it from a public page with no authentication, and I proxy the request through my own backend so the paid key is never in the browser.
I have also restricted the endpoint to my own origin. That stops it being called from another website in a browser.
What it does not stop is somebody opening the network tab, copying the request and replaying it from a script. Everything I add seems to be visible to the client and therefore copyable. Is there a way to actually solve this, or am I asking for something impossible?
@threat_model_thea · 2h ago
You are asking for something impossible, and it is worth being precise about why, because the precise version tells you what to do instead.
Anything your client possesses, the user possesses. A secret in JavaScript is readable. A signed token issued to an anonymous visitor can be requested by anyone. Even in a compiled mobile app the same holds — it is harder, not different. There is no arrangement in which an anonymous client proves it is "the real client", because there is nothing about it that an attacker cannot also have.
The origin restriction you added is worth understanding correctly too: it is a browser policy. It stops another website's page from reading your responses. It does nothing about a script, a command line tool, or anything that is not a browser obeying rules voluntarily.
So drop the goal of authentication and pick up the goal of cost control. That one is achievable.
Reply
Report