Q: Is it 'safe' to include a secret API Key in a HEADER (for a request) which prevents bad actors from creating their own evil-requests by using your API Key ?
We need to send data to a 3rd party from our mobile app. Their SDK ends up sending requests to their REST api .. with our unique API KEY as part of the request HEADER.
So in my head, I'm simplifying this as a simple curl
request with a custom HEADER that contains the api key:
(other headers/body stripped out)
curl 'https://example.com/api/data' \
-X POST \
-H 'X-Api-Key: some-guid'
Also, I'm thinking about the following threat models:
- A passive attacker on the network (eavesdropping)
- An active attacker on the network (can change packets at will, mitm, etc) <-- E.g. An attacker is doing MITM from their mobile phone <-> 3rd party server.
So - given all of this ... can't a bad attacker just snoop all the requests from their mobile phone (aka. MITM attack) and see this single request and now read the API key in the header .. and viola! they can now generate their own curl's
?
I keep reading a consistent suggestion here and that is: If the request is done over TLS (aka HTTPS) then the request is "secure". But .. as suggested above, I can decrypt the HTTPS request, right? Then I can easily see the API key, right?
Am I missing something obvious here?
If this was server <-> server, I wouldn't care. If you are doing a MITM on that level then I have bigger things to worry about now.
But because this is a mobile phone - surely this is a security issue?
UPDATE 1: Including topology example, of a single request:
- Mobile Phone (with a custom proxy set)
- My computer with the custom proxy MITMProxy running
- ☁️ Interwebs
- 3rd Party API Server
UPDATE 2 Re-reading my comments I feel like I'm basically saying "please tell me how to be a bad-actor/hacker". I'm actually reviewing some 3rd Party SDK which is to be used in our iPhone/Android App .. and we're thinking: this could be a security issue as someone could steal our API Key (using the steps/thinking, above) and abuse our account .. which means abuse our customers.