Skip to content

Token endpoint logs client errors (e.g. invalid_client) at error level since v26 (follow-up to #4095) #4142

Open

Description

@jepp3

Preflight checklist

Describe the bug

Since commit 502b8cc ("chore: remove unused log code"), oauth2TokenExchange calls x.LogError unconditionally when NewAccessRequest fails:

accessRequest, err := h.r.OAuth2Provider().NewAccessRequest(ctx, r, session)
if err != nil {
    x.LogError(r, err, h.r.Logger())
    h.r.OAuth2Provider().WriteAccessError(ctx, w, accessRequest, err)
    ...

As a result, every client mistake on the token endpoint (unknown client_id, wrong secret, expired refresh token, invalid grant) is logged as level=error, msg="An error occurred".

Before v26 (verified in the source of v1.11.10, v2.0.3 and v25.4.0, and by running v25.4.0), logOrAudit only sent ErrServerError, ErrTemporarilyUnavailable and ErrMisconfiguration to x.LogError. Everything else was logged at info.

In #4095 a maintainer said these logs are noise and would be fixed in the next release. v26.2.0 is still the latest release, and that issue only covers /oauth2/auth.

Reproducing the bug

docker run -d -p 4444:4444 -e DSN=memory -e LOG_FORMAT=json \
  -e SECRETS_SYSTEM=thisisaverylongsecretforlocaltesting \
  oryd/hydra:v26.2.0 serve all --dev

curl -X POST http://localhost:4444/oauth2/token \
  -d 'grant_type=client_credentials&client_id=does-not-exist&client_secret=x'
# → 401 {"error":"invalid_client", ...}

v26.2.0 logs:

{"audience":"application","error":{"debug":"Unable to locate the resource","message":"invalid_client","reason":"","status":"Unauthorized","status_code":401},"http_request":{"method":"POST","path":"/oauth2/token", ...},"level":"error","msg":"An error occurred","service_version":"v26.2.0"}

The same request against v25.4.0 logs:

{"audience":"application","error":{"debug":"Unable to locate the resource","message":"invalid_client","reason":"","status":"Unauthorized","status_code":401},"http_request":{"method":"POST","path":"/oauth2/token", ...},"level":"info","msg":"access denied","service_version":"v25.4.0"}

The level went from info to error for the same 401 client error.

Expected behavior

4xx client errors on the token endpoint are logged at info or debug, as before v26. Only 5xx (server error, temporarily unavailable, misconfiguration) are logged at error level. Otherwise the error level can't be used for alerting, and one misconfigured client can fill the error logs.

Does the planned fix for #4095 also cover /oauth2/token, introspection and the device flow, which 502b8cc switched to x.LogError too?

Version

v26.2.0 (oryd/hydra:v26.2.0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions