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

OAuth2: add a nonce to the state parameter #35919

Merged
merged 44 commits into from
Sep 16, 2024

Conversation

zhaohuabing
Copy link
Member

@zhaohuabing zhaohuabing commented Aug 30, 2024

Commit Message: This PR adds a nonce to the state parameter of the oauth2 requests to mitigate the risk of CSRF.
Additional Description:
Risk Level: low
Testing: Unit and Integration test
Docs Changes: API docs: add a new oauth_nonce to the OAuth2Credentials.CookieNames proto API.
Release Notes: Yes
Platform Specific Features: No
[Optional Runtime guard:]
[Optional Fixes #Issue] Implement #35232 #29526
[Optional Fixes commit #PR or SHA]
[Optional Deprecated:]
[Optional API Considerations:]

The diagram below shows how nonce works within the oauth2 flow, with the red annotations highlighting the changes introduced in this PR.
Untitled-2024-05-19-1553

Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
@zhaohuabing zhaohuabing marked this pull request as draft August 30, 2024 10:49
@zhaohuabing zhaohuabing changed the title OAuth2: add a nonce to state parameter OAuth2: add a nonce to the state parameter Aug 31, 2024
Signed-off-by: Huabing Zhao <[email protected]>
Copy link

CC @envoyproxy/api-shepherds: Your approval is needed for changes made to (api/envoy/|docs/root/api-docs/).
envoyproxy/api-shepherds assignee is @wbpcode
CC @envoyproxy/api-watchers: FYI only for changes made to (api/envoy/|docs/root/api-docs/).

🐱

Caused by: #35919 was synchronize by zhaohuabing.

see: more, trace.

Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
Signed-off-by: Huabing Zhao <[email protected]>
@phlax
Copy link
Member

phlax commented Sep 4, 2024

@zhaohuabing would you be able to fix the example first?

@zhaohuabing
Copy link
Member Author

zhaohuabing commented Sep 4, 2024

@zhaohuabing would you be able to fix the example first?

@phlax
Yes, I can, but some of the verifications in the example need to be temporarily disabled. This is because the content of the state parameter has changed, and the current OAuth2 filter's verification of the state differs from the new implementation. Once this PR is merged, I will re-enable those verifications in the examples.

@phlax
Copy link
Member

phlax commented Sep 4, 2024

hmm - was just looking - i guess my main concern is that the PR lands and breaks both repos

not sure if resolution is trivial - ie assuming the nonce is not predictable - might require some hackery on the responds_with_header fun

@zhaohuabing
Copy link
Member Author

zhaohuabing commented Sep 4, 2024

hmm - was just looking - i guess my main concern is that the PR lands and breaks both repos

not sure if resolution is trivial - ie assuming the nonce is not predictable - might require some hackery on the responds_with_header fun

Yes, the nonce is not predictable. But we can change the verification to just check the presence of the state, not the value of the nonce, like what we currently do to the auth code.

If this approach is acceptable, I will raise a PR to the example repository to fix the example accordingly.

@phlax
Copy link
Member

phlax commented Sep 4, 2024

could you raise the PR now, so its ready to go?

this will also need to be resolved for the fix to work - #35954

Signed-off-by: Huabing Zhao <[email protected]>
@repokitteh-read-only repokitteh-read-only bot added the deps Approval required for changes to Envoy's external dependencies label Sep 5, 2024
Copy link

CC @envoyproxy/dependency-shepherds: Your approval is needed for changes made to (bazel/.*repos.*\.bzl)|(bazel/dependency_imports\.bzl)|(api/bazel/.*\.bzl)|(.*/requirements\.txt)|(.*\.patch).
envoyproxy/dependency-shepherds assignee is @phlax

🐱

Caused by: #35919 was synchronize by zhaohuabing.

see: more, trace.

Copy link
Member

@wbpcode wbpcode left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution. A comment is added. I am not familiar to oauth2. So, may be we need to defer this code review to others. Or I need to take more time to read the oauth2 first.

/wait

Comment on lines +55 to +58

// Cookie name to hold the nonce value. Defaults to ``OauthNonce``.
string oauth_nonce = 6
[(validate.rules).string = {well_known_regex: HTTP_HEADER_NAME ignore_empty: true}];
Copy link
Member

Choose a reason for hiding this comment

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

if there a way to disable this new feature? Or is this has any possible side effect?

Copy link
Member Author

Choose a reason for hiding this comment

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

Enabling this by default enhances the security posture of the OAuth2 filter. This practice is also recommended by the OAuth2 spec: https://datatracker.ietf.org/doc/html/rfc6819#section-5.3.5. So my preference is that we enable this since this release and don't provide an option to disable it unless there is a particular reason asking for it.

There are no side effects, as the nonce is transparent to both the end users and the applications.

Copy link
Member

Choose a reason for hiding this comment

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

got it. Thanks.

source/extensions/filters/http/oauth2/filter.cc Outdated Show resolved Hide resolved
Signed-off-by: Huabing Zhao <[email protected]>
@wbpcode
Copy link
Member

wbpcode commented Sep 9, 2024

/lgtm api

@repokitteh-read-only repokitteh-read-only bot removed the api label Sep 9, 2024
@zhaohuabing
Copy link
Member Author

Thanks for the contribution. A comment is added. I am not familiar to oauth2. So, may be we need to defer this code review to others. Or I need to take more time to read the oauth2 first.

/wait

Hi @derekargueta @mattklein123 could you please help review this PR when you have a moment? I noticed that you're listed as owners of the OAuth2 filter in the CODEOWNERS file. Thank you so much for your time and assistance!

@mattklein123 mattklein123 self-assigned this Sep 12, 2024
@mattklein123 mattklein123 merged commit b6c24ab into envoyproxy:main Sep 16, 2024
40 checks passed
@zhaohuabing zhaohuabing deleted the nonce-state branch September 18, 2024 01:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
deps Approval required for changes to Envoy's external dependencies
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants