XGameRuntime: keep embedded URLs in XSTS canonical query paths #1666

Open
eizispark wants to merge 1 commit from upstream-pr/1676 into main
eizispark commented 2026-11-24 19:12:18 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by eizispark on 2026-11-24T19:12:18Z.


xsign::canonical_path_and_query previously ran url.split_once("://") across the entire URL before stripping #fragment and without checking that a RFC 3986 scheme:// prefix precedes any / or ?. As a result, relative paths with callback/redirect URLs in query parameters (e.g. /oauth/authorize?redirect_uri=https://title.example/cb) or fragments containing :// were split inside the query or fragment, signing /cb instead of the actual request path and query, and scheme-relative //authority/... URLs kept the host inside the path.

In addition, signer() leaked CNG handles on initialization failure and did not track ecdsa_alg alongside its child ecdsa_key (per Windows CNG rules, a BCRYPT_KEY_HANDLE must be destroyed via BCryptDestroyKey before closing its parent BCRYPT_ALG_HANDLE via BCryptCloseAlgorithmProvider).

What is in it

  • crates/xcl/src/hle/xgameruntime/xsign.rs: strip #fragment first in canonical_path_and_query, strip only a leading // or RFC 3986 scheme:// authority prefix before normalizing the path-and-query, clean up CNG key/algorithm handles in reverse order on initialization failure and in Drop for EphemeralSigner, and add canonical_url_preserves_embedded_query_urls_and_strips_fragments_first covering embedded query/fragment URLs, scheme-relative URLs, and end-to-end sign_request_at + BCryptVerifySignature verification.

Tested

  • Hardware / toolchain: AMD Radeon RX 9070 XT (driver 32.0.32015.16001), AMD Ryzen 7 9800X3D, Windows 11 x64, rustc 1.100.0 (0ef1bc386 2026-11-09) (stable-x86_64-pc-windows-msvc), debug (unit + workspace tests) and release (60 s title smoke).
  • cargo test -p xcl --lib xsign: 5 passed, 0 failed, 0 ignored (canonical_url_preserves_embedded_query_urls_and_strips_fragments_first verified failing with "/cb" before the fix).
  • cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4: 777 passed, 0 failed, 41 ignored (SKIPPED GPU/SDK tests: 3 — test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll; heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows; uploads_start_from_each_subresources_state: no D3D12 debug layer).

Regression run

main (9e3831e1f570d3646e53ab753b19ec07eb8f1485):

xcl-smoke v1
commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1677 (PresentX 1677)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14728 MB

PR (3c13a5a8de3c10a59527f8d875518fe259935fdf):

xcl-smoke v1
commit: 3c13a5a8de3c10a59527f8d875518fe259935fdf
gpu: AMD Radeon RX 9070 XT
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1672 (PresentX 1673)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14855 MB

Not tested

  • Live Xbox Live / GDK titles calling XUserGetTokenAndSignature* with embedded redirect URLs in query strings; Linux / Wine (bcrypt.dll).
  • D3D12 SDK debug-layer tests (d3d12SDKLayers.dll not installed on this machine).

AI use

  • Antigravity (Google DeepMind, Gemini 4 Carbon): audited xsign.rs, wrote the regression test and fix, ran the workspace test suite and scripts/smoke.ps1 runs, and drafted this PR description.
