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 cb82ff9
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions src/webhooks/webhooks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -200,31 +200,44 @@ 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 signatureWithoutPort = validateSignatureWithUrl(
authToken,
twilioHeader,
removePort(urlObject),
params
);

if (signatureWithoutPort) {
return true;
}

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

if (signatureWithPort) {
return true;
}

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

if (signatureWithLegacyQuerystring) {
return true;
}

return validateSignatureWithUrl(
authToken,
twilioHeader,
withLegacyQuerystring(addPort(urlObject)),
params
);
}

Expand Down

0 comments on commit cb82ff9

Please sign in to comment.