authelia: Client Assertion fails with jti was already used error on first use.

Version

v4.38.10

Deployment Method

Docker

Reverse Proxy

Traefik

Reverse Proxy Version

2.11.7

Description

When attempting to use pushed authentication requests for oidc clients, using token_endpoint_auth_method: private_key_jwt with a registered public key for validating the incoming jwt client assertion, every client assertion is refused with an error that includes a suspicious sql error.

Pushed Authorization Request failed with error: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The requested OAuth 2.0 Client could not be authenticated. The jti was already used. Claim 'jti' from 'client_assertion' MUST only be used once. error selecting oauth2 blacklisted JTI with signature '': sql: no rows in result set

My suspicion is that LoadOAuth2PARContext from sql_provider.go is creating it’s own error rather than raising the sql.ErrNoRows which is expected by ClientAssertionJWTValid in store.go which ultimately leads to all jtis being rejected.

sql_provider.go reference

https://github.com/authelia/authelia/blob/95e3ea73be1e92823a93da7b1c00b96e938ed953/internal/storage/sql_provider.go#L1250-L1264

store.go reference

https://github.com/authelia/authelia/blob/95e3ea73be1e92823a93da7b1c00b96e938ed953/internal/oidc/store.go#L117-L134

client_authentication_strategy.go reference

https://github.com/authelia/oauth2-provider/blob/acbadb6280d549dc7cd67c5a50a0dc54b15e94a8/client_authentication_strategy.go#L243-L277

Reproduction

I have reproduced this several times using the local example with the following sanitized client configuration.

My client application is python code that generates a unique RSA keypair per client and a unique uuid-based jti per request. The code is not publishable at this time, but I have verified that the client_assertion is correctly formed and signed by using https://jwt.io.


identity_providers:
  oidc:
    clients:
      - client_id: 'example-two'
        public: false
        require_pkce: true
        pkce_challenge_method: 'S256'
        redirect_uris:
          - 'https://federation.example.com/callback'
        scopes:
          - 'offline_access'
          - 'offline'
          - 'authelia.bearer.authz'
        audience:
          - 'https://app1.example.com'
          - 'https://app2.example.com'
        grant_types:
          - 'authorization_code'
          - 'refresh_token'
        response_types:
          - 'code'
        response_modes:
          - 'form_post'
        consent_mode: 'explicit'
        require_pushed_authorization_requests: true
        # https://www.authelia.com/configuration/identity-providers/openid-connect/clients/#token_endpoint_auth_method
        # client_secret_basic, client_secret_post, client_secret_jwt, private_key_jwt, or none
        token_endpoint_auth_method: 'private_key_jwt' 
        token_endpoint_auth_signing_alg: 'RS256'
        access_token_signed_response_key_id: 'example-key'
        jwks:
          - key_id: 'example-client-1'
            algorithm: 'RS256'
            use: 'sig'
            key: |
              -----BEGIN PUBLIC KEY-----
               <SNIP>
              -----END PUBLIC KEY-----

Expectations

No response

Configuration (Authelia)

No response

Build Information

Last Tag: v4.38.10
State: tagged clean
Branch: v4.38.10
Commit: b7d5e3ff29917bd0842c8509b4a8338d19f2934e
Build Number: 31324
Build OS: linux
Build Arch: arm64
Build Compiler: gc
Build Date: Sun, 04 Aug 2024 22:15:26 +1000
Extra:

Go:
    Version: go1.22.2
    Module Path: github.com/authelia/authelia/v4
    Executable Path: github.com/authelia/authelia/v4/cmd/authelia

Logs (Authelia)

2024-08-30 14:26:09 time="2024-08-31T04:26:09+10:00" level=error msg="Pushed Authorization Request failed with error: Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The requested OAuth 2.0 Client could not be authenticated. The jti was already used. Claim 'jti' from 'client_assertion' MUST only be used once. error selecting oauth2 blacklisted JTI with signature '': sql: no rows in result set" method=POST path=/api/oidc/pushed-authorization-request remote_ip=192.168.65.1 stack="github.com/authelia/authelia/v4/internal/handlers/handler_oidc_authorization.go:176          OpenIDConnectPushedAuthorizationRequest\ngithub.com/authelia/authelia/v4/internal/middlewares/http_to_authelia_handler_adaptor.go:114 handleRouter.NewHTTPToAutheliaHandlerAdaptor.func23\ngithub.com/authelia/authelia/v4/internal/middlewares/bridge.go:54                            handleRouter.(*BridgeBuilder).Build.func16.1\ngithub.com/authelia/authelia/v4/internal/middlewares/headers.go:91                           SecurityHeadersNoStore.func1\ngithub.com/authelia/authelia/v4/internal/middlewares/headers.go:75                           SecurityHeadersCSPNoneOpenIDConnect.func1\ngithub.com/authelia/authelia/v4/internal/middlewares/headers.go:30                           SecurityHeadersBase.func1\ngithub.com/authelia/authelia/v4/internal/middlewares/cors.go:216                             handleRouter.(*CORSPolicy).Middleware.func24\ngithub.com/fasthttp/router@v1.5.2/router.go:441                                              (*Router).Handler\ngithub.com/authelia/authelia/v4/internal/middlewares/log_request.go:14                       handleRouter.LogRequest.func40\ngithub.com/authelia/authelia/v4/internal/middlewares/errors.go:38                            RecoverPanic.func1\ngithub.com/valyala/fasthttp@v1.55.0/server.go:2379                                           (*Server).serveConn\ngithub.com/valyala/fasthttp@v1.55.0/workerpool.go:224                                        (*workerPool).workerFunc\ngithub.com/valyala/fasthttp@v1.55.0/workerpool.go:196                                        (*workerPool).getCh.func1\nruntime/asm_arm64.s:1222

Logs (Proxy / Application)

No response

Documentation

No response

Pre-Submission Checklist

  • I agree to follow the Code of Conduct

  • This is a bug report and not a support request

  • I have read the security policy and this bug report is not a security issue or security related issue

  • I have either included the complete configuration file or I am sure it’s unrelated to the configuration

  • I have either included the complete debug / trace logs or the output of the build-info command if the logs are not relevant

  • I have provided all of the required information in full with the only alteration being reasonable sanitization in accordance with the Troubleshooting Sanitization reference guide

  • I have checked for related proxy or application logs and included them if available

  • I have checked for related issues and checked the documentation

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 17 (10 by maintainers)

Commits related to this issue

Most upvoted comments

Thanks a lot, fixed in 561d34fb47d9b73f6caa478b2482a1e0243eb1ae by a linter. The work in implementing them is paying for itself.

Thanks for the detailed report, pretty sure this is accurate without even looking. but I’ll add a test to confirm and then fix it.