HLE: prevent automatic WinHTTP redirects #997

Closed
github-bot wants to merge 1 commit from github-bot/gh-997 into main AGit
Owner

@⁠Hiiva on GitHub · 2026-11-24 14:47 UTC · original
hiiva/winhttp-no-redirect-upstream → main · +372 −8 · 2 files · 1 commits · closed without merging

WinHTTP can follow a redirect returned by an allowed loopback server inside the host implementation, without another call through the WinHttpConnect guard.

Set WINHTTP_OPTION_REDIRECT_POLICY_NEVER before returning a new session. Later redirect-policy changes on sessions or requests still apply NEVER. 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:

  • Two loopback listeners: the first returns a 307 and the second detects any follow. All four session/request-policy combinations return 307, retain NEVER, and make zero connections to the second listener.
  • Dynamically loaded WinHttpOpen and WinHttpSetOption resolve to the guarded exports.
  • An option failure is returned with the original error, and a non-null handle that cannot accept the policy is closed. This check runs in an isolated child so parallel tests cannot reuse the closed handle value.

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.
**@⁠Hiiva** on GitHub · 2026-11-24 14:47 UTC · [original](https://github.com/Marvisak/VIctory/pull/997) `hiiva/winhttp-no-redirect-upstream` → `main` · +372 −8 · 2 files · 1 commits · closed without merging WinHTTP can follow a redirect returned by an allowed loopback server inside the host implementation, without another call through the `WinHttpConnect` guard. Set `WINHTTP_OPTION_REDIRECT_POLICY_NEVER` before returning a new session. Later redirect-policy changes on sessions or requests still apply `NEVER`. 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](https://learn.microsoft.com/en-us/windows/win32/winhttp/option-flags#winhttp_option_redirect_policy). Synthetic regression coverage: - Two loopback listeners: the first returns a 307 and the second detects any follow. All four session/request-policy combinations return 307, retain `NEVER`, and make zero connections to the second listener. - Dynamically loaded `WinHttpOpen` and `WinHttpSetOption` resolve to the guarded exports. - An option failure is returned with the original error, and a non-null handle that cannot accept the policy is closed. This check runs in an isolated child so parallel tests cannot reuse the closed handle value. 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.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:16:33 +00:00
github-bot closed this pull request 2026-11-26 06:32:07 +00:00
Author
Owner

@⁠Zipettte on GitHub · 2026-11-24 15:12 UTC · original

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-hle passes, 98 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed).

Tested with AI assistance (Claude).

**@⁠Zipettte** on GitHub · 2026-11-24 15:12 UTC · [original](https://github.com/Marvisak/VIctory/pull/997#issuecomment-7135649156) 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-hle` passes, 98 passed / 0 failed. Workspace baseline on main (ffe310e) is green on the same machine (342 passed). _Tested with AI assistance (Claude)._
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 01:25 UTC · original

Automated triage for the maintainers.

Needs work. The gap is real and this tightens the offline guard rather than loosening it. WinHttpConnect only checks the first host, and WinHTTP follows redirects on its own by default, so a loopback server could send a request off the machine. Setting WINHTTP_OPTION_REDIRECT_POLICY to NEVER on every new session in WinHttpOpen is a good fix. Two things need changing first:

  • In crates/victory-hle/src/modules/net.rs, no_http_redirects calls WinHttpCloseHandle on the title's own handle when WinHttpSetOption fails. From WinHttpSetOption, 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_success asserts exactly this). Close the handle only in WinHttpOpen, where we created it. In WinHttpSetOption, 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

**@⁠Marvisak** on GitHub · 2026-11-25 01:25 UTC · [original](https://github.com/Marvisak/VIctory/pull/997#issuecomment-7149533893) <!-- victory-triage v1 head=7d1a0a585b183c4bd2610ca7f270acc4641e1552 verdict=needs-work at=2026-11-25T01:25:36Z --> Automated triage for the maintainers. **Needs work.** The gap is real and this tightens the offline guard rather than loosening it. `WinHttpConnect` only checks the first host, and WinHTTP follows redirects on its own by default, so a loopback server could send a request off the machine. Setting `WINHTTP_OPTION_REDIRECT_POLICY` to NEVER on every new session in `WinHttpOpen` is a good fix. Two things need changing first: - In `crates/victory-hle/src/modules/net.rs`, `no_http_redirects` calls `WinHttpCloseHandle` on the title's own handle when `WinHttpSetOption` fails. From `WinHttpSetOption`, 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_success` asserts exactly this). Close the handle only in `WinHttpOpen`, where we created it. In `WinHttpSetOption`, 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](https://claude.ai/code)_

Pull request closed

This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!997
No description provided.