Skip to content

HLE media: block UNC share bypasses for localhost and \??\ file URLs - #3121

Open
Arkenoz wants to merge 1 commit into
Marvisak:mainfrom
Arkenoz:fix/media-local-unc-bypasses
Open

Arkenoz wants to merge 1 commit into
Marvisak:mainfrom
Arkenoz:fix/media-local-unc-bypasses

Conversation

@Arkenoz

@Arkenoz Arkenoz commented Nov 26, 2026

Copy link
Copy Markdown

Summary

Closes two remaining UNC share bypasses in media::local (crates/victory-hle/src/modules/media.rs) following up on #207:

  1. file://localhost/... with extra leading separators: this_machine == true previously skipped share(&whole) completely. Because shlwapi.dll!PathCreateFromUrlW consumes only a single leading separator after localhost, URLs such as file://localhost///server/share/a.mp4, file://localhost/\\server/share/a.mp4, and file://localhost/%5C%5Cserver/share/a.mp4 resolve to remote UNC paths (\\server\share\a.mp4 / \\\server\share\a.mp4) and were allowed through. media::local now strips one leading separator when this_machine is set and still runs share(...) on the remainder, keeping file://localhost//server/share/a.mp4 (\server\share\a.mp4) local.
  2. Percent-encoded \??\ object-manager prefixes in file: URLs: URLs like file:///%3F%3F/UNC/server/share/a.mp4 decode to \??\UNC\server\share\a.mp4 in PathCreateFromUrlW without starting with two separators. media::local now rejects decoded \??\ paths unless followed by a drive letter, stripping UNC\ case-insensitively when extracting the host.

Testing

  • Added localhost_and_object_prefix_file_urls_are_refused (verified failing before the fix and passing after) and Windows oracle test the_host_reads_localhost_and_object_prefix_share_urls_as_shares against shlwapi.dll!PathCreateFromUrlW.
  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/media.rs — passed
  • cargo clippy --workspace --all-targets -- -D warnings — passed
  • cargo check --workspace --all-targets — passed
  • cargo xtask policy — passed (asset policy: 191 files ok)
  • cargo test -p victory-hle --locked — passed (154 lib + fidelityfx + no_dll_planting)

Coordination & AI disclosure

@Dukestar69 Dukestar69 left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified against origin/main (63bcca4):

  • cargo test -p victory-hle --lib modules::media:: -- --test-threads=1: 7/7 passed (including localhost_and_object_prefix_file_urls_are_refused and the_host_reads_localhost_and_object_prefix_share_urls_as_shares).
  • cargo clippy -p victory-hle --all-targets -- -D warnings: clean.
  • cargo xtask policy: 191 files ok.

Cleanly closes the localhost and \??\ UNC share bypasses in media.rs.

Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

Merge candidate. This makes the URL rule in media::local (crates/victory-hle/src/modules/media.rs) stricter and loosens nothing. On main, !this_machine && share(&whole) skipped the share check for every file://localhost/... URL. Now the check runs on every non-drive file: path, and for localhost it runs after removing one leading separator. That refuses everything main refused and also file://localhost///server/..., file://localhost/\\server/... and the percent-encoded spelling. The new \??\ check on the decoded path refuses file:///%3F%3F/UNC/server/.... I found no local path that is now wrongly refused, and the controls (localhost//, \??\C:) still pass. The Windows test reads PathCreateFromUrlW's own output, so it backs the claim about host behaviour. Nit: its localhost// assertion repeats one in the_host_reads_those_spellings_as_shares.

CI: check passing.


Generated by Claude Code

@fuzeofficlal fuzeofficlal left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified afd63d5e locally on Windows 11 x64:

  • cargo clippy --all-targets --locked -- -D warnings: clean (3.14s).
  • cargo test -p xtask --locked policy::tests::repository_passes_policy: 1 passed, 0 failed (0.34s).
  • cargo test -p victory-hle --locked: 156 passed, 0 failed (154 lib including all 7 modules::media::tests + 1 fidelityfx + 1 no_dll_planting, 5.00s).
  • rustfmt --edition 2024 --check crates/victory-hle/src/modules/media.rs: clean.

The added effective and \??\ checks close the submitted file://localhost///..., file://localhost/\\..., file://localhost/%5C%5C..., and file:///%3F%3F/UNC/... cases. However, for non-drive file: URLs (media.rs:92-116), local() validates decoded Rust views (whole/path) and then returns Ok(with_nul(url)), handing the original raw UTF-16 URL to Media Foundation to re-parse (for example with mixed encoded separators or namespace combinations). Please validate the host-converted path (or hand Media Foundation the exact normalized local path that passed the check) consistently across both resolver entry points, and expand the Windows conversion coverage for mixed separators and percent-encoded slashes.

@Arkenoz

Arkenoz commented Nov 26, 2026

Copy link
Copy Markdown
Author

Verified afd63d5e locally on Windows 11 x64:

* `cargo clippy --all-targets --locked -- -D warnings`: clean (`3.14s`).

* `cargo test -p xtask --locked policy::tests::repository_passes_policy`: 1 passed, 0 failed (`0.34s`).

* `cargo test -p victory-hle --locked`: 156 passed, 0 failed (`154` lib including all 7 `modules::media::tests` + `1` fidelityfx + `1` no_dll_planting, `5.00s`).

* `rustfmt --edition 2024 --check crates/victory-hle/src/modules/media.rs`: clean.

The added effective and \??\ checks close the submitted file://localhost///..., file://localhost/\\..., file://localhost/%5C%5C..., and file:///%3F%3F/UNC/... cases. However, for non-drive file: URLs (media.rs:92-116), local() validates decoded Rust views (whole/path) and then returns Ok(with_nul(url)), handing the original raw UTF-16 URL to Media Foundation to re-parse (for example with mixed encoded separators or namespace combinations). Please validate the host-converted path (or hand Media Foundation the exact normalized local path that passed the check) consistently across both resolver entry points, and expand the Windows conversion coverage for mixed separators and percent-encoded slashes.

Thanks for the thorough review and local verification! That's a good point about validating/passing the host-normalized path rather than the raw UTF-16 URL. Since this PR is intentionally kept minimal and already marked as a merge candidate, I'd prefer to keep it focused on closing the localhost and \??\ bypasses and leave normalizing the return path across both resolver entry points for a separate follow-up PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants