summaryrefslogtreecommitdiff
path: root/internal/handlers/response.go
diff options
context:
space:
mode:
authorJames Elliott <james-d-elliott@users.noreply.github.com>2021-12-02 13:21:46 +1100
committerGitHub <noreply@github.com>2021-12-02 13:21:46 +1100
commitbf9ab360bd8dd46739d4aa0018ceb4c08e05dba8 (patch)
tree530f43f59e3a4dc4c0bf0256b443c5777bb7142c /internal/handlers/response.go
parentf3f3b31b12a87586770c5cfaf646a9e85a724089 (diff)
refactor(handlers): utilize referer for auth logging rm/rd (#2655)
This utilizes the referrer query parameters instead of current request query parameters for logging the requested URI and method. Minor performance improvements to header peek/sets.
Diffstat (limited to 'internal/handlers/response.go')
-rw-r--r--internal/handlers/response.go15
1 files changed, 14 insertions, 1 deletions
diff --git a/internal/handlers/response.go b/internal/handlers/response.go
index 34a26860f..1f3f5220e 100644
--- a/internal/handlers/response.go
+++ b/internal/handlers/response.go
@@ -150,7 +150,20 @@ func markAuthenticationAttempt(ctx *middlewares.AutheliaCtx, successful bool, ba
// We only Mark if there was no underlying error.
ctx.Logger.Debugf("Mark %s authentication attempt made by user '%s'", authType, username)
- if err = ctx.Providers.Regulator.Mark(ctx, successful, bannedUntil != nil, username, string(ctx.RequestCtx.QueryArgs().Peek("rd")), string(ctx.RequestCtx.QueryArgs().Peek("rm")), authType, ctx.RemoteIP()); err != nil {
+ var (
+ requestURI, requestMethod string
+ )
+
+ referer := ctx.Request.Header.Referer()
+ if referer != nil {
+ refererURL, err := url.Parse(string(referer))
+ if err == nil {
+ requestURI = refererURL.Query().Get("rd")
+ requestMethod = refererURL.Query().Get("rm")
+ }
+ }
+
+ if err = ctx.Providers.Regulator.Mark(ctx, successful, bannedUntil != nil, username, requestURI, requestMethod, authType, ctx.RemoteIP()); err != nil {
ctx.Logger.Errorf("Unable to mark %s authentication attempt by user '%s': %+v", authType, username, err)
return err