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

verifyRequestSignature breaks if request does not contain required headers #1069

Closed
5 of 16 tasks
ramsgoli opened this issue Jul 30, 2020 · 2 comments · Fixed by #1070
Closed
5 of 16 tasks

verifyRequestSignature breaks if request does not contain required headers #1069

ramsgoli opened this issue Jul 30, 2020 · 2 comments · Fixed by #1070
Assignees
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented

Comments

@ramsgoli
Copy link
Contributor

ramsgoli commented Jul 30, 2020

Description

verifyRequestSignature breaks if the POST request does not contain any of the required headers

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.

Bug Report

Filling out the following details about bugs will help us solve your issue sooner.

Packages:

Select all that apply:

  • @slack/web-api
  • @slack/events-api
  • @slack/interactive-messages
  • @slack/rtm-api
  • @slack/webhooks
  • @slack/oauth
  • I don't know

Reproducible in:

package version: latest

node version: v10.15.3

OS version(s): macos 10.15.5

Steps to reproduce:

  1. Register the listener to the app (before any bodyparsers)
app.use('/api/slack/event', slackEvents.requestListener())
  1. send a POST to /api/slack/event but don't include any of the required headers (x-slack-signature, x-slack-request-timestamp)

Expected result:

The request should be rejected

Actual result:

The request results in an internal server error


/Users/ram/myproj/node_modules/@slack/events-api/dist/http-handler.js:41
    var _b = requestSignature.split('='), version = _b[0], hash = _b[1];
                              ^
TypeError: Cannot read property 'split' of undefined
    at verifyRequestSignature (/Users/ram/myproj/node_modules/@slack/events-api/dist/http-handler.js:41:31)
    at /Users/ram/myproj/node_modules/@slack/events-api/dist/http-handler.js:168:17
    at process._tickCallback (internal/process/next_tick.js:68:7)

This happens because at

requestSignature: req.headers['x-slack-signature'] as string,
,
we cast the headers as strings. IMO they should be treated as string | undefined and then handled appropriately in verifyRequestSignature. This would be nicer than the app throwing errors when requests are missing headers.

@mwbrooks mwbrooks added the bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented label Jul 31, 2020
@mwbrooks
Copy link
Member

Hey @ramsgoli thanks for reporting this issue and documenting all of the details we need to re-create (and resolve) it! 👊🏻

I agree that the app should handle missing headers gracefully, rather than throwing an exception. I'll line up this issue to be fixed soon (see the assigned Project board). If you happen to want to submit a PR, please go for it and we'll help to review and merge it.

@ramsgoli
Copy link
Contributor Author

@mwbrooks Sounds good! Just put up a PR that addresses this ☝️

@mwbrooks mwbrooks linked a pull request Aug 1, 2020 that will close this issue
2 tasks
@mwbrooks mwbrooks self-assigned this Aug 1, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug M-T: A confirmed bug report. Issues are confirmed when the reproduction steps are documented
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants