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

Add option to disable state verification, fix redirect uri bug #1116

Merged
merged 19 commits into from
Sep 27, 2021

Conversation

srajiang
Copy link
Member

@srajiang srajiang commented Sep 16, 2021

Summary

Fixes #1101
Fixes #1115

See both for more context.

It adds the option to disable state verification during OAuth flow via a stateVerification flag. By default this will be true. When state verification is disabled, stateSecret is no longer required, so this updates error messages associated with that previous hard requirement.

This PR also fixes an issue where the user supplied redirect_uri is not properly being passed as part of oauth/v2/authorize request params. It adds a separate top-level redirectUri parameter that contains the full url and includes some input validation.

Todo

  • Add tests for redirectUri configuration error states
  • Add test for stateVerification flow (needs new types pulled in)
  • Prep documentation PR to follow here
  • node-slack-sdk/pull/1329 should be released in node-slack-sdk.

Requirements (place an x in each [ ])

docs/_basic/authenticating_oauth.md Outdated Show resolved Hide resolved
@seratch seratch added the enhancement M-T: A feature request for new functionality label Sep 17, 2021
@seratch seratch added this to the 3.7.0 milestone Sep 17, 2021
@srajiang srajiang self-assigned this Sep 17, 2021
@srajiang srajiang force-pushed the 1101_add_state_validation_opt branch from f5e4c69 to beb3d57 Compare September 23, 2021 23:46
@srajiang srajiang changed the title [WIP] Add option to disable state verification Add option to disable state verification, fix redirect uri bug Sep 23, 2021
@srajiang srajiang force-pushed the 1101_add_state_validation_opt branch from beb3d57 to 79a77cd Compare September 24, 2021 00:34
@codecov
Copy link

codecov bot commented Sep 24, 2021

Codecov Report

Merging #1116 (daf5cee) into main (2f3f499) will increase coverage by 0.79%.
The diff coverage is 86.04%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main    #1116      +/-   ##
==========================================
+ Coverage   70.92%   71.71%   +0.79%     
==========================================
  Files          14       15       +1     
  Lines        1324     1354      +30     
  Branches      392      402      +10     
==========================================
+ Hits          939      971      +32     
- Misses        311      312       +1     
+ Partials       74       71       -3     
Impacted Files Coverage Δ
src/receivers/ExpressReceiver.ts 60.39% <60.00%> (+1.93%) ⬆️
src/receivers/verify-redirect-opts.ts 83.33% <83.33%> (ø)
src/receivers/SocketModeReceiver.ts 89.02% <93.33%> (+4.09%) ⬆️
src/App.ts 83.64% <100.00%> (+0.04%) ⬆️
src/receivers/HTTPReceiver.ts 37.12% <100.00%> (+2.25%) ⬆️

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 2f3f499...daf5cee. Read the comment docs.

Copy link
Member Author

@srajiang srajiang left a comment

Choose a reason for hiding this comment

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

Updated changes include:

  • Moved docs changes to separate PR.
  • Utility verification function that throws an error when custom redirect options are incomplete or invalid + tests for those scenarios at App and Receiver levels
  • Tests to check that install options are being directly handed over to handleCallback when stateVerification is disabled.
  • Did some reorganization of SocketModeReceiver and HTTPReceiver tests sections for readability.

Thanks in advance for your 👀 - I will squash and merge when the PR is ready!

@@ -117,217 +117,344 @@ describe('HTTPReceiver', function () {
});
Copy link
Member Author

Choose a reason for hiding this comment

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

I have added additional describe sections and reorganized some of the tests here and also in SocketModeReceiver.spec.ts to make the test files more consistent with one another and to make navigating test files / reading test output a little more clear.

Copy link
Member Author

Choose a reason for hiding this comment

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

Note: I attempted to incorporate state validation related tests for this, but ran into an issue with the requestHandler being a private function - wasn't sure how to really set up a fake request. I see that we don't really have the same test coverage for ExpressReceiver that we do for the other receivers and I'm wondering if that's a known limitation.

@srajiang srajiang force-pushed the 1101_add_state_validation_opt branch 2 times, most recently from cf22ddc to 283f6b6 Compare September 24, 2021 00:49
@srajiang srajiang marked this pull request as ready for review September 24, 2021 00:56
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

I left one comment. As long as your Slack app has only one Redirect URI in its settings, skipping to have redirect_uri parameter should be allowed. Also, if we add the validation about the existence of redirectUri as a requirement, it'll be a breaking change to many of the existing OAuth ebaled apps. They will need updates when upgrading bolt-js version.

scopes,
redirectUri,
}), AppInitializationError);
// missing redirectUri
Copy link
Member

Choose a reason for hiding this comment

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

Not setting redirectUri should be allowed. You can initiate the OAuth flow without redirect_uri parameter when your Slack app has only one redirect_uri setting.

I won't repeat the same comment for HTTPReceiver and SocketModeReceiver.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good catch. I have modified the check so now it makes sure that if redirectUri is supplied, redirectUriPath is required only.

redirectUriPath?: HTTPReceiverInstallerOptions['redirectUriPath'],
}

export function verifyRedirectOpts({ redirectUri, redirectUriPath }: RedirectOptions): void {
Copy link
Member

Choose a reason for hiding this comment

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

I added a comment on the corresponding test code side but missing only redirectUri should be okay.

@srajiang srajiang force-pushed the 1101_add_state_validation_opt branch 2 times, most recently from 08b9f87 to efc5e17 Compare September 24, 2021 18:10
@srajiang srajiang force-pushed the 1101_add_state_validation_opt branch from efc5e17 to f053a34 Compare September 24, 2021 18:12
@srajiang srajiang requested a review from seratch September 24, 2021 18:14
Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

LGTM 👍

@seratch
Copy link
Member

seratch commented Sep 24, 2021

Hey, other reviewers! This one is the last pull request waiting for merging in the v3.7.0 release milestone: https://github.com/slackapi/bolt-js/milestone/11 If you have any comments on this PR, submit your reviews by next Monday your Tuesday!

@srajiang Can I ask you to work on the release early next week?

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! Left a couple minor comments.

src/receivers/HTTPReceiver.ts Outdated Show resolved Hide resolved
src/receivers/HTTPReceiver.spec.ts Outdated Show resolved Hide resolved
srajiang and others added 2 commits September 27, 2021 11:14
Co-authored-by: Fil Maj <maj.fil@gmail.com>
Co-authored-by: Fil Maj <maj.fil@gmail.com>
@srajiang srajiang merged commit 1c1eb57 into slackapi:main Sep 27, 2021
@srajiang srajiang deleted the 1101_add_state_validation_opt branch September 27, 2021 18:18
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 semver:minor
Projects
None yet
4 participants