mirror of https://github.com/embarklabs/embark.git
fix(modules/authenticator): ensure request hash doesn't include query params
The authenticators request hash algorithm produced different hashes than on the client, because client-side hash-request don't include the query parameters of a URL. This causes authentication issues when sending any requests with query parameters. This commit ensures we ignore them on the server as well.
This commit is contained in:
parent
479b79eeaf
commit
b654fdecd8
|
@ -18,10 +18,14 @@ class Authenticator {
|
||||||
generateRequestHash(req) {
|
generateRequestHash(req) {
|
||||||
let cnonce = req.headers['x-embark-cnonce'];
|
let cnonce = req.headers['x-embark-cnonce'];
|
||||||
let hash = new keccak();
|
let hash = new keccak();
|
||||||
|
let url = req.url;
|
||||||
|
let queryParamIndex = url.indexOf('?');
|
||||||
|
url = url.substring(0, queryParamIndex !== -1 ? queryParamIndex : url.length)
|
||||||
|
|
||||||
hash.update(cnonce);
|
hash.update(cnonce);
|
||||||
hash.update(this.authToken);
|
hash.update(this.authToken);
|
||||||
hash.update(req.method);
|
hash.update(req.method);
|
||||||
hash.update(req.url);
|
hash.update(url);
|
||||||
return hash.digest('hex');
|
return hash.digest('hex');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue