Skip to content

fix(hosting): accept the CORS origins the CLI accepts for empty labels, long names and sub-delimiter hosts (#929) - #946

Merged
Blind-Striker merged 1 commit into
masterfrom
fix/929-cors-origin-rows-pr
Nov 17, 2026
Merged

Blind-Striker merged 1 commit into
masterfrom
fix/929-cors-origin-rows-pr

Conversation

@Blind-Striker

Copy link
Copy Markdown
Collaborator

📝 Description

What does this PR do?

OpenCodeServiceConfiguration.SetCorsOriginsAsync refused CORS origins that opencode's CLI stores. The SDK's CorsOriginPolicy accepts an origin only when it equals the origin .NET's own Uri parse rebuilds, and that parse is stricter than the WHATWG URL parsing upstream uses (external/opencode/packages/cli/src/services/service-config.ts at the 2.3.0 pin). This PR closes the gap for the three classes #929 names. Upstream's behaviour is the oracle.

  • Empty labels (http://a..b, http://., http://a.42..) are accepted as upstream accepts them. The numeric-final-label rule now drops at most one terminal empty label, as WHATWG does, so http://a.42. and http://a..42 stay refused.
  • Long names are accepted without DNS length limits, as WHATWG's parse imposes none. The oracle has rows at 63 and 64 characters per label, 253, 254 and 255 per name (with and without the trailing dot), and a 257-character label.
  • Sub-delimiter host characters !$&'()*+;=~ are accepted, alone and inside a label.
  • How: when Uri refuses the item, a bounded ASCII-host fallback takes over. It requires lowercase http:// or https://, and a host of lowercase ASCII letters, digits, ._- and those eleven characters. It lets the BCL parse the scheme and port with a fixed placeholder host, then rebuilds the origin with the original host. The existing exact comparison still decides every verdict, so the fallback cannot accept an origin upstream refuses: percent-encoded, userinfo, uppercase, default-port and path forms all stay refused, and the corpus has a row for each. The ACE, IPv4 and IPv6 paths are unchanged. No WHATWG or IDNA parser is ported.
  • Docs: the canon paragraph on CorsOriginPolicy (docs/architecture/client-runtime.md) describes the fallback as shipped, and CHANGELOG.md has the fix under [Unreleased].

Related Issue(s):

🔄 Type of Change

  • 🐛 Bug fix (non-breaking change that fixes an issue)

🎯 Protocol & API Surface

  • No change to the public API surface
  • The pinned snapshot (spec/) is untouched
  • Nothing under external/ was hand-edited

🧪 Testing

How has this been tested?

The oracle corpus grows from 81 to 147 rows: the 64 planned rows, plus http://!@! and http://!:8080/, two rows that reach the fallback's userinfo and path checks. Every verdict comes from upstream's own ServiceConfig.set("cors", origin) via bun tools/oracles/service-config.ts. The 64 planned verdicts matched the predictions, and no existing verdict changed. After each corpus change the oracle ran twice more, with a clean tree each time.

Local check on 60522e22 (macOS arm64, on master c903e9c5), all green:

  • the oracle pair;
  • slopwatch;
  • dotnet build -c Release, and again with -p:IncludeNet472Tests=true (0 warnings);
  • both format passes;
  • verify-clones;
  • Tools tests (2863);
  • SDK tests (9764, net10.0 and net11.0);
  • ServiceElection (22);
  • --help and generate --verify.

Mutation proof: 22 mutants, one at a time under the full analyzer build, each failing CorsOriginPolicyTests.IsOrigin_Should_Match_Every_Upstream_Cors_Verdict on net10.0 and net11.0 at its corpus row. They cover:

  • the empty-label rule, the final-label rule and the one-trailing-empty-label rule;
  • the length characterizations;
  • the percent-encoded and uppercase refusals;
  • userinfo, default port and trailing path;
  • each of the eleven punctuation characters.

The net472 replay is pending on the Windows gate host; this PR is enqueued only after it.

Review: a fresh cross-family read found nothing blocking. It confirmed by reading that the fallback cannot over-accept and that nothing in it depends on .NET Framework's Uri. Its non-blocking findings are #945.

📚 Documentation

  • CHANGELOG.md entry added for the user-facing fix
  • Canon updated in the same change

Known follow-ups

@Blind-Striker Blind-Striker added this to the Next milestone Nov 17, 2026
@Blind-Striker

Copy link
Copy Markdown
Collaborator Author

net472 mutation replay on Windows at 60522e2:

  • Baseline: the isolation guard (1) and CorsOriginPolicyTests (1 test over all 147 corpus rows) passed. This is the CORS corpus's first run on .NET Framework, and every row agrees with upstream's verdict there.
  • Mutants: 22 of 22 were killed at the corpus test's disagreements assertion. No analyzer rejected a mutant, and none survived.
  • Restored tree: both baseline runs passed again.

@Blind-Striker
Blind-Striker added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit a086fb4 Nov 17, 2026
17 checks passed
@Blind-Striker
Blind-Striker deleted the fix/929-cors-origin-rows-pr branch November 17, 2026 03:46
@Blind-Striker Blind-Striker mentioned this pull request Nov 17, 2026
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.

CORS origin policy: oracle rows for empty labels, DNS length limits and WHATWG-only host characters

1 participant