Skip to content

Commit

Permalink
Log invalid user as well
Browse files Browse the repository at this point in the history
  • Loading branch information
Mygod committed Jul 20, 2023
1 parent a29f011 commit 4e71e85
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions forwardproxy.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import (
"strings"
"sync"
"time"
"unicode/utf8"

caddy "github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig/caddyfile"
Expand Down Expand Up @@ -421,6 +422,18 @@ func (h Handler) checkCredentials(r *http.Request) error {
return nil
}
}
buf := make([]byte, base64.StdEncoding.DecodedLen(len([]byte(pa[1]))))
n, err := base64.StdEncoding.Decode(buf, []byte(pa[1]))
if err == nil && utf8.Valid(buf[:n]) {
cred := string(buf[:n])
i := strings.IndexByte(cred, ':')
repl := r.Context().Value(caddy.ReplacerCtxKey).(*caddy.Replacer)
if i >= 0 {
repl.Set("http.auth.user.id", "invalid:"+cred[:i])
} else {
repl.Set("http.auth.user.id", "invalidformat:"+cred)
}
}
return errors.New("invalid credentials")
}

Expand Down

0 comments on commit 4e71e85

Please sign in to comment.