-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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 state support to PKCE implementation #2114
Conversation
…-oauth feat: [DX-2999] add state to pkce oauth
+1 Also, relates to #2148 that also fixes the intermediate redirect issue. |
+1 Can we get this merged sometime soon? |
+1 This needed for us as well, we use Okta too and state param is required there, can this be merged anytime soon |
Shall |
@lohxt1 Assigning this to you Lets make it a priority to have this merged early next week. |
@@ -30,10 +30,12 @@ const authorizeUserInWindow = ({ authorizeUrl, callbackUrl, session }) => { | |||
}); | |||
|
|||
function onWindowRedirect(url) { | |||
// The finalUrl should always be the callbackUrl. | |||
const hasHitRedirectUrl = url.includes(callbackUrl); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@m-schrepel Could you please handle the scenario pointed out by @pietrygamat in the above comment.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this necessary now considering #2275 ?
Issue Ref
1003
Description
State is a recommended part of the PKCE Oauth2 spec, but it is required by our identity provider (Okta). This implements support for state in a fairly straight-forward manner. We use the unique session id from the Oauth2 class (which might be the electron store?) and we make that URL safe and pass it along as a query param when the PKCE checkbox is enabled in the Oauth2 authorization code flow.
I implemented one more fix in the oauth2 helper file, also due to okta. The code previously had a conditional that checked for a code URL parameter when in the redirect flow, but okta returned that parameter before the final redirect was reached. That meant I changed the logic to say if we're at the callback url and we see this code query parameter, then execute the rest of the code. This should be backward compatible with anything else since only the PKCE flow uses this function and callback url is a requirement of the PKCE flow.
https://datatracker.ietf.org/doc/html/rfc6749#section-4.1.1 for more information on state
This pull request includes changes to the
packages/bruno-electron/src/ipc/network
directory that focus on improving the OAuth2 authentication process. The key changes involve enhancing the URL redirect validation in theauthorizeUserInWindow
function, simplifying the hash generation process in thegenerateCodeVerifier
function, and adding a unique state parameter in thegetOAuth2AuthorizationCode
function.URL Redirect Validation:
packages/bruno-electron/src/ipc/network/authorize-user-in-window.js
: TheonWindowRedirect
function now checks if the URL includes thecallbackUrl
before checking for an authorization code. This change ensures that thefinalUrl
is always thecallbackUrl
.Hash Generation:
packages/bruno-electron/src/ipc/network/oauth2-helper.js
: ThegenerateCodeChallenge
function has been renamed togenerateUniqueHash
and simplified. It now directly creates a SHA-256 hash of the input string and returns it in base64url format. This function is used to generate a unique hash for thecodeVerifier
and thestate
parameter.OAuth2 Authorization Code Retrieval:
packages/bruno-electron/src/ipc/network/oauth2-helper.js
: ThegetOAuth2AuthorizationCode
function now generates a unique state parameter using the session ID of the collection and includes this in the OAuth2 query parameters. This change adds an extra layer of security to the OAuth2 process by mitigating cross-site request forgery attacks.Contribution Checklist:
Note: Keeping the PR small and focused helps make it easier to review and merge. If you have multiple changes you want to make, please consider submitting them as separate pull requests.
Publishing to New Package Managers
Please see here for more information.