I have api.example.com and example.com.
I need example.com could exchange data with api.example.com but I don't want to take some extra security measures. Before now I sent request to api.example.com (axios.get("http://api.example.com")), but there I used JWT tokens. No there is no need in them, how to make secure communication?
1 Answer
You could use a private API key to secure communication. Here's the general approach:
1.Come up with a complicated password, and use a PROVEN hashing algorithm to obfuscate it. This is your API Key.
2.Every request from the front-end to the backend should contain the API key, preferably as part of the Headers under Authorization property, like so:
Authorization: Apikey TEST_API_KEY
3.Your backend decodes the hashed value with the same hashing algorithm and compares it with the password, if it's not a match, send a 401 status!
Make sure your requests are over HTTPS as that way, the request is encrpyted.
2 Comments
GET requests, you can expose the API without making it secure, provided that you use procedures to limit DDOS attacks (e.g. Limit number of requests per seconds from devices/ip-addresses), but these aren't completely bullet-proof. 2. You don't decode the hash on the client, the client only sends the secret with every request, but yes, the API key is exposed. There are ways to obfuscate your JS bundle, and bundlers like Webpack make it easy, but not bullet-proof.
api.example.comfromexample.com? What do you mean by "there is no need in them" ? No need to use JWT ?