mirror of
https://github.com/Buriburizaem0n/nezha_domains.git
synced 2026-02-04 04:30:05 +00:00
fix: possible redirect url inconsistency (#1003)
This commit is contained in:
@@ -51,7 +51,8 @@ func oauth2redirect(c *gin.Context) (*model.Oauth2LoginResponse, error) {
|
||||
if !has {
|
||||
return nil, singleton.Localizer.ErrorT("provider not found")
|
||||
}
|
||||
o2conf := o2confRaw.Setup(getRedirectURL(c))
|
||||
redirectURL := getRedirectURL(c)
|
||||
o2conf := o2confRaw.Setup(redirectURL)
|
||||
|
||||
randomString, err := utils.GenerateRandomString(32)
|
||||
if err != nil {
|
||||
@@ -62,6 +63,7 @@ func oauth2redirect(c *gin.Context) (*model.Oauth2LoginResponse, error) {
|
||||
Action: model.Oauth2LoginType(rTypeInt),
|
||||
Provider: provider,
|
||||
State: state,
|
||||
RedirectURL: redirectURL,
|
||||
}, cache.DefaultExpiration)
|
||||
|
||||
url := o2conf.AuthCodeURL(state, oauth2.AccessTypeOnline)
|
||||
@@ -138,7 +140,7 @@ func oauth2callback(jwtConfig *jwt.GinJWTMiddleware) func(c *gin.Context) (any,
|
||||
return nil, singleton.Localizer.ErrorT("code is required")
|
||||
}
|
||||
|
||||
openId, err := exchangeOpenId(c, o2confRaw, callbackData)
|
||||
openId, err := exchangeOpenId(c, o2confRaw, callbackData, state.RedirectURL)
|
||||
if err != nil {
|
||||
model.BlockIP(singleton.DB, realip, model.WAFBlockReasonTypeBruteForceOauth2, model.BlockIDToken)
|
||||
return nil, err
|
||||
@@ -188,8 +190,9 @@ func oauth2callback(jwtConfig *jwt.GinJWTMiddleware) func(c *gin.Context) (any,
|
||||
}
|
||||
}
|
||||
|
||||
func exchangeOpenId(c *gin.Context, o2confRaw *model.Oauth2Config, callbackData *model.Oauth2Callback) (string, error) {
|
||||
o2conf := o2confRaw.Setup(getRedirectURL(c))
|
||||
func exchangeOpenId(c *gin.Context, o2confRaw *model.Oauth2Config,
|
||||
callbackData *model.Oauth2Callback, redirectURL string) (string, error) {
|
||||
o2conf := o2confRaw.Setup(redirectURL)
|
||||
ctx := context.Background()
|
||||
|
||||
otk, err := o2conf.Exchange(ctx, callbackData.Code)
|
||||
|
||||
@@ -20,4 +20,5 @@ type Oauth2State struct {
|
||||
Action Oauth2LoginType
|
||||
Provider string
|
||||
State string
|
||||
RedirectURL string
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user