Skip to content

Commit d6d940c

Browse files
authored
Enable CSRF protection in grant (OAuth2) (#5504)
* Enable CSRF protection in grant (OAuth2) I've been doing some testing and from what I can see, this is already supported in https://github.com/simov/grant (which companion uses for OAuth2), when enabling the `state` parameter. It seems to be working and it is checking the parameter when redirected back from the provider: https://github.com/simov/grant/blob/61fe48a8dac6aa4ec5764fadff0898b743b85588/lib/flow/oauth2.js#L72So * fix test
1 parent 6d413f5 commit d6d940c

File tree

2 files changed

+20
-8
lines changed

2 files changed

+20
-8
lines changed

packages/@uppy/companion/src/config/grant.js

+14-8
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
11
const google = {
2-
transport: 'session',
3-
42
// access_type: offline is needed in order to get refresh tokens.
53
// prompt: 'consent' is needed because sometimes a user will get stuck in an authenticated state where we will
64
// receive no refresh tokens from them. This seems to be happen when running on different subdomains.
@@ -15,51 +13,59 @@ const google = {
1513
"scope_delimiter": " "
1614
}
1715

16+
const defaults = {
17+
transport: 'session',
18+
state: true, // Enable CSRF check
19+
};
20+
1821
// oauth configuration for provider services that are used.
1922
module.exports = () => {
2023
return {
2124
// we need separate auth providers because scopes are different,
2225
// and because it would be a too big rewrite to allow reuse of the same provider.
2326
googledrive: {
27+
...defaults,
2428
...google,
29+
state: true,
2530
callback: '/drive/callback',
2631
scope: ['https://www.googleapis.com/auth/drive.readonly'],
2732
},
2833
googlephotos: {
34+
...defaults,
2935
...google,
3036
callback: '/googlephotos/callback',
3137
scope: ['https://www.googleapis.com/auth/photoslibrary.readonly', 'https://www.googleapis.com/auth/userinfo.email'], // if name is needed, then add https://www.googleapis.com/auth/userinfo.profile too
3238
},
3339
dropbox: {
34-
transport: 'session',
40+
...defaults,
3541
authorize_url: 'https://www.dropbox.com/oauth2/authorize',
3642
access_url: 'https://api.dropbox.com/oauth2/token',
3743
callback: '/dropbox/callback',
3844
custom_params: { token_access_type : 'offline' },
3945
},
4046
box: {
41-
transport: 'session',
47+
...defaults,
4248
authorize_url: 'https://account.box.com/api/oauth2/authorize',
4349
access_url: 'https://api.box.com/oauth2/token',
4450
callback: '/box/callback',
4551
},
4652
instagram: {
47-
transport: 'session',
53+
...defaults,
4854
callback: '/instagram/callback',
4955
},
5056
facebook: {
51-
transport: 'session',
57+
...defaults,
5258
scope: ['email', 'user_photos'],
5359
callback: '/facebook/callback',
5460
},
5561
// for onedrive
5662
microsoft: {
57-
transport: 'session',
63+
...defaults,
5864
scope: ['files.read.all', 'offline_access', 'User.Read'],
5965
callback: '/onedrive/callback',
6066
},
6167
zoom: {
62-
transport: 'session',
68+
...defaults,
6369
authorize_url: 'https://zoom.us/oauth/authorize',
6470
access_url: 'https://zoom.us/oauth/token',
6571
callback: '/zoom/callback',

packages/@uppy/companion/test/__tests__/provider-manager.js

+6
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ describe('Test Provider options', () => {
4141
providerManager.addProviderOptions(getCompanionOptions(), grantConfig, getOauthProvider)
4242
expect(grantConfig.instagram).toEqual({
4343
transport: 'session',
44+
"state": true,
4445
callback: '/instagram/callback',
4546
redirect_uri: 'http://localhost:3020/instagram/redirect',
4647
key: '123456',
@@ -53,6 +54,7 @@ describe('Test Provider options', () => {
5354
key: 'dropbox_key',
5455
secret: 'dropbox_secret',
5556
transport: 'session',
57+
"state": true,
5658
redirect_uri: 'http://localhost:3020/dropbox/redirect',
5759
authorize_url: 'https://www.dropbox.com/oauth2/authorize',
5860
access_url: 'https://api.dropbox.com/oauth2/token',
@@ -66,6 +68,7 @@ describe('Test Provider options', () => {
6668
key: 'box_key',
6769
secret: 'box_secret',
6870
transport: 'session',
71+
"state": true,
6972
redirect_uri: 'http://localhost:3020/box/redirect',
7073
authorize_url: 'https://account.box.com/api/oauth2/authorize',
7174
access_url: 'https://api.box.com/oauth2/token',
@@ -81,6 +84,7 @@ describe('Test Provider options', () => {
8184
key: 'google_key',
8285
secret: 'google_secret',
8386
transport: 'session',
87+
"state": true,
8488
redirect_uri: 'http://localhost:3020/drive/redirect',
8589
scope: [
8690
'https://www.googleapis.com/auth/drive.readonly',
@@ -101,6 +105,7 @@ describe('Test Provider options', () => {
101105
key: 'google_key',
102106
secret: 'google_secret',
103107
transport: 'session',
108+
"state": true,
104109
redirect_uri: 'http://localhost:3020/googlephotos/redirect',
105110
scope: ['https://www.googleapis.com/auth/photoslibrary.readonly', 'https://www.googleapis.com/auth/userinfo.email'],
106111
callback: '/googlephotos/callback',
@@ -114,6 +119,7 @@ describe('Test Provider options', () => {
114119
key: 'zoom_key',
115120
secret: 'zoom_secret',
116121
transport: 'session',
122+
"state": true,
117123
authorize_url: 'https://zoom.us/oauth/authorize',
118124
redirect_uri: 'http://localhost:3020/zoom/redirect',
119125
access_url: 'https://zoom.us/oauth/token',

0 commit comments

Comments
 (0)