Improves key matching algorithm
This commit is contained in:
@@ -99,20 +99,20 @@ function handleParseHeaders(req, res, next) {
|
|||||||
|
|
||||||
// Client keys are not required in parse-server, but if any have been configured in the server, validate them
|
// Client keys are not required in parse-server, but if any have been configured in the server, validate them
|
||||||
// to preserve original behavior.
|
// to preserve original behavior.
|
||||||
var keyRequired = (req.config.clientKey
|
let keys = ["clientKey", "javascriptKey", "dotNetKey", "restAPIKey"];
|
||||||
|| req.config.javascriptKey
|
|
||||||
|| req.config.dotNetKey
|
// We do it with mismatching keys to support no-keys config
|
||||||
|| req.config.restAPIKey);
|
var keyMismatch = keys.reduce(function(mismatch, key){
|
||||||
var keyHandled = false;
|
// check the info key
|
||||||
if (keyRequired
|
// increment the mismatch if different
|
||||||
&& ((info.clientKey && req.config.clientKey && info.clientKey === req.config.clientKey)
|
if (info[key] !== req.config[key]) {
|
||||||
|| (info.javascriptKey && req.config.javascriptKey && info.javascriptKey === req.config.javascriptKey)
|
mismatch++;
|
||||||
|| (info.dotNetKey && req.config.dotNetKey && info.dotNetKey === req.config.dotNetKey)
|
}
|
||||||
|| (info.restAPIKey && req.config.restAPIKey && info.restAPIKey === req.config.restAPIKey)
|
return mismatch;
|
||||||
)) {
|
}, 0);
|
||||||
keyHandled = true;
|
|
||||||
}
|
// All keys mismatch
|
||||||
if (keyRequired && !keyHandled) {
|
if (keyMismatch == keys.length) {
|
||||||
return invalidRequest(req, res);
|
return invalidRequest(req, res);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user