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

fix: resilient social sign in #3011

Merged
merged 3 commits into from
Jan 10, 2023
Merged

fix: resilient social sign in #3011

merged 3 commits into from
Jan 10, 2023

Conversation

aeneasr
Copy link
Member

@aeneasr aeneasr commented Jan 10, 2023

Related issue(s)

Checklist

  • I have read the contributing guidelines.
  • I have referenced an issue containing the design document if my change
    introduces a new feature.
  • I am following the
    contributing code guidelines.
  • I have read the security policy.
  • I confirm that this pull request does not address a security
    vulnerability. If this pull request addresses a security vulnerability, I
    confirm that I got the approval (please contact
    [email protected]) from the maintainers to push
    the changes.
  • I have added tests that prove my fix is effective or that my feature
    works.
  • I have added or changed the documentation.

Further Comments

CaptainStandby
CaptainStandby previously approved these changes Jan 10, 2023
Copy link
Contributor

@CaptainStandby CaptainStandby left a comment

Choose a reason for hiding this comment

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

lgtm 👍

selfservice/strategy/oidc/provider_test.go Outdated Show resolved Hide resolved
@codecov
Copy link

codecov bot commented Jan 10, 2023

Codecov Report

Merging #3011 (fc258f8) into master (b50a222) will increase coverage by 0.93%.
The diff coverage is 79.54%.

@@            Coverage Diff             @@
##           master    #3011      +/-   ##
==========================================
+ Coverage   76.58%   77.52%   +0.93%     
==========================================
  Files         308      310       +2     
  Lines       19229    19216      -13     
==========================================
+ Hits        14727    14897     +170     
+ Misses       3401     3181     -220     
- Partials     1101     1138      +37     
Impacted Files Coverage Δ
selfservice/strategy/oidc/strategy.go 63.31% <0.00%> (-0.85%) ⬇️
selfservice/strategy/oidc/provider_dingtalk.go 31.52% <50.00%> (+31.52%) ⬆️
selfservice/strategy/oidc/provider_vk.go 73.91% <71.42%> (+73.91%) ⬆️
selfservice/strategy/oidc/error.go 75.00% <75.00%> (ø)
identity/credentials_oidc.go 87.50% <100.00%> (+2.50%) ⬆️
selfservice/strategy/oidc/provider.go 100.00% <100.00%> (ø)
selfservice/strategy/oidc/provider_auth0.go 71.87% <100.00%> (+8.38%) ⬆️
selfservice/strategy/oidc/provider_facebook.go 83.56% <100.00%> (+0.46%) ⬆️
selfservice/strategy/oidc/provider_gitlab.go 81.48% <100.00%> (+9.25%) ⬆️
selfservice/strategy/oidc/provider_microsoft.go 60.00% <100.00%> (+60.00%) ⬆️
... and 11 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Member

@zepatrik zepatrik left a comment

Choose a reason for hiding this comment

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

Looks very reasonable, and much needed 😅

@@ -17,3 +25,17 @@ var (
ErrAPIFlowNotSupported = herodot.ErrBadRequest.WithError("API-based flows are not supported for this method").
WithReasonf("Social Sign In and OpenID Connect are only supported for flows initiated using the Browser endpoint.")
)

func logUpstreamError(l *logrusx.Logger, resp *http.Response) error {
if resp.StatusCode == http.StatusOK {
Copy link
Member

Choose a reason for hiding this comment

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

Why not

Suggested change
if resp.StatusCode == http.StatusOK {
if resp.StatusCode / 100 == 2 {

in case the status code is some other 2XX?

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 point. I also thought of doing 200 >= x < 300 but decided against it. As far as I could tell from my research, all userinfo endpoints will return 200. Once exception might be a 3xx redirect, however that should be handled be the roundtripper. One problem with accepting all 200 is that we also accept 204 (no content) which would bring back the issue of an empty response body. 204 might be emitted when the service is having a disruption or something. So I think it makes sense to explicitly test for 200. For any service that doesn't return 200 but instead idk 201 (doesn't make sense though imo), we could adjust the logic. WDYT?

selfservice/strategy/oidc/error.go Outdated Show resolved Hide resolved
}

l.WithField("response_code", resp.StatusCode).WithField("response_body", string(body)).Error("The upstream OIDC provider returned a non 200 status code.")
return errors.WithStack(herodot.ErrInternalServerError.WithReasonf("OpenID Connect provider returned a %d status code but 200 is expected.", resp.StatusCode))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return errors.WithStack(herodot.ErrInternalServerError.WithReasonf("OpenID Connect provider returned a %d status code but 200 is expected.", resp.StatusCode))
return errors.WithStack(herodot.ErrInternalServerError.WithReasonf("OpenID Connect provider returned a %d status code but 2XX is expected.", resp.StatusCode))

@aeneasr aeneasr merged commit ca35b45 into master Jan 10, 2023
@aeneasr aeneasr deleted the fix-status-codes branch January 10, 2023 16:14
CNLHC pushed a commit to seekthought/kratos that referenced this pull request May 16, 2023
peturgeorgievv pushed a commit to senteca/kratos-fork that referenced this pull request Jun 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants