HLE: prevent automatic WinHTTP redirects #997
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/997"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by Hiiva on 2026-11-24T14:47:50Z.
WinHTTP can follow a redirect returned by an allowed loopback server inside the host implementation, without another call through the
WinHttpConnectguard.Set
WINHTTP_OPTION_REDIRECT_POLICY_NEVERbefore returning a new session. Later redirect-policy changes on sessions or requests still applyNEVER. If the host cannot enforce the policy, close the handle and preserve the option failure.The existing destination and proxy guards remain in place. The option type, supported handles, and behavior follow Microsoft's WinHTTP option documentation.
Synthetic regression coverage:
NEVER, and make zero connections to the second listener.WinHttpOpenandWinHttpSetOptionresolve to the guarded exports.The redirect regression fails with the guard disabled: all four requests reach the second local listener and return 200. With the guard restored, all four return 307 without following the redirect.
Validation:
cargo test -p victory-hle modules::net:: -- --nocapture: four tests pass, including the isolated child check.cargo test -p victory-hle --features diagnostics modules::net:: -- --nocapture: four tests pass.cargo clippy -p victory-hle --all-targets --features diagnostics -- -D warnings: passes.cargo xtask policy: passes.Imported from Marvisak/VIctory. Originally posted by mercuryVM on 2026-11-24T15:58:02Z.
Review: CHANGES_REQUESTED
Tested
7d1a0a5on Windows 11, RTX 5070, MSVC: builds;cargo test -p victory-hle97 passed, 0 failed, including the three newredirect_tests. The finding below is from reading.Setting
WINHTTP_OPTION_REDIRECT_POLICY_NEVERon every new session, and pinning it against later changes, is the right guard. The redirect test with two loopback listeners demonstrates it convincingly. One problem with the failure handling:WinHttpSetOptioncloses a handle the title owns (net.rs:783 via :808).no_http_redirectscloses the handle whenever setting the option fails, and the guardedWinHttpSetOptioncalls it for everyWINHTTP_OPTION_REDIRECT_POLICYrequest. If a title sets the policy on a handle that doesn't support it (a connection handle, as the new test does), we close that handle behind its back. The title's next use or its ownWinHttpCloseHandlethen hits a closed handle, or one WinHTTP has reused for a different handle in another thread. On Windows and on console, a failedWinHttpSetOptionleaves the handle open. Fix: close only inWinHttpOpen, where the session is ours and never reached the title. InWinHttpSetOption, return the failure with its last error and leave the handle alone, which already keeps the policy at NEVER.redirect_policy_failure_is_not_reported_as_successwould then assert the connection is still usable instead of closed.AI-assisted (Claude Code).
Imported from Marvisak/VIctory. Originally posted by Zipettte on 2026-11-24T15:12:59Z.
Tested on AMD Radeon RX 7700 XT (RDNA3, gfx1101), driver 32.0.32029.2010, Windows 11, Rust 1.98.1 MSVC at
7d1a0a5:cargo test -p victory-hlepasses, 98 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).Tested with AI assistance (Claude).
Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:25:38Z.
Automated triage for the maintainers.
Needs work. The gap is real and this tightens the offline guard rather than loosening it.
WinHttpConnectonly checks the first host, and WinHTTP follows redirects on its own by default, so a loopback server could send a request off the machine. SettingWINHTTP_OPTION_REDIRECT_POLICYto NEVER on every new session inWinHttpOpenis a good fix. Two things need changing first:crates/victory-hle/src/modules/net.rs,no_http_redirectscallsWinHttpCloseHandleon the title's own handle whenWinHttpSetOptionfails. FromWinHttpSetOption, that handle belongs to the title. For example, a connect handle, which does not accept this option, gets closed and later used or closed again by the title (redirect_policy_failure_is_not_reported_as_successasserts exactly this). Close the handle only inWinHttpOpen, where we created it. InWinHttpSetOption, either return success without forwarding (the session's NEVER policy already carries over to its requests), or forward NEVER and return the host's result as is.net_redirect_tests.rs(322 lines) re-runs the test binary as a child process and starts two TCP listeners. Spawning processes from tests needs the maintainer's decision. Without the closing behaviour, the child-process test is not needed. One loopback 307 test plus a policy check is enough.CI: not run on this head.
Generated by Claude Code
Pull request closed