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

Fix #648 Option to disable signature verification #1088

Merged
merged 3 commits into from
Aug 28, 2021

Conversation

seratch
Copy link
Member

@seratch seratch commented Aug 26, 2021

Summary

This pull request resolves #648 by introducing a new option signatureVerification: boolean in App, HTTPReceiver, and ExpressReceiver. You can verify if the option works with the following example apps:

const { App, ExpressReceiver } = require('@slack/bolt');

const app = new App({
  logLevel: 'debug',
  token: process.env.SLACK_BOT_TOKEN,
  signingSecret: 'xxx',
  signatureVerification: false,
});

const app = new App({
  logLevel: 'debug',
  token: process.env.SLACK_BOT_TOKEN,
  receiver: new ExpressReceiver({
    signingSecret: 'xxx',
    signatureVerification: false,
  }),
});

Requirements (place an x in each [ ])

@seratch seratch added the enhancement M-T: A feature request for new functionality label Aug 26, 2021
@seratch seratch added this to the 3.7.0 milestone Aug 26, 2021
@seratch seratch self-assigned this Aug 26, 2021
@codecov
Copy link

codecov bot commented Aug 26, 2021

Codecov Report

Merging #1088 (0bf5beb) into main (2f463ce) will decrease coverage by 0.61%.
The diff coverage is 40.74%.

❗ Current head 0bf5beb differs from pull request most recent head cbb5be5. Consider uploading reports for the commit cbb5be5 to get more accurate results
Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1088      +/-   ##
==========================================
- Coverage   70.16%   69.55%   -0.62%     
==========================================
  Files          13       13              
  Lines        1257     1281      +24     
  Branches      369      377       +8     
==========================================
+ Hits          882      891       +9     
- Misses        305      319      +14     
- Partials       70       71       +1     
Impacted Files Coverage Δ
src/receivers/verify-request.ts 13.51% <0.00%> (-0.78%) ⬇️
src/receivers/ExpressReceiver.ts 59.06% <31.57%> (-3.22%) ⬇️
src/receivers/HTTPReceiver.ts 32.27% <66.66%> (+0.72%) ⬆️
src/App.ts 83.51% <100.00%> (+0.08%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2f463ce...cbb5be5. Read the comment docs.

@@ -320,12 +328,19 @@ export const respondToUrlVerification: RequestHandler = (req, res, next) => {
next();
};

export function verifySignatureAndParseRawBody(
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wanted to rename the builder method to buildVerificationBodyParserMiddleware internally but we still need to keep exporting this one for backward compatibility

src/App.ts Outdated
@@ -59,6 +59,7 @@ export interface AppOptions {
signingSecret?: HTTPReceiverOptions['signingSecret'];
endpoints?: HTTPReceiverOptions['endpoints'];
processBeforeResponse?: HTTPReceiverOptions['processBeforeResponse'];
requestVerification?: HTTPReceiverOptions['requestVerification'];
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There may be a better name for this flag. Let me know if you have any suggestions.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about signatureVerification? It feels a bit more specific.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@filmaj That's also an option! But strictly speaking, the validation checks not only the signature but also others like x-slack-request-timestamp: https://api.slack.com/authentication/verifying-requests-from-slack Thus, I'm thinking that "request verification" is slightly more suitable. What do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I immediately thought of signatureVerification as well. But requestVerification also makes sense to me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the inputs! OK, let me change the name and see how it looks!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed to signatureVerification ✅

Copy link
Contributor

@filmaj filmaj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Do Bolt or the lower level Slack SDKs have a concept of environments, in the sense of being able to differentiate between a production Slack app, vs. one deployed to a development environment, or even one used in local test suites? The reason I ask is based on the discussion in the original issue, it seems the impetus for this feature is mostly around testing. If testing is the intended use of this feature, perhaps there could be some manner of environment checks in conjunction with this flag to ensure that users don't use this flag for a production application? Just thinking out loud; acceptable answers include "no" 😄

src/App.ts Outdated
@@ -59,6 +59,7 @@ export interface AppOptions {
signingSecret?: HTTPReceiverOptions['signingSecret'];
endpoints?: HTTPReceiverOptions['endpoints'];
processBeforeResponse?: HTTPReceiverOptions['processBeforeResponse'];
requestVerification?: HTTPReceiverOptions['requestVerification'];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about signatureVerification? It feels a bit more specific.

src/receivers/verify-request.ts Show resolved Hide resolved
@seratch
Copy link
Member Author

seratch commented Aug 26, 2021

@filmaj Thanks for the comment!

Do Bolt or the lower level Slack SDKs have a concept of environments, in the sense of being able to differentiate between a production Slack app, vs. one deployed to a development environment, or even one used in local test suites? The reason I ask is based on the discussion in the original issue, it seems the impetus for this feature is mostly around testing.

This option is indeed useful for testing but the main reason why we decided to add this one in the Java SDK first is, as linked from #648, to support the use cases like having a proxy in front of our server that already checks the Slack signatures: slackapi/java-slack-sdk#689 If the motivation is only for easier testing, we might not add this functionality.

If testing is the intended use of this feature, perhaps there could be some manner of environment checks in conjunction with this flag to ensure that users don't use this flag for a production application? Just thinking out loud; acceptable answers include "no" 😄

This sounds a good idea but for the above reason, the need to disable the verification in production on the Bolt app side can be valid. We can trust users decisions and have some clear notice in the document like we do for the Java SDK: https://slack.dev/java-slack-sdk/guides/bolt-basics#customize-the-built-in-middleware-list

@seratch
Copy link
Member Author

seratch commented Aug 27, 2021

We are still discussing the naming requestVerification. If you have thoughts on it, feel free to write comments!

Copy link
Member

@mwbrooks mwbrooks left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me!

Do we want to update the documentation to mention this new option?

src/App.ts Outdated
@@ -59,6 +59,7 @@ export interface AppOptions {
signingSecret?: HTTPReceiverOptions['signingSecret'];
endpoints?: HTTPReceiverOptions['endpoints'];
processBeforeResponse?: HTTPReceiverOptions['processBeforeResponse'];
requestVerification?: HTTPReceiverOptions['requestVerification'];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I immediately thought of signatureVerification as well. But requestVerification also makes sense to me.

@filmaj
Copy link
Contributor

filmaj commented Aug 27, 2021

@seratch thanks for the information and clarification! Much appreciated

@seratch seratch force-pushed the issue-648-request-verification branch from 4c2d348 to ea6abc3 Compare August 28, 2021 00:08
@seratch
Copy link
Member Author

seratch commented Aug 28, 2021

Resolved conflicts ✅

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement M-T: A feature request for new functionality
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to disable signature verification
3 participants