Skip to content

Commit

Permalink
chore: appply PR suggestions
Browse files Browse the repository at this point in the history
  • Loading branch information
leon19 committed Jan 20, 2025
1 parent 4c908e6 commit cd6a943
Showing 1 changed file with 41 additions and 26 deletions.
67 changes: 41 additions & 26 deletions src/webhooks/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,40 +200,55 @@ export function validateRequest(
* and with and without the legacy querystring (special chars are encoded when using `new URL()`)
* since signature generation on the back end is inconsistent
*/
return (
validateSignatureWithUrl(
authToken,
twilioHeader,
removePort(urlObject),
params
) ||
validateSignatureWithUrl(
authToken,
twilioHeader,
addPort(urlObject),
params
) ||
validateSignatureWithUrl(
authToken,
twilioHeader,
withLegacyQuerystring(removePort(urlObject)),
params
) ||
validateSignatureWithUrl(
authToken,
twilioHeader,
withLegacyQuerystring(addPort(urlObject)),
params
)
const isValidSignatureWithoutPort = validateSignatureWithUrl(
authToken,
twilioHeader,
removePort(urlObject),
params
);

if (isValidSignatureWithoutPort) {
return true;
}

const isValidSignatureWithPort = validateSignatureWithUrl(
authToken,
twilioHeader,
addPort(urlObject),
params
);

if (isValidSignatureWithPort) {
return true;
}

const isValidSignatureWithLegacyQuerystringWithoutPort = validateSignatureWithUrl(
authToken,
twilioHeader,
withLegacyQuerystring(removePort(urlObject)),
params
);

if (isValidSignatureWithLegacyQuerystringWithoutPort) {
return true;
}

const isValidSignatureWithLegacyQuerystringWithPort = validateSignatureWithUrl(
authToken,
twilioHeader,
withLegacyQuerystring(addPort(urlObject)),
params
);

return isValidSignatureWithLegacyQuerystringWithPort;
}

function validateSignatureWithUrl(
authToken: string,
twilioHeader: string,
url: string,
params: Record<string, any>
) {
): boolean {
const signatureWithoutPort = getExpectedTwilioSignature(
authToken,
url,
Expand Down

0 comments on commit cd6a943

Please sign in to comment.