Any type of key, token or security you apply will need to be applied on the client side as well. And that’s the big problem. When we are talking about a web application, there are easy ways to inspect the browser and find that key or token. Already in a mobile app, the user can decompile their app and easily grab that key. If the connection between client and server does not use SSL, someone with a network monitor can view the requests.
The fact is, in your case, your API is public. The user does not need to previously log in to use it or anything like that. Just consult and requisition.
If someone really wants to hit your API from outside of your applications, they will succeed. No matter what techniques you add to prevent this, all that will happen is to make this work harder, but it is still possible.
What I usually do in public Apis is monitor. Cloud servers and services today already have tools to block and de-prioritize requests that are abusing your application. Guide your decisions according to what the dice show you. Monitor your application and see if there really is someone trying to do something they shouldn’t. If they are not, why worry so soon? And if they are trying, it is a good sign. Your application is already so famous that it is calling attention. When you get there, make the necessary arrangements: JWT, CORS, CSRF.
The only way to ensure 100% that your public API will not receive requests from outside is by making it private. Thus, you have control of 100% of the requisitors.
I do not think that answers the question. Your answer includes means of authentication. What I want is a means to make only the mine front-end and the mine application can consume the API (even without user authentication). I edited the question adding more details.
– Luiz Felipe
Got it. I’ll be updating my answer as soon as possible.
– Mathias Berwig
You can check the referrer and check if it’s your front-end domain.
req.headers.referer
– Paulo Victor
Updated response. If needed, we can discuss these (and other) security approaches in chat.
– Mathias Berwig