How to protect an API Key when using JavaScript?

后端 未结 2 686
南方客
南方客 2020-11-30 05:30

So, I\'m developing a small application just for my own use and perhaps an open source project on Git. I\'m using an API from Envato Marketplaces, and as you all know there

相关标签:
2条回答
  • 2020-11-30 06:30

    Short answer: No

    What ever you do to obfuscate the key, you still have to send it to make it available on the client somehow, and therefore it will be possible to extract it using fx. Firebug.

    Even if you devise an awesome magical way to keep the key secret, at some point you would have to make the actual API-request, and as it would have to be sent from the browser, an attacker would be able to read out the key in plain text from Firebugs net tab.

    The right thing to do is to create a PHP wrapper around the API calls that require keys, and then call that wrapper from Javascript.

    0 讨论(0)
  • 2020-11-30 06:31

    My solution right now is to write a little wrapper in rust, and throw it in the /cgi-bin and make calls to that. That should keep the api-key, api creds and session data separate from the client.

    0 讨论(0)
提交回复
热议问题