Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined twilio header causing exception during validation #445

Closed
mniehe opened this issue May 7, 2019 · 0 comments · Fixed by #446
Closed

Undefined twilio header causing exception during validation #445

mniehe opened this issue May 7, 2019 · 0 comments · Fixed by #446
Labels
type: bug bug in the library

Comments

@mniehe
Copy link
Contributor

mniehe commented May 7, 2019

Version:
3.30.3

Code Snippet

The function call to Buffer.from() throws an error if passed undefined. When used here, there's no protection from twilioHeader being undefined (which is possible from an invalid request). This is causing exceptions to happen during validation.

function validateRequest(authToken, twilioHeader, url, params) {
  var expectedSignature = getExpectedTwilioSignature(authToken, url, params);
  return scmp(Buffer.from(twilioHeader), Buffer.from(expectedSignature));
}

The easiest fix for this would be to assign a default value if it is undefined:

function validateRequest(authToken, twilioHeader, url, params) {
  twilioHeader = twilioHeader || '';
  var expectedSignature = getExpectedTwilioSignature(authToken, url, params);
  return scmp(Buffer.from(twilioHeader), Buffer.from(expectedSignature));
}

Exception/Log

TypeError [ERR_INVALID_ARG_TYPE]: The first argument must be one of type string, Buffer, ArrayBuffer, Array, or Array-like Object. Received type undefined
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug bug in the library
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants