How Can I Limit an API Endpoint to a Specific Domain While Keeping It Public?

0
12
Asked By QuietFox_92 On

I'm trying to figure out if there's a way to restrict access to an API endpoint such that it can only be called from a UI hosted on a specific domain. The challenge is that I want the endpoint to be accessible to non-logged-in users, but I want to prevent access from anywhere else. Is it possible to achieve this without implementing any form of authentication? I considered using CORS and tokens, but I'm worried that someone could easily spoof this with a third-party request.

3 Answers

Answered By SecurityGuru77 On

If you’re serious about security, you might consider using a Cloudflare Turnstile-like method for validation. It allows for a passwordless token that the server can validate. This could help you achieve the level of protection you’re looking for without traditional login methods.

QuietFox_92 -

That actually sounds like the kind of solution I'm looking for—an easy way to validate without needing a password.

Answered By CodeNinja88 On

Using CORS can help limit who can access your endpoint from a browser, but keep in mind that any endpoint exposed to the client can be hit by other HTTP clients too. Sure, you can restrict headers or implement CORS, but those can be faked. If your concern is keeping endpoints private, you might want to rethink what you’re trying to secure.

Answered By DevWizard23 On

You can use Same-Origin Policy (SOP) to protect your API from other origins. Combine that with CORS to specify allowed origins, but remember, any client the user controls can send any request. So, implementing authentication along with rate limiting is the real way to protect your endpoints.

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.