vmauth: JWT-authenticated user with unmatched path gets "missing 'Authorization' request header" instead of "missing route"

Author: Crazy-HopperCreated Sep 7, 2026Updated Sep 30, 2026
Labelsbugvmauthcompletedjwt

Describe the bug

Note: This report was drafted by an AI coding assistant (Claude) on my behalf, based on reading the vmauth source.

When a request is successfully authenticated via jwt/OIDC (matchClaims matched, token valid) but the requested path is not covered by that VMUser's url_map/src_paths, vmauth responds with:

401 Unauthorized
WWW-Authenticate: Basic realm="Restricted"
missing 'Authorization' request header

This is misleading — the client did send a valid Authorization: Bearer <id_token> and was correctly authenticated; only the route lookup failed. The expected/consistent behavior (and what happens for Basic Auth / static bearer-token users in the identical situation) is:

400 Bad Request
user <username> missing route for "<path>"

Root cause

In app/vmauth/main.go, processRequest():

go
if up == nil {
    if ui.DefaultURL == nil {
        // Authorization should be requested for http requests without credentials
        // to a route that is not in the configuration for unauthorized user.
        // See https://github.com/VictoriaMetrics/VictoriaMetrics/issues/5236
        if ui.BearerToken == "" && ui.Username == "" && len(*authUsers.Load()) > 0 {
            handleMissingAuthorizationError(w)
            return
        }
        missingRouteRequests.Inc()
        ...
        httpserver.Errorf(w, r, "user %s missing route for %q%s", userName, u.String(), di)
        return
    }

This check was added in #5236 to make browsers show a native Basic-Auth login prompt when the anonymous unauthorized_user hits an unconfigured path (that UserInfo naturally has empty BearerToken/Username). However, a VMUser configured purely via jwt/matchClaims also has empty BearerToken and Username fields (JWT users don't use these fields at all), so this check can't distinguish "genuinely anonymous request" from "authenticated JWT user whose token just doesn't cover this path." Both fall into the same branch, producing the wrong error message and status code for the JWT case.

Expected behavior

The check should also require ui.JWT == nil (or otherwise verify the user was actually resolved via static credentials, not JWT), e.g.:

go
if ui.BearerToken == "" && ui.Username == "" && ui.JWT == nil && len(*authUsers.Load()) > 0 {

so that JWT-authenticated users always get the precise missing route error, matching Basic Auth / static bearer-token behavior.

To Reproduce

  1. Configure a VMUser/user entry with jwt.oidc/matchClaims and a url_map restricted to specific paths.
  2. Authenticate with a valid token matching matchClaims.
  3. Request a path outside that user's url_map.
  4. Observe 401 + missing 'Authorization' request header instead of 400 + missing route for "<path>".

Version

vmauth-20260717-112718-tags-v1.148.0-0-gd94a85a405

Logs

No response

Screenshots

No response

Used command-line flags

/vmauth-prod
-auth.config=/opt/vmauth/config.yaml
-flagsAuthKey=file:///etc/vm/secrets/vmauth-creds/flagsAuthKey
-httpAuthHeader=Authorization,X-Basic-Auth
-httpListenAddr=:8427
-logInvalidAuthTokens=true
-loggerFormat=json
-loggerLevel=INFO
-metricsAuthKey=file:///etc/vm/secrets/vmauth-creds/metricsAuthKey
-pprofAuthKey=file:///etc/vm/secrets/vmauth-creds/pprofAuthKey
-reloadAuthKey=file:///etc/vm/config-reload-auth/reloadAuthKey

Additional information

No response

Source: VictoriaMetrics/VictoriaMetrics