authelia: ERROR: value too long for type character varying(8) (`authentication_log`.`request_method`)

Bug Report

Description

I’m using Authelia with caddy server 2.5.1, using the new forward_auth directive. I have Authelia hosted at authelia.mydomain.com, and a wiki hosted at wiki.mydomain.com. Logging in to Authelia directly via authelia.mydomain.com works without issue, and once logged in, I’m able to access wiki.mydomain.com.

If I’m not logged in, when I try to access wiki.mydomain.com, I’m correctly redirected to the Authelia login page. All authentication attempts fail at this point, because of a SQL error (I’m using Postgres): ERROR: value too long for type character varying(8).

Expected Behaviour

Authentication with proper credentials should succeed, even if the redirect query param is set!

Additional Information

Relevant software:

  • Authelia v4.35.5
  • Caddy v2.5.1
  • Postgres v14.3

Error logs:

time="2022-06-04T23:38:55-04:00" level=debug msg="Mark 1FA authentication attempt made by user '<REDACTED>'" method=POST path=/api/firstfactor remote_ip=<REDACTED>
time="2022-06-04T23:38:55-04:00" level=error msg="Unable to mark 1FA authentication attempt by user '<REDACTED>': error inserting authentication attempt for user '<REDACTED>': ERROR: value too long for type character varying(8) (SQLSTATE 22001)" method=POST path=/api/firstfactor remote_ip=<REDACTED>
stack="github.com/authelia/authelia/v4/internal/handlers/response.go:223           markAuthenticationAttempt
github.com/authelia/authelia/v4/internal/handlers/handler_firstfactor.go:68 FirstFactorPOST.func1
github.com/authelia/authelia/v4/internal/middlewares/authelia_context.go:53 AutheliaMiddleware.func1.1
github.com/authelia/authelia/v4/internal/middlewares/headers.go:25          SecurityHeadersCSPNone.func1
github.com/authelia/authelia/v4/internal/middlewares/headers.go:35          SecurityHeadersNoStore.func1
github.com/authelia/authelia/v4/internal/middlewares/headers.go:16          SecurityHeaders.func1
github.com/fasthttp/router@v1.4.9/router.go:414                             (*Router).Handler
github.com/valyala/fasthttp@v1.36.0/http.go:153                             (*Response).StatusCode
github.com/valyala/fasthttp@v1.36.0/server.go:2338                          (*Server).serveConn
github.com/valyala/fasthttp@v1.36.0/workerpool.go:224                       (*workerPool).workerFunc
github.com/valyala/fasthttp@v1.36.0/workerpool.go:196                       (*workerPool).getCh.func1
runtime/asm_amd64.s:1571                                                    goexit"

The field that the error message is referring to is the request_method field of the authentication_logs table. It appears that Authelia is attempting to write a much longer string than just the HTTP method name in this situation. Here’s an example:

GET, https://authelia.mydomain.com/?rd=https://wiki.mydomain.com/,GET

For now, I was able to resolve this by altering the column type to be character varying(150).

Here’s my Caddy configuration, in case it’s relevant (I’m not sure where this “request_method” string is coming from, Authelia or Caddy):

authelia.shanemoore.me {
  reverse_proxy <REDACTED>
}

wiki.shanemoore.me {
  forward_auth <REDACTED (Authelia address and port)> {
    uri /api/verify?rd=https://authelia.mydomain.com
    copy_headers Remote-User Remote-Groups Remote-Name Remote-Email
  }
  @localnet {
    remote_ip 127.0.0.1 192.168.0.0/16 172.16.0.0/12 10.0.0.0/8
  }

  reverse_proxy @localnet <REDACTED>
}

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 19 (11 by maintainers)

Most upvoted comments

How peculiar. I’ll setup a debug version to see if this issue is originating with Authelia or Caddy. Probably the same image.

Can you try uri /api/verify?rd=https%3A%2F%2Fauth.example.com? Basically %3A%2F%2F instead of ://.