How to secure the search only API Key?
Is there a way to ensure the API Key only responds to calls from my own domain?
cc: @Jason Bosco
f
Fanis Tharropoulos
03/19/2025, 9:08 AM
While not recent, there was a similar question asked a while back here:
https://threads.typesense.org/2K3200
And it didn't seem possible. Maybe @Kishore Nallan has something more to add
k
Kishore Nallan
03/19/2025, 9:58 AM
It's not possible to restrict API key to a domain. Generally search API exposes already public information. If you are storing data from different users in the same collection, check scoped API key on how we can embed a fixed filtering expression into the API key so that it can't be tampered with.
c
Carlos
03/19/2025, 12:36 PM
Got it. Thanks. It’s a major issue because it opens us up to abuse and scraping. Will look into the methods you mention in the docs. Thanks!
j
Jason Bosco
03/20/2025, 12:48 AM
There's technically no way to ensure that an API can only be called from a certain domain. There's CORS, but that is only a browser-thing, and can be easily bypassed using curl directly.
So if scraping protection is what you're looking for, you want to consider using these precautions: https://typesense.org/docs/guide/data-access-control.html#scraping-protection
e
Elliot Sawyer
03/20/2025, 4:47 AM
You can rotate the search key regularly. If you have control of the domain name, put Cloudflare in front of it with Bot Fight Mode
Elliot Sawyer
03/20/2025, 4:48 AM
But yeah, if making direct calls to the API endpoint, not easy to avoid