Skip to content

Commit 6ff6d21

Browse files
committed
fix: add state parameter for oauth2
state parameter is recommended with oauth2 authentification to mitigate CSRF attacks (see [1]). hydra [2] will throw the following error message if state is missing: description="The state is missing or has less than 8 characters and is therefore considered too weak" error=invalid_state hint="Request parameter \"state\" must be at least be 8 characters long to ensure sufficient entropy." [1]: https://auth0.com/docs/protocols/oauth2/oauth-state [2]: https://www.ory.sh/hydra/ Signed-off-by: Samuel Trégouët <[email protected]>
1 parent a6c7582 commit 6ff6d21

File tree

3 files changed

+3
-0
lines changed

3 files changed

+3
-0
lines changed

lib/auth/oauth2/index.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ passport.use(new OAuth2CustomStrategy({
1616
clientSecret: config.oauth2.clientSecret,
1717
callbackURL: config.serverURL + '/auth/oauth2/callback',
1818
userProfileURL: config.oauth2.userProfileURL,
19+
state: config.oauth2.state,
1920
scope: config.oauth2.scope
2021
}, passportGeneralCallback))
2122

lib/config/default.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,7 @@ module.exports = {
100100
userProfileDisplayNameAttr: 'displayName',
101101
userProfileEmailAttr: 'email',
102102
userProfilePhotoAttr: 'photo',
103+
state: true,
103104
scope: 'email'
104105
},
105106
facebook: {

lib/config/environment.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ module.exports = {
9494
tokenURL: process.env.CMD_OAUTH2_TOKEN_URL,
9595
userProfileURL: process.env.CMD_OAUTH2_USER_PROFILE_URL,
9696
scope: process.env.CMD_OAUTH2_SCOPE,
97+
state: process.env.CMD_OAUTH2_STATE,
9798
userProfileUsernameAttr: process.env.CMD_OAUTH2_USER_PROFILE_USERNAME_ATTR,
9899
userProfileDisplayNameAttr: process.env.CMD_OAUTH2_USER_PROFILE_DISPLAY_NAME_ATTR,
99100
userProfileEmailAttr: process.env.CMD_OAUTH2_USER_PROFILE_EMAIL_ATTR,

0 commit comments

Comments
 (0)