Home > Net >  How to restrict the access to backend API to be only accessed by the react app?
How to restrict the access to backend API to be only accessed by the react app?

Time:01-28

I am creating a public facing SPA web application using React js. The backend for this application are the endpoints available under Azure APIM. I would like to restrict the access to these APIM endpoints in a way that they are only accessible from my react app. As the react app will be rendered in the user's browser, I cannot have any IP restriction on my APIM backend inbound policy, as the application could be accessed from anywhere ( public facing). But if anyone gets access to the API url by inspecting the network traffic in the browser , my backend API's become vulnerable. How can I restrict that APIM endpoints are only accessible from the react app ? I have tried using CORS policy to allow my domain , but still tools like POSTMAN are able to access the endpoints.

CodePudding user response:

The short answer is you cannot fully prevent people from hitting your public API endpoint on their own.

The longer answer is that you can put protections within your API config so that this isn't a concern. If all requests need a valid user authentication token, for instance, it doesn't matter if that valid request comes from your React UI or an errant user's terminal window. Check out some best practices on protecting your API endpoints, and it will hopefully answer your question.

CodePudding user response:

You can't. At best you can obstruct the user by making it harder to replicate a proper request to your API. Ultimately there's no way to identify whether or not a request came from a browser or some other tool though.

It's up to you to construct the API in such a way that the user can't abuse it by limiting the user to only perform actions that they should be allowed to make. If you are concerned by a user overloading your API you can add a policy to APIM to apply rate limiting (e.g. by IP).

  • Related