Skip to content

Commit

Permalink
refactor: ♻️ Refactor headers construction for countercheck. Hopefull…
Browse files Browse the repository at this point in the history
…y fixing that too much headers are included in the counter check
  • Loading branch information
Hobart2967 committed Oct 1, 2023
1 parent ea607a0 commit 92b28bf
Showing 1 changed file with 8 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/services/request-verification.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,20 +132,17 @@ export class RequestVerificationService {
}

private getCleansedHeaders(request: RequestWithContext, incomingSignature: ParsedSignature): OutgoingHttpHeaders {
const headers = Object.assign({}, request.headers);
const cleansedHeaders: OutgoingHttpHeaders = Object.entries(request.headers)
.filter(([header]) => !incomingSignature.signedHeaders.includes(header.toLowerCase()))
.reduce((prev, [header, value]) => ({
...prev,
[header.toLowerCase()]: value
}), {});

delete headers.authorization;
delete headers['Authorization'];

const cleansedHeaders = Object.keys(headers)
.map(x => x.toLowerCase())
.filter(x => !incomingSignature.signedHeaders.includes(x));
this._logger.debug('Cleansed headers: ' + JSON.stringify(cleansedHeaders));

for (const header of cleansedHeaders) {
delete headers[header];
}

return headers;
return cleansedHeaders;
}
//#endregion
}

0 comments on commit 92b28bf

Please sign in to comment.