Skip to content

Commit 472f592

Browse files
committed
fix: Dont panic if not sso account on legacy validate session
1 parent a81f63f commit 472f592

2 files changed

Lines changed: 4 additions & 15 deletions

File tree

internal/domains/accounts.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func (d *AccountsDomain) GetAccountByUsername(ctx context.Context, username stri
4141
return nil, fmt.Errorf("error getting accounts: %v", err)
4242
}
4343
if len(accounts) != 1 {
44-
return nil, fmt.Errorf("got more none or more than one account by username: %s", username)
44+
return nil, fmt.Errorf("got none or more than one account by username: %s", username)
4545
}
4646

4747
return model.Ptr(accounts[0].ToDTO()), nil

internal/webserver/handler.go

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func (h *Handler) validateSession(r *http.Request) error {
5454
if h.dependencies.Config().Http.SSOProxyAuth {
5555
account, err = h.ssoAccount(r)
5656
if err != nil {
57-
return err
57+
h.dependencies.Logger().WithError(err).Error("getting sso account")
5858
}
5959
}
6060

@@ -116,18 +116,12 @@ func (h *Handler) ssoAccount(r *http.Request) (*model.AccountDTO, error) {
116116
if errors.As(err, &addrErr) && addrErr.Err == "missing port in address" {
117117
ip = remoteAddr
118118
} else {
119-
h.dependencies.Logger().
120-
WithError(err).
121-
WithField("remote_addr", remoteAddr).
122-
WithField("method", r.Method).
123-
WithField("path", r.URL.Path).
124-
Error("Could not parse remote ip")
125-
return nil, nil
119+
return nil, err
126120
}
127121
}
128122
requestIP := net.ParseIP(ip)
129123
if !h.isTrustedIP(requestIP) {
130-
return nil, nil
124+
return nil, fmt.Errorf("'%s' is not a trusted ip", r.RemoteAddr)
131125
}
132126

133127
headerName := h.dependencies.Config().Http.SSOProxyAuthHeaderName
@@ -138,11 +132,6 @@ func (h *Handler) ssoAccount(r *http.Request) (*model.AccountDTO, error) {
138132

139133
account, err := h.dependencies.Domains().Accounts().GetAccountByUsername(r.Context(), userName)
140134
if err != nil {
141-
h.dependencies.Logger().
142-
WithError(err).
143-
WithField("method", r.Method).
144-
WithField("path", r.URL.Path).
145-
Error("Failed to get account from sso header")
146135
return nil, err
147136
}
148137

0 commit comments

Comments
 (0)