<!-- greyfinch-sync:ivall/xcl:issue:5478644337 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1676). Originally posted by [eizispark](https://github.com/eizispark) on 2026-11-24T19:12:18Z. --- `xsign::canonical_path_and_query` previously ran `url.split_once("://")` across the entire URL before stripping `#fragment` and without checking that a RFC 3986 `scheme://` prefix precedes any `/` or `?`. As a result, relative paths with callback/redirect URLs in query parameters (e.g. `/oauth/authorize?redirect_uri=https://title.example/cb`) or fragments containing `://` were split inside the query or fragment, signing `/cb` instead of the actual request path and query, and scheme-relative `//authority/...` URLs kept the host inside the path. In addition, `signer()` leaked CNG handles on initialization failure and did not track `ecdsa_alg` alongside its child `ecdsa_key` (per Windows CNG rules, a `BCRYPT_KEY_HANDLE` must be destroyed via `BCryptDestroyKey` before closing its parent `BCRYPT_ALG_HANDLE` via `BCryptCloseAlgorithmProvider`). **What is in it** - `crates/xcl/src/hle/xgameruntime/xsign.rs`: strip `#fragment` first in `canonical_path_and_query`, strip only a leading `//` or RFC 3986 `scheme://` authority prefix before normalizing the path-and-query, clean up CNG key/algorithm handles in reverse order on initialization failure and in `Drop for EphemeralSigner`, and add `canonical_url_preserves_embedded_query_urls_and_strips_fragments_first` covering embedded query/fragment URLs, scheme-relative URLs, and end-to-end `sign_request_at` + `BCryptVerifySignature` verification. **Tested** - Hardware / toolchain: AMD Radeon RX 9070 XT (driver `32.0.32015.16001`), AMD Ryzen 7 9800X3D, Windows 11 x64, `rustc 1.100.0 (0ef1bc386 2026-11-09)` (`stable-x86_64-pc-windows-msvc`), debug (unit + workspace tests) and release (60 s title smoke). - `cargo test -p xcl --lib xsign`: 5 passed, 0 failed, 0 ignored (`canonical_url_preserves_embedded_query_urls_and_strips_fragments_first` verified failing with `"/cb"` before the fix). - `cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4`: 777 passed, 0 failed, 41 ignored (SKIPPED GPU/SDK tests: 3 — `test_title_draws_with_a_root_signature_under_the_debug_layer`: no `d3d12SDKLayers.dll`; `heap_window_out_of_memory_falls_back_to_the_switch_form`: no heap windows; `uploads_start_from_each_subresources_state`: no D3D12 debug layer). **Regression run** `main` (`9e3831e1f570d3646e53ab753b19ec07eb8f1485`): ``` xcl-smoke v1 commit: 9e3831e1f570d3646e53ab753b19ec07eb8f1485 gpu: AMD Radeon RX 9070 XT title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1677 (PresentX 1677) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14728 MB ``` PR (`3c13a5a8de3c10a59527f8d875518fe259935fdf`): ``` xcl-smoke v1 commit: 3c13a5a8de3c10a59527f8d875518fe259935fdf gpu: AMD Radeon RX 9070 XT title: 9cc6a39e seconds: 60 exit: 0x0 frames shown: 1672 (PresentX 1673) presents per 2 s (last 3): 60 60 60 device removals: 0 crashes: 0 peak commit: 14855 MB ``` **Not tested** - Live Xbox Live / GDK titles calling `XUserGetTokenAndSignature*` with embedded redirect URLs in query strings; Linux / Wine (`bcrypt.dll`). - D3D12 SDK debug-layer tests (`d3d12SDKLayers.dll` not installed on this machine). **AI use** - Antigravity (Google DeepMind, Gemini 4 Carbon): audited `xsign.rs`, wrote the regression test and fix, ran the workspace test suite and `scripts/smoke.ps1` runs, and drafted this PR description.
DavidM1911 commented 2026-11-24 22:06:46 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by DavidM1911 on 2026-11-24T21:37:41Z.


Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

  • cargo test -p xcl --lib: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified main.)

Thanks!

<!-- greyfinch-sync:ivall/xcl:comment:7145180298 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1676#issuecomment-7145180298). Originally posted by [DavidM1911](https://github.com/DavidM1911) on 2026-11-24T21:37:41Z. --- Verification on RTX 3060 Ti (Windows 11), branch merged with current `main`: - `cargo test -p xcl --lib`: all passed, 0 failed, ~22 ignored. (Intermittent single-test flake under parallel scheduling; clean on single-threaded rerun — same flake seen on unmodified `main`.) Thanks!
JJAutoCompare commented 2026-11-25 04:10:43 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by JJAutoCompare on 2026-11-25T03:55:23Z.


