mirror of
https://github.com/jsbin/jsbin.git
synced 2026-01-18 15:18:04 +00:00
Flag to enforce API requests over SSL
This commit is contained in:
parent
fe0c142de7
commit
44d030e88a
@ -48,7 +48,8 @@
|
||||
"report": []
|
||||
},
|
||||
"api": {
|
||||
"allowAnonymous": true
|
||||
"allowAnonymous": true,
|
||||
"requireSSL": false
|
||||
},
|
||||
"blacklist": {
|
||||
"html": ["processform.cgi", "habbo.com"],
|
||||
|
||||
@ -189,6 +189,15 @@ module.exports = {
|
||||
|
||||
if (req.url.indexOf('/api') === 0) {
|
||||
req.isApi = true;
|
||||
|
||||
if (config.api.requireSSL) {
|
||||
if (!req.secure && (String(req.headers['x-forwarded-proto']).toLowerCase() !== "https") ) {
|
||||
res.status(403); // forbidden
|
||||
res.json({ error: 'All API requests must be made over SSL/TLS' });
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (req.query.api_key) {
|
||||
apiKey = req.query.api_key;
|
||||
} else if (req.headers.authorization) {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user