Skip to content

Commit 34a621b

Browse files
committed
Merge pull request #682 from ParsePlatform/flovilmart.fixKeysChecking
Improves key matching algorithm
2 parents 57c9364 + 4e5cc1f commit 34a621b

File tree

1 file changed

+14
-14
lines changed

1 file changed

+14
-14
lines changed

src/middlewares.js

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -99,20 +99,20 @@ function handleParseHeaders(req, res, next) {
9999

100100
// Client keys are not required in parse-server, but if any have been configured in the server, validate them
101101
// to preserve original behavior.
102-
var keyRequired = (req.config.clientKey
103-
|| req.config.javascriptKey
104-
|| req.config.dotNetKey
105-
|| req.config.restAPIKey);
106-
var keyHandled = false;
107-
if (keyRequired
108-
&& ((info.clientKey && req.config.clientKey && info.clientKey === req.config.clientKey)
109-
|| (info.javascriptKey && req.config.javascriptKey && info.javascriptKey === req.config.javascriptKey)
110-
|| (info.dotNetKey && req.config.dotNetKey && info.dotNetKey === req.config.dotNetKey)
111-
|| (info.restAPIKey && req.config.restAPIKey && info.restAPIKey === req.config.restAPIKey)
112-
)) {
113-
keyHandled = true;
114-
}
115-
if (keyRequired && !keyHandled) {
102+
let keys = ["clientKey", "javascriptKey", "dotNetKey", "restAPIKey"];
103+
104+
// We do it with mismatching keys to support no-keys config
105+
var keyMismatch = keys.reduce(function(mismatch, key){
106+
107+
// check if set in the config and compare
108+
if (req.config[key] && info[key] !== req.config[key]) {
109+
mismatch++;
110+
}
111+
return mismatch;
112+
}, 0);
113+
114+
// All keys mismatch
115+
if (keyMismatch == keys.length) {
116116
return invalidRequest(req, res);
117117
}
118118

0 commit comments

Comments
 (0)