How Can I Restrict API Endpoint Access to a Specific Domain?

0
1
Asked By BlueSkyTraveler42 On

I'm looking for a way to secure an endpoint I've developed so that it can only be accessed from a UI hosted at a specific domain. The challenge is that the endpoint needs to remain public, allowing non-logged-in users of my UI to use it, but I also want to prevent access from outside that specific domain. Is there a method to achieve this without needing some form of authentication? I've considered using CORS and token checks, but I'm concerned that any information sent from the client can be spoofed in a third-party request. Is this a viable approach?

4 Answers

Answered By SecureNode22 On

The Same Origin Policy (SOP) helps ensure that your API isn't accessible to other origins in the browser, and CORS allows you to specify which ones you want to permit. However, since it’s the client sending those requests, any user-controlled client can send whatever data they want. Implementing authentication and rate limiting is the best way to address these concerns.

Answered By CloudyTechie On

You might want to explore adding a validation process similar to Cloudflare Turnstile on your server. This can provide a passwordless authentication method with a token that can be validated server-side, helping to control access.

Answered By SecureBackendGuy On

You definitely need a backend to handle this securely. From there, you can implement various strategies like CORS, CSRF protection, and using time-based signed tokens to manage access to your endpoints. Although it's not foolproof, combining these methods can significantly reduce the risk of abuse.

Answered By WebDevGuru99 On

CORS can help a bit, but it’s not a complete solution since any endpoint accessible by your client can be hit by other HTTP clients as well. While you can filter certain headers and use CORS to allow specific domains, all these measures can be spoofed. If you're worried about endpoint visibility, you might want to rethink what you're trying to protect.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.