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

Commit4c9ccde

Browse files
committed
add refresh token validation
1 parent7110ef1 commit4c9ccde

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

‎coderd/oauth2provider/revoke.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818
"github.com/coder/coder/v2/coderd/database/dbauthz"
1919
"github.com/coder/coder/v2/coderd/httpapi"
2020
"github.com/coder/coder/v2/coderd/httpmw"
21+
"github.com/coder/coder/v2/coderd/userpassword"
2122
)
2223

2324
var (
@@ -28,6 +29,12 @@ var (
2829
)
2930

3031
// RevokeToken implements RFC 7009 OAuth2 Token Revocation
32+
// Authentication is unique for this endpoint in that it does not use the
33+
// standard token authentication middleware. Instead, it expects the token that
34+
// is being revoked to be valid.
35+
// TODO: Currently the token validation occurs in the revocation logic itself.
36+
// This code should be refactored to share token validation logic with other parts
37+
// of the OAuth2 provider/http middleware.
3138
funcRevokeToken(db database.Store,logger slog.Logger) http.HandlerFunc {
3239
returnfunc(rw http.ResponseWriter,r*http.Request) {
3340
ctx:=r.Context()
@@ -126,6 +133,14 @@ func revokeRefreshTokenInTx(ctx context.Context, db database.Store, token string
126133
returnxerrors.Errorf("get oauth2 provider app token by prefix: %w",err)
127134
}
128135

136+
equal,err:=userpassword.Compare(string(dbToken.RefreshHash),parsedToken.Secret)
137+
iferr!=nil {
138+
returnxerrors.Errorf("invalid refresh token: %w",err)
139+
}
140+
if!equal {
141+
returnxerrors.Errorf("invalid refresh token")
142+
}
143+
129144
// Verify ownership
130145
//nolint:gocritic // Using AsSystemOAuth2 for OAuth2 public token revocation endpoint
131146
appSecret,err:=db.GetOAuth2ProviderAppSecretByID(dbauthz.AsSystemOAuth2(ctx),dbToken.AppSecretID)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp