Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

chore: do not refresh tokens that have already failed refreshing#15608

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
Emyrk merged 7 commits intomainfromstevenmasley/refresh_token_spam
Nov 21, 2024

Conversation

Emyrk
Copy link
Member

For#14982

What this does

Once a token refresh fails, we remove theoauth_refresh_token from the database. This will prevent the token from hitting the IDP for subsequent refresh attempts.

Without this change, a bad script can cause a failing token to hit a remote IDP repeatedly with eachgit operation. With this change, after the first hit, subsequent hits will fail locally, and never contact the IDP.

The solution in both cases is to authenticate the external auth link. So the resolution is the same as before.

Note

When thinking about this originally, I added a column to cache the refresh error. That way I could persist the original error on subsequent calls. This method requires 2 columns, one for the error, the other for the(access_token, refresh_token) pair.

It adds more complexity, and in the end, the errors are all very generic "Refresh token is invalid" type errors. Which is no more actionable then our errortoken expired, refreshing is either disabled or refreshing failed and will not be retried.

So this solution requires no db schema changes, and prevents refresh token spam.

Once a token fails a refresh, discard the refresh token, and nevertry again.
@EmyrkEmyrk requested a review fromjohnstcnNovember 20, 2024 19:53
Comment on lines +1511 to +1528
var oauthErr *oauth2.RetrieveError
if errors.As(err, &oauthErr) {
if oauthErr.Response.StatusCode != 0 {
status = oauthErr.Response.StatusCode
}

rw.Header().Set("Content-Type", "application/x-www-form-urlencoded; charset=utf-8")
form := url.Values{
"error": {oauthErr.ErrorCode},
"error_description": {oauthErr.ErrorDescription},
"error_uri": {oauthErr.ErrorURI},
}
rw.WriteHeader(status)
_, _ = rw.Write([]byte(form.Encode()))
return
}

http.Error(rw, err.Error(), status)
Copy link
MemberAuthor

Choose a reason for hiding this comment

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

Added this to the fake IDP to construct proper oauth errors. This allows me to send a status code 200 with an oauth error. This is how github does it, which feels kinda strange, but wanted to make sure we support that behavior.

//
// Notes: Provider responses are not uniform. Here are some examples:
// Github
// - Returns a 200 with Code "bad_refresh_token" and Description "The refresh token passed is incorrect or expired."
Copy link
Member

Choose a reason for hiding this comment

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

thisisfine.jpg

Emyrk reacted with laugh emoji
Copy link
Member

@johnstcnjohnstcn left a comment
edited
Loading

Choose a reason for hiding this comment

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

Tested out on personal deployment after cherry-picking on top of 2.17.2, appears to work fine for me:shipit:

@EmyrkEmyrk merged commit78f9f43 intomainNov 21, 2024
27 checks passed
@EmyrkEmyrk deleted the stevenmasley/refresh_token_spam branchNovember 21, 2024 02:13
coadler pushed a commit that referenced this pull requestDec 3, 2024
…with dbcrypt (#15721)#15608 introduced a buggy behaviourwith dbcrypt enabled.When clearing an oauth refresh token, we had been setting the value tothe empty string.The database encryption package considers decrypting an empty string tobe an error, as an empty encrypted string value will still have a nonceassociated with it and thus not actually be empty when stored at rest.Instead of 'deleting' the refresh token, 'update' it to be the emptystring.This plays nicely with dbcrypt.It also adds a 'utility test' in the dbcrypt package to help encrypt avalue. This was useful when manually fixing users affected by this bugon our dogfood instance.
stirby pushed a commit that referenced this pull requestDec 3, 2024
…with dbcrypt (#15721)#15608 introduced a buggy behaviourwith dbcrypt enabled.When clearing an oauth refresh token, we had been setting the value tothe empty string.The database encryption package considers decrypting an empty string tobe an error, as an empty encrypted string value will still have a nonceassociated with it and thus not actually be empty when stored at rest.Instead of 'deleting' the refresh token, 'update' it to be the emptystring.This plays nicely with dbcrypt.It also adds a 'utility test' in the dbcrypt package to help encrypt avalue. This was useful when manually fixing users affected by this bugon our dogfood instance.(cherry picked from commite744cde)
@bpmctbpmct mentioned this pull requestJan 4, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@johnstcn

[8]ページ先頭

©2009-2025 Movatter.jp