Skip to content

fix(nvhttp): bound GameStream requests before routing - #6098

Open
NotUncleBob wants to merge 1 commit into
SunshineStream:masterfrom
NotUncleBob:fix/miniupnpc-xml-bounds
Open

NotUncleBob wants to merge 1 commit into
SunshineStream:masterfrom
NotUncleBob:fix/miniupnpc-xml-bounds

Conversation

@NotUncleBob

@NotUncleBob NotUncleBob commented Nov 14, 2026 •

Copy link
Copy Markdown

Description

Bound requests on the two GameStream servers to 64 KiB and give them an on_error handler, before routing or authentication. GameStream requests carry everything in the query string, including the pairing certificate, and have no body.

With the pinned Simple-Web-Server, a chunked request cut short after its chunk data reaches an unchecked on_error call and throws std::bad_function_call out of the server thread, which aborts Sunshine. Setting the handler avoids that until the library fix lands.

The dependency fixes that were part of this PR at first went upstream instead:

Screenshot

Issues Fixed or Closed

Roadmap Issues

Testing

Validation after rebasing onto master at 5716a2ac (MiniUPnPc update #6111):

  • Built Sunshine and test_sunshine on Arch Linux x86_64 with GCC 16.2.1, Boost 1.92.0, Release, BUILD_WERROR=ON, and CUDA disabled. The four HTTP regression tests passed. The full C++ suite under Xvfb with PulseAudio and the HTTP fixture server completed with 959 passed, 0 failed and 7 skipped (PipeWire, Windows-only UTF utilities, scoped link-local networking, two system-tray tests, and NVENC/VAAPI).
  • Web CI commands: npm ci --ignore-scripts, npm test (217 tests passed), npm run build, and npm publish --dry-run --tag ci --ignore-scripts passed.
  • Windows PowerShell: Pester 5.9.0, 19 tests passed, 100% coverage of the setup-process script.
  • Local lint checks passed: clang-format 23.1.0, cmake-lint, actionlint, hadolint, shellcheck, yamllint, flake8, PSScriptAnalyzer, and the PR whitespace/newline checks.
  • MiniUPnPc 2.3.4 was separately built from the release tag; all 7 CTest tests passed, including validateminixml.
  • This is local validation, not a complete GitHub Actions matrix. Native Windows/macOS/FreeBSD/ARM builds, all distribution packages, CUDA and hosted CodeQL/SonarCloud checks were not reproduced locally. GitHub Actions requiring maintainer approval remain separate from these results.

Earlier validation before this rebase (retained for context):

  • Added four loopback regressions in tests/unit/test_http_request_limits.cpp: a truncated chunk in one read and split over two reads, a 64 KiB header next to a pairing-sized query, and a body over the limit.
  • Built test_sunshine on Fedora 44 with GCC 16.2.1 (Release, BUILD_WERROR=ON). The four tests pass, and all four fail without the settings in configure_gamestream_server.
  • The rest of the suite passes, except four suites that can't set up inside my container (X11 grab, audio, mouse HID, encoder).
  • Ran clang-format 23.1.0 on the three files.
  • Ran a host built from this branch (Nobara, KDE Wayland) with Moonlight 6.2.0 on Windows: pairing, app list and launch work, and a 720p H.264 stream with the software encoder had video and audio.
  • On that host, a chunked request cut short on the plain HTTP port closes its connection and /serverinfo keeps answering. The same tree without the settings in configure_gamestream_server aborts the process on that request.

Type of Change

  • feat: New feature (non-breaking change which adds functionality)
  • fix: Bug fix (non-breaking change which fixes an issue)
  • docs: Documentation only changes
  • style: Changes that do not affect the meaning of the code (white-space, formatting, missing semicolons, etc.)
  • refactor: Code change that neither fixes a bug nor adds a feature
  • perf: Code change that improves performance
  • test: Adding missing tests or correcting existing tests
  • build: Changes that affect the build system or external dependencies
  • ci: Changes to CI configuration files and scripts
  • chore: Other changes that don't modify src or test files
  • revert: Reverts a previous commit
  • BREAKING CHANGE: Introduces a breaking change (can be combined with any type above)

Checklist

  • Code follows the style guidelines of this project
  • Code has been self-reviewed
  • Code has been commented, particularly in hard-to-understand areas
  • Code docstring/documentation-blocks for new or existing methods/components have been added or updated
  • Tests have been added or updated for new or modified functionality, including regression tests for bug fixes

AI Usage

See our AI usage policy.

  • AI tools were used while preparing this PR

Copy link
Copy Markdown
Member

Thanks for investigating these fixes and adding regression coverage. I don't want Sunshine to maintain dependency backports; please take an upstream-first approach here:

  • MiniUPnPc: Please ask upstream for a client release containing both XML bounds fixes linked in this PR, then update the Flatpak dependency to that release instead of carrying miniupnpc-minixml-bounds.patch or pinning an unreleased commit.
  • Simple-Web-Server: Please submit the generic parser fixes upstream and link that submission here. Once accepted, update the submodule to a revision containing the fixes rather than carrying the patches and build-tree patching machinery in Sunshine.

Sunshine-specific request limits and GameStream policy can remain in Sunshine, with the regression coverage retained. This is feedback on the dependency-maintenance approach, not a claim that the fixes themselves are incorrect or that full integration testing has passed.

Review completed by Codex | Model: unavailable | Thinking: unavailable

@NotUncleBob
NotUncleBob force-pushed the fix/miniupnpc-xml-bounds branch from 1ccd104 to e300c0d Compare November 14, 2026 17:12
@NotUncleBob NotUncleBob changed the title fix(security): backport UPnP XML and HTTP parser bounds fixes fix(nvhttp): bound GameStream requests before routing Nov 14, 2026
@NotUncleBob

Copy link
Copy Markdown
Author

Thanks for the review, that makes sense. I went upstream first and trimmed this PR.

What's left is Sunshine's own part: the 64 KiB limit on GameStream requests and an on_error handler on the two GameStream servers. With the current submodule that handler is also what keeps a truncated chunked request from stopping them.

Two things from the first version are not in this one:

  • Rejecting request bodies on the GameStream ports needs a new option in Simple-Web-Server. I sent that separately in https://gitlab.com/eidheim/Simple-Web-Server/-/merge_requests/287. Until then, bodies are bounded by the same 64 KiB limit.
  • The chunk size overflow can only be fixed in the library, so it stays until the submodule moves.

I rebased on master and built test_sunshine on Fedora 44 with GCC 16.2.1. The 4 new tests pass, and all 4 fail if I take the two settings out of configure_gamestream_server. The rest of the suite passes, except four suites that can't set up inside my container (X11 grab, audio, mouse HID, encoder).

I also ran a host built from this branch next to my installed one and used Moonlight 6.2.0 on Windows against it: pairing, the app list and launching work as before, and a 720p H.264 stream with the software encoder had video and audio. On the same host, a chunked request cut short on the plain HTTP port just closes that connection. The same tree without the two settings aborts the whole process on that one request (std::bad_function_call).

@NotUncleBob
NotUncleBob force-pushed the fix/miniupnpc-xml-bounds branch from e300c0d to e141db8 Compare November 16, 2026 04:49
@NotUncleBob

Copy link
Copy Markdown
Author

I requested a new MiniUPnPc release containing the minixml bounds fixes in miniupnp/miniupnp#953, and upstream has now published MiniUPnPc 2.3.4. Sunshine already points to that release through #6111.

I rebased this branch onto master. The diff remains limited to the Sunshine-specific 64 KiB GameStream request limit, error handler, and four regression tests.

Local validation after the rebase passed: the Release/Werror build, all four HTTP regressions, the C++ suite (959 passed, 0 failed, 7 skipped), web tests (217), PowerShell tests (19), lint checks, and the seven MiniUPnPc 2.3.4 upstream tests. The description records the environment and limitations; this does not replace the full hosted CI matrix. CI, common lint, and CodeQL still require maintainer approval to run.

Now that the new MiniUPnPc tag is available and Sunshine has adopted it, could you take another look and see whether we can move this scoped change forward? The Simple-Web-Server submissions remain separate upstream follow-ups.

@sonarqubecloud

Copy link
Copy Markdown

Copy link
Copy Markdown
Member

Re-reviewed the current e141db84 against 5716a2ac, including the pinned Simple-Web-Server reader and the four loopback regressions. The current three-file diff follows the upstream-first direction: no dependency patches or patching machinery remain. Both GameStream listeners receive the limit and error handler before starting. I found no concrete correctness blocker in this scoped change.

The truncated-chunk tests cover the two unchecked error-callback paths in the pinned reader, while the other tests exercise an ordinary pairing-sized query and oversized header/body rejection. git diff --check passed. I have not independently run these tests or a native build in this review environment (Boost/GoogleTest development headers are absent), nor repeated the live Moonlight validation. CI, common lint and CodeQL for this exact head still await maintainer approval; those are separate from the contributor's reported local results.

The Simple-Web-Server parser fixes and body-rejection option remain separate upstream follow-ups; this scoped mitigation does not replace them.

Review completed by Codex | Model: unavailable | Thinking: unavailable

This branch has not been deployed

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants