Skip to content

Commit

Permalink
SECURITY-5161: pull in new test cases, fix tests
Browse files Browse the repository at this point in the history
Co-authored-by: Laszlo Hammerl <[email protected]>
  • Loading branch information
knagy and potato committed Jun 7, 2024
1 parent 0b0aedd commit ec253ba
Show file tree
Hide file tree
Showing 10 changed files with 20 additions and 1,544 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@ jobs:
strategy:
matrix:
node: [
'12.22.5',
'14.17.5',
'16.7.0'
'16',
'18',
'20'
]

name: Node JS ${{ matrix.node }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ build/Release
# Commenting this out is preferred by some people, see
# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git-
node_modules
package-lock.json

This comment has been minimized.

Copy link
@SchroederSteffen

SchroederSteffen Jul 15, 2024

The package-lock.json shouldn't be ignored to ensure reproduceable builds and avoid supply chain attacks and malicious packages like https://snyk.io/blog/open-source-npm-packages-colors-faker/.


# Users Environment Variables
.lock-wscript
Expand Down
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
v8.9.0
v20.14.0
2 changes: 1 addition & 1 deletion lib/canonicalizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class Canonicalizer {
const parsedUrl = Utils.parseUrl(preparedUrl, true);
const headers = this._filterHeaders(Utils.normalizeHeaders(requestOptions.headers), headersToSign);
const lines = [
requestOptions.method,
requestOptions.method.toUpperCase(),
path.normalize(parsedUrl.pathname),
this.canonicalizeQuery(parsedUrl.query),
this._canonicalizeHeaders(headers).join('\n'),
Expand Down
8 changes: 6 additions & 2 deletions lib/escher.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ class Escher {
signRequest(requestOptions, body, headersToSign) {
const currentDate = new Date();
this.validateRequest(requestOptions, body);
headersToSign = ['host', this._config.dateHeaderName.toLowerCase()].concat(headersToSign || []);
headersToSign = this.getHeadersToSign(headersToSign);
const formattedDate =
this._config.dateHeaderName.toLowerCase() === 'date'
? Utils.toHeaderDateFormat(currentDate)
Expand All @@ -60,6 +60,10 @@ class Escher {
return requestOptions;
}

getHeadersToSign(headersToSign) {
return ['host', this._config.dateHeaderName.toLowerCase()].concat(headersToSign || []);
}

authenticate(request, keyDB, mandatorySignedHeaders) {
const currentDate = new Date();
this.validateRequest(request);
Expand Down Expand Up @@ -154,7 +158,7 @@ class Escher {
}

validateRequest(request, body) {
if (typeof request.method !== 'string' || !allowedRequestMethods.includes(request.method)) {
if (typeof request.method !== 'string' || !allowedRequestMethods.includes(request.method.toUpperCase())) {
throw new Error('The request method is invalid');
}

Expand Down
Loading

0 comments on commit ec253ba

Please sign in to comment.