Lets consider the following scenario:
We have an angular js front end which consumes an internal API to get and manipulate data.
We expose this API under /api/internal
. However, we don't want this to be publicly accessible, we want it to be accessed only by our front end. To make sure of this, we allow access to the API only with a token passed in the request header: Authorization: Token token=xxx
The problem comes in how we set this token for all requests. We may take an approach like this:
angular.module('myApp').run(function($http) {
$http.defaults.headers.common.Authorization = 'Token token="xxx"'
})
The problem, of course, is this will be in the client, which means anyone who will inspect the javascript and grep for a Token
or Authorization
string will be able to find the token and use it to access the data.
There are other security measures in place of course, but focusing on just this issue, I am interested in how it can be approached differently and more safely.