amuleweb: fix POST body parsing when URL has a query string - #729
Merged
mrjimenez merged 1 commit intoMay 26, 2026
Merged
Conversation
CWebSocket::OnRequestReceived appended the POST body to the request
URL with a literal "?" so CParsedUrl could pick up form fields the
same way it does for GET ?key=value pairs:
if ( is_post ) {
sURL += "?" + sData.Left(dwDataLen);
}
That works when the URL has no query string ("/" + POST "pass=XYZ"
-> "/?pass=XYZ"), but on a URL that already has one, the combined
string ends up with two "?":
/amuleweb-main-search.php?sort=sources + POST pass=XYZ
-^
--> /amuleweb-main-search.php?sort=sources?pass=XYZ
CParsedUrl splits on the *first* "?" then tokenises the remainder by
"&" only. The single resulting token "sort=sources?pass=XYZ" is then
split on the first "=" into key="sort", val="sources?pass=XYZ" -- so
m_params never gets a "pass" entry. Param("pass") returns empty,
WebServer.cpp:1884 falls through to the "no password entered" branch,
and the user gets sent back to login.php no matter what they typed.
Visible symptom: login works on / and /amuleweb-main-dload.php, fails
on /amuleweb-main-search.php?sort=sources or any URL with ?... in it
(reported as issue amule-project#724).
Fix: when the URL already contains a "?", use "&" instead of "?" as
the separator before the POST body. This is exactly what an HTML
form would do if the action attribute carried the query string.
Bisect note: this is *not* a regression in 8ce30f9..fe4e287 --
WebSocket.cpp has zero commits in that range. The bug has been
present since the POST-to-URL append was first written; @ngosang
just happened to first try a query-string URL on master tip.
Fixes amule-project#724.
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.
Fixes #724.
CWebSocket::OnRequestReceived(insrc/webserver/src/WebSocket.cpp) appends the POST body to the request URL soCParsedUrlcan pick up form fields the same way it does for GET?key=valuepairs:That works when the URL has no query string (
/+ POSTpass=XYZ→/?pass=XYZ), but on a URL that already has one, the combined string ends up with two?:CParsedUrlsplits on the first?and tokenises the remainder by&only. The single resulting tokensort=sources?pass=XYZis then split on the first=intokey="sort",val="sources?pass=XYZ".m_paramsnever gets apassentry,Param("pass")returns empty,WebServer.cpp:1884falls through to the "no password entered" branch, and the user gets bounced back to the login form — exactly what was reported in #724:The fix
If the URL already has a
?, use&to join the POST body. This is exactly what an HTML form does when its action attribute carries a query string.Bisect note
This is not a regression in
8ce30f910..fe4e28709(the range in #724).WebSocket.cpphas zero commits in that range — and the broken append-with-?logic has been present since the POST-to-URL merge was first written years ago.@ngosangjust happened to first try a query-string-bearing URL on master tip; any earlier version that also went throughCWebSocket::OnRequestReceivedwould have failed identically.