PR #1676 — STOR-WINLAB verification

Tested 3c13a5a8de3c10a59527f8d875518fe259935fdf at detached HEAD, matching the fetched PR head.

Environment

STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, DoublePrecisionFloatShaderOps=0, wave range 8–32). DXC/DXIL 1.9.2609.5. Rust 1.100.0 (0ef1bc386, 2026-11-09). Unoptimized build and test profiles with debug info disabled.

Tested

  • cargo build --workspace and cargo test --workspace --no-run completed successfully. Every Cargo test invocation used the shared Arc lock.
  • cargo test -p xcl xgameruntime -- --nocapture exited 0. Libtest reported 74 unit tests passed, 0 failed, 0 ignored. One sample-dependent integration test also reported a pass with its sample unset. All five xsign tests passed. The new regression test checks that canonicalization keeps embedded query URLs, strips fragments, handles relative and scheme-relative inputs, and produces equivalent signing payloads for relative and absolute URLs. BCrypt verified the ephemeral P-256 signature.
  • One full run of cargo test --workspace --no-fail-fast -- --test-threads=4 exited 101. The 20 summaries in pr1676-suite.log report 761 passed, 16 failed, 41 ignored. The signing regression test passed again.

Workspace failures and skips

  • 15 GPU recompiler failures. Eleven tests involving FP64 hit CreateComputePipelineState error 0x80070057. Four assertions failed in FMA overflow, implicit mip LOD sampling, FP16 high-half preservation, and pixel-shader wave reduction.
  • One test-title failure. The dynamic depth bias RSSetDepthBiasX check read a blue pixel where it expected green.
  • Three explicit SKIPPED lines in the suite log, two for no wave64 and one for no heap windows. These paths contribute no coverage.

Not tested

Live XSTS service acceptance, retail-title smoke tests, a main baseline, and other GPUs. Optional game-data paths had no XCL_SAMPLE_* inputs. The D3D12 debug layer, system Gaming Services paths, and audio endpoint paths were unavailable.

AI use

T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against pr1676-suite.log and published.

<!-- greyfinch-sync:ivall/xcl:comment:7152364734 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1676#issuecomment-7152364734). Originally posted by [JJAutoCompare](https://github.com/JJAutoCompare) on 2026-11-25T03:55:23Z. --- # PR #1676 — STOR-WINLAB verification Tested `3c13a5a8de3c10a59527f8d875518fe259935fdf` at detached HEAD, matching the fetched PR head. **Environment** STOR-WINLAB, Windows 11 Enterprise Evaluation build 26200.9974, Ryzen 7 3800X, Intel Arc A770 16 GiB (driver 32.0.101.9175, `DoublePrecisionFloatShaderOps=0`, wave range 8–32). DXC/DXIL 1.9.2609.5. Rust 1.100.0 (`0ef1bc386`, 2026-11-09). Unoptimized build and test profiles with debug info disabled. **Tested** - `cargo build --workspace` and `cargo test --workspace --no-run` completed successfully. Every Cargo test invocation used the shared Arc lock. - `cargo test -p xcl xgameruntime -- --nocapture` exited 0. Libtest reported 74 unit tests passed, 0 failed, 0 ignored. One sample-dependent integration test also reported a pass with its sample unset. All five `xsign` tests passed. The new regression test checks that canonicalization keeps embedded query URLs, strips fragments, handles relative and scheme-relative inputs, and produces equivalent signing payloads for relative and absolute URLs. BCrypt verified the ephemeral P-256 signature. - One full run of `cargo test --workspace --no-fail-fast -- --test-threads=4` exited 101. The 20 summaries in `pr1676-suite.log` report **761 passed, 16 failed, 41 ignored**. The signing regression test passed again. **Workspace failures and skips** - 15 GPU recompiler failures. Eleven tests involving FP64 hit `CreateComputePipelineState` error `0x80070057`. Four assertions failed in FMA overflow, implicit mip LOD sampling, FP16 high-half preservation, and pixel-shader wave reduction. - One test-title failure. The dynamic depth bias `RSSetDepthBiasX` check read a blue pixel where it expected green. - Three explicit `SKIPPED` lines in the suite log, two for `no wave64` and one for `no heap windows`. These paths contribute no coverage. **Not tested** Live XSTS service acceptance, retail-title smoke tests, a `main` baseline, and other GPUs. Optional game-data paths had no `XCL_SAMPLE_*` inputs. The D3D12 debug layer, system Gaming Services paths, and audio endpoint paths were unavailable. **AI use** T3 Code / Codex (gpt-6.2-sol, reasoningEffort: high) ran the build and verification. Coordinator #2 (T3 Code / Antigravity, gemini-4-neon) verified counts against `pr1676-suite.log` and published.
github-actions[bot] commented 2026-11-28 08:02:09 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by github-actions[bot] on 2026-11-28T08:02:09Z.


