You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
proxy: credentials_by_user_agent matches the user agent the wrong way round #4091
The proxy setting auth_middleware.credentials_by_user_agent is meant to limit the WWW-Authenticate challenges of a 401 to one method for clients whose user agent contains a configured key, e.g. mirall: basic for the desktop client. The proxy compares the other way round, strings.Contains(key, userAgent), so the lock-in only applies when the user agent is part of the key:
A real desktop client (Mozilla/5.0 (…) mirall/<version> (…)) never matches mirall, and still gets all challenges.
A request without a user agent, or with a short one such as mir, matches every key, and gets only the configured method. With several keys, the method is picked at random (map order) and changes from request to request.
The default (empty map) isn't affected. The setting only changes the advertised challenges, not which credentials are accepted.
Steps to reproduce
Reproduced on main (d43947a209), otherwise with the default config.
services/proxy/pkg/middleware/authentication.go, in Authentication (the loop over options.CredentialsByUserAgent) and in evalRequestURI (for /ocs/v[12].php/cloud/). Neither has a test.
Fix: match with strings.Contains(r.UserAgent(), key) and skip an empty user agent, as the frontend's reva auth middleware already does (getCredsForUserAgent); share one helper between both places, pick the longest matching key so that the result doesn't depend on map order, and add tests.
Activity