mirror of
https://github.com/balena-os/balena-supervisor.git
synced 2024-12-19 05:37:53 +00:00
Allow using an HTTP header for auth
This commit is contained in:
parent
439bac6331
commit
1eb63366ee
@ -1,3 +1,4 @@
|
||||
* Allow using an HTTP header for auth [Pablo]
|
||||
* Add iptables rules to block requests to the supervisor API from all interfaces except vpn, docker and local [Pablo]
|
||||
|
||||
# v1.13.2
|
||||
|
@ -17,9 +17,15 @@ module.exports = (application) ->
|
||||
parsedRouter.use(bodyParser())
|
||||
|
||||
api.use (req, res, next) ->
|
||||
queryKey = req.query.apikey
|
||||
header = req.get('Authorization') ? ''
|
||||
match = header.match(/^ApiKey (\w+)$/)
|
||||
headerKey = match?[1]
|
||||
utils.getOrGenerateSecret('api')
|
||||
.then (secret) ->
|
||||
if bufferEq(new Buffer(req.query.apikey), new Buffer(secret))
|
||||
if queryKey? && bufferEq(new Buffer(queryKey), new Buffer(secret))
|
||||
next()
|
||||
else if headerKey? && bufferEq(new Buffer(headerKey), new Buffer(secret))
|
||||
next()
|
||||
else
|
||||
res.sendStatus(401)
|
||||
|
Loading…
Reference in New Issue
Block a user