file: enforce Basic Auth realms for URL-prefix handlers#31
Open
hauke wants to merge 1 commit into
Open
Conversation
uh_handle_request() selects check_url dispatch handlers (lua, ucode and ubus) via dispatch_find(url, NULL) and invokes them through uh_invoke_handler() before reaching __handle_file_request(), which holds the only uh_auth_check() call. As a result a configured Basic Auth realm was never evaluated for those handlers: a request to a lua/ucode/ubus prefix was served without authentication, and even invalid credentials were ignored. CGI scripts are not affected because they register a check_path handler and fall through to the authenticated file path, so the same realm protected /cgi-bin/foo but silently not /api/foo. Evaluate the matching realm against the request URL before invoking a check_url handler. uh_auth_check() already emits the 401 challenge and tears the request down on failure, so handlers stay consistent with the static file and CGI paths. Deployments without a realm covering the prefix are unaffected. Link: https://github.com/openwrt/uhttpd/security/advisories/GHSA-5cgm-8h9x-v28c Reported-by: @aramosf Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Hauke Mehrtens <hauke@hauke-m.de>
jow-
reviewed
Jul 20, 2026
| * before the file/CGI path that performs uh_auth_check(). | ||
| * Enforce any matching Basic Auth realm so these handlers are | ||
| * protected consistently with static files and CGI scripts. */ | ||
| if (!uh_auth_check_url(cl, url)) |
Contributor
There was a problem hiding this comment.
The return without expression followed by the return-with-function-call-returning-void looks a bit weird, even if technically correct, but it'll likely let casual readers stumble.
I suggest writing it like this:
if (d) {
/* check_url handlers (lua, ucode, ubus) are dispatched here,
* before the file/CGI path that performs uh_auth_check().
* Enforce any matching Basic Auth realm so these handlers are
* protected consistently with static files and CGI scripts. */
if (uh_auth_check_url(cl, url))
uh_invoke_handler(cl, d, url, NULL);
return;
}
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
uh_handle_request() selects check_url dispatch handlers (lua, ucode and ubus) via dispatch_find(url, NULL) and invokes them through uh_invoke_handler() before reaching __handle_file_request(), which holds the only uh_auth_check() call. As a result a configured Basic Auth realm was never evaluated for those handlers: a request to a lua/ucode/ubus prefix was served without authentication, and even invalid credentials were ignored. CGI scripts are not affected because they register a check_path handler and fall through to the authenticated file path, so the same realm protected /cgi-bin/foo but silently not /api/foo.
Evaluate the matching realm against the request URL before invoking a check_url handler. uh_auth_check() already emits the 401 challenge and tears the request down on failure, so handlers stay consistent with the static file and CGI paths. Deployments without a realm covering the prefix are unaffected.
Link: https://github.com/openwrt/uhttpd/security/advisories/GHSA-5cgm-8h9x-v28c
Reported-by: @aramosf
Assisted-by: Claude:claude-opus-4-8