Repository navigation
Keep the query string on index redirects - #729
Merged
AlbertShown merged 1 commit intoNov 26, 2026
Merged
Conversation
When WebUI answers `/` or a folder URL with a 302 to the index file, it passed only the index path to `mg_send_http_redirect()` and dropped the request's query string. `/?a=1&b=2` landed on `index.html` without `?a=1&b=2`, so deep links and callback URLs that carry their state in the query lost it. This affected both the local root-folder mode (`_webui_http_handler()`: the `/` index and the subfolder index) and the custom file handler mode (`_webui_external_file_handler()`: the start-file rewrite and the folder-index probe). A new internal helper, `_webui_http_redirect_keep_query()`, now sends these four redirects and appends the original query to the Location. The query is still percent-encoded as received, so it is passed through unchanged; only bytes outside visible ASCII and `#` are percent-encoded, which keeps the Location a single header line and stops `#` from turning into a fragment. Queries longer than 8 KiB are answered with 414 instead of being echoed back. Redirects without a query are unchanged. The public API and ABI are unchanged; the helper is static and no header or exported symbol changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
AlbertShown
approved these changes
Nov 26, 2026
Member
|
Thank you @ViktorJannicke |
ViktorJannicke
added a commit
to Runic-Artifex/cs-webui
that referenced
this pull request
Nov 26, 2026
#37) * Adopt the official WebUI nightly 8a55352c2 Pin the official nightly release built from webui-dev/webui 8a55352c2d7b6c0be9a149af417373714a390cb8 (release body "Generated from commit 8a55352c...", assets built 2026-11-26). The manifest digests match GitHub's release assets API and the verified bootstrap downloads; flake.nix and flake.lock pin the same revision. include/webui.h is byte-identical (112 exports), and the dynamic exports of the official linux-x64 .so are identical to 24c7d196e, so CsWebUi.Native and the public API need no change. Upstream changes since 24c7d196e: - a89c4ebf7 (webui-dev/webui#729): the redirects from / and folder URLs to their index file keep the request's query string, with a file handler and with a root folder. Bytes outside visible ASCII and '#' in the query are percent-encoded; a query over 8 KiB gets 414. WebUiIndexRedirectTests covers / and a folder URL with SetFileHandler and with SetRootFolder; both tests fail against 24c7d196e. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Release CS-WebUI 2.5.0-beta.4.11 Set the version to 2.5.0-beta.4.11 and FileVersion to 2.5.0.11, and add the release notes for the query string on index redirects (#33, webui-dev/webui#729). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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.
Problem
When WebUI answers
/or a folder URL with a 302 to the index file, it drops the request's query string:/?a=1&b=2is redirected toindex.html, notindex.html?a=1&b=2. A page that reads its state fromlocation.search(a deep link, a callback URL,?lang=…) loses it on the first load.All four index redirects in
src/webui.cpass only the index path tomg_send_http_redirect():_webui_http_handler(), root-folder mode (webui_set_root_folder()):/index (GET /?a=1&b=2→index.html);GET /sub/?a=1&b=2→/sub/index.html)._webui_external_file_handler(), file-handler mode (webui_set_file_handler()):webui_start_server(win, "index.html"),GET /?a=1&b=2→/index.html);GET /sub/?a=1&b=2→/sub/index.html).Fix
A new static helper,
_webui_http_redirect_keep_query(), now sends these four redirects and appends the request's query to theLocation.query_stringstill percent-encoded, since WebUI doesn't enabledecode_query_string. So the query is passed through as received,%xxincluded.#, are percent-encoded. TheLocationthen stays one header line, and#can't start a fragment. CivetWeb already answers a raw space or 0x7F in the request line with 400.414 URI Too Longinstead of being copied into the header. CivetWeb's own request limit (16 KiB by default) still applies first.No API or ABI change. Only
src/webui.cchanges;include/,bridge/andsrc/civetweb/are untouched. The helper isstatic.nm -D --defined-onlyoflibwebui-2.solists the same 196 symbols before and after this change, for gcc and clang, release and debug builds. Language bindings need no change.Testing
Built on Linux x64 with gcc 16.2 and clang 21:
makeandmake debug, plus the CMake build with examples;-Wall -Wextra;test_index_redirect.I checked each of the four paths with a small harness (not part of this PR). It starts the server without a browser, and I sent requests with curl and over a raw socket:
…/?a=1&b=2…index.html…index.html?a=1&b=2…index.html\x80\xC3\xA9\xFF, raw#%80%C3%A9%FF,%23%20%23%41curl -L …/?a=1&b=2/index.html/index.html?a=1&b=2I also ran the library and the harness under AddressSanitizer with LeakSanitizer, and they reported nothing. I couldn't test on Windows or macOS; the change has no platform-specific code.
🤖 Generated with Claude Code