Nothing has happened on this PR for 3 days, so it is marked stale and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto main if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.

<!-- greyfinch-sync:ivall/xcl:comment:7236319136 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1676#issuecomment-7236319136). Originally posted by [github-actions[bot]](https://github.com/apps/github-actions) on 2026-11-28T08:02:09Z. --- Nothing has happened on this PR for 3 days, so it is marked `stale` and will be closed in 4 days. A push or a comment takes the mark off: rebase it onto `main` if it conflicts, and say in one line what it still fixes. If it only waits for a maintainer, a comment saying so is enough.
Foniass commented 2026-12-01 06:28:47 +00:00 (Migrated from github.com)

Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T06:28:47Z.


Triage (#1607) – head 3c13a5a

No open or merged PR makes the same change. Main's canonical_path_and_query (xsign.rs) still splits at the first ://, so /oauth/authorize?redirect_uri=https://title.example/cb signs as /cb; this PR fixes that and tests it.
Two remarks on the diff: the Drop for EphemeralSigner never runs (the signer lives in a static OnceLock), and the BCrypt cleanup is unrelated to the title, so it belongs in its own PR. A scheme-less host/path (e.g. social.xboxlive.com/users/me) now signs as /social.xboxlive.com/users/me where main gave /users/me. Say whether any caller passes that form.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

<!-- greyfinch-sync:ivall/xcl:comment:7302920780 --> Imported from [ivall/xcl](https://github.com/xcl-dev/xcl/pull/1676#issuecomment-7302920780). Originally posted by [Foniass](https://github.com/Foniass) on 2026-12-01T06:28:47Z. --- **Triage (#1607)** – head 3c13a5a No open or merged PR makes the same change. Main's `canonical_path_and_query` (`xsign.rs`) still splits at the first `://`, so `/oauth/authorize?redirect_uri=https://title.example/cb` signs as `/cb`; this PR fixes that and tests it. Two remarks on the diff: the `Drop for EphemeralSigner` never runs (the signer lives in a `static OnceLock`), and the BCrypt cleanup is unrelated to the title, so it belongs in its own PR. A scheme-less `host/path` (e.g. `social.xboxlive.com/users/me`) now signs as `/social.xboxlive.com/users/me` where main gave `/users/me`. Say whether any caller passes that form. Recommendation: keep open. AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
This pull request cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/1676:upstream-pr/1676'
git switch 'upstream-pr/1676'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/1676'
git switch 'upstream-pr/1676'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/1676'
git switch 'upstream-pr/1676'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/1676'
git switch 'main'
git merge --squash 'upstream-pr/1676'
git switch 'main'
git merge --ff-only 'upstream-pr/1676'
git switch 'main'
git merge 'upstream-pr/1676'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
xcl-dev/xcl!1666
No description provided.