Skip to content

Keep the test server to this machine and its file middleware inside its roots - #1379

Merged
djmb merged 1 commit into
mainfrom
test-server-hardening
Nov 26, 2026
Merged

djmb merged 1 commit into
mainfrom
test-server-hardening

Conversation

@djmb

@djmb djmb commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

The web-test-runner server listens on every interface so Sauce Connect can reach it, and that applies to local runs too. Its file middleware joins the request URL onto src/test or node_modules without checking where the result lands, so a request with .. segments reads any file the test process can read. While the suite runs, anyone on the same network can do that.

Unless Sauce Labs is configured, a small plugin now drops connections that don't come from a loopback address. Setting hostname to 127.0.0.1 doesn't help, because @web/dev-server-core listens on every interface when the hostname is localhost or 127.0.0.1. Dropping at the connection also covers the test runner's WebSocket, which Koa middleware never sees.

The fixture and QUnit middleware now serve a file only when its resolved path stays under src/test/test_helpers/fixtures or node_modules/qunit.

…ts roots

Unless Sauce Labs is configured, drop connections to the web-test-runner
server that don't come from a loopback address. Setting hostname to
127.0.0.1 doesn't help: @web/dev-server-core listens on every interface
when hostname is localhost or 127.0.0.1.

Serve /test_helpers/fixtures/ and /qunit/ requests only when the resolved
path stays under the fixtures directory and node_modules/qunit
respectively.
Copilot AI balanced review requested due to automatic review settings November 26, 2026 15:14

Copilot AI 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.

🟢 Approved

No active review issues are recorded for the server connection restrictions and file-path containment changes.

No open issues 🎉

What changed in this PR

This PR hardens the web-test-runner server by restricting local connections and adding path containment checks to its file middleware, while preserving Sauce Connect access.

Changes:

  • Reject non-loopback connections when Sauce Labs is not configured, including WebSocket connections.
  • Check resolved fixture and QUnit paths against their designated roots before serving files.

[!TIP]
If you aren't ready for review, convert to a draft PR.
Click "Convert to draft" or run gh pr ready --undo.
Click "Ready for review" or run gh pr ready to reengage.

File Description
web-test-runner.config.mjs Adds loopback-only connection filtering and path containment checks for fixture and QUnit files.

Review effort: Balanced

@djmb
djmb merged commit 826acea into main Nov 26, 2026
21 of 22 checks passed
@djmb
djmb deleted the test-server-hardening branch November 26, 2026 15:22
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