Skip to content

Commit 9a2ba1d

Browse files
authored
fix(server): add missing return after error responses (#2150)
In BeginAuthnRegistration (webauthn.go), missing return statements after error responses caused the function to continue executing with a nil authnInstance, potentially leading to a nil pointer panic. In OIDCLoginCallback and SSOLoginCallback (ssologin.go), missing return statements after GenerateToken/autoRegister errors caused the handler to send a second response, resulting in a superfluous response write. In SetThunderBrowser (offline_download.go), the default case of the storage type switch sent an error response but did not return, causing SaveSettingItems and tool initialization to continue executing even when driver type validation failed.
1 parent f3428e6 commit 9a2ba1d

File tree

3 files changed

+7
-0
lines changed

3 files changed

+7
-0
lines changed

server/handles/offline_download.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ func SetThunderBrowser(c *gin.Context) {
448448
case *thunder_browser.ThunderBrowser, *thunder_browser.ThunderBrowserExpert:
449449
default:
450450
common.ErrorStrResp(c, "unsupported storage driver for offline download, only ThunderBrowser is supported", 400)
451+
return
451452
}
452453
}
453454
items := []model.SettingItem{

server/handles/ssologin.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,11 +256,13 @@ func OIDCLoginCallback(c *gin.Context) {
256256
user, err = autoRegister(userID, userID, err)
257257
if err != nil {
258258
common.ErrorResp(c, err, 400)
259+
return
259260
}
260261
}
261262
token, err := common.GenerateToken(user)
262263
if err != nil {
263264
common.ErrorResp(c, err, 400)
265+
return
264266
}
265267
if useCompatibility {
266268
c.Redirect(302, common.GetApiUrl(c)+"/@login?token="+token)
@@ -427,6 +429,7 @@ func SSOLoginCallback(c *gin.Context) {
427429
token, err := common.GenerateToken(user)
428430
if err != nil {
429431
common.ErrorResp(c, err, 400)
432+
return
430433
}
431434
if usecompatibility {
432435
c.Redirect(302, common.GetApiUrl(c)+"/@login?token="+token)

server/handles/webauthn.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,17 +130,20 @@ func BeginAuthnRegistration(c *gin.Context) {
130130
authnInstance, err := authn.NewAuthnInstance(c)
131131
if err != nil {
132132
common.ErrorResp(c, err, 400)
133+
return
133134
}
134135

135136
options, sessionData, err := authnInstance.BeginRegistration(user)
136137

137138
if err != nil {
138139
common.ErrorResp(c, err, 400)
140+
return
139141
}
140142

141143
val, err := json.Marshal(sessionData)
142144
if err != nil {
143145
common.ErrorResp(c, err, 400)
146+
return
144147
}
145148

146149
common.SuccessResp(c, gin.H{

0 commit comments

Comments
 (0)