Skip to content

fix(hosting): accept the remaining WHATWG host characters in CORS origins and pin the fallback's invariants (#945) - #948

Merged
Blind-Striker merged 2 commits into
masterfrom
fix/945-cors-remaining-pr
Nov 17, 2026
Merged

Blind-Striker merged 2 commits into
masterfrom
fix/945-cors-remaining-pr

Conversation

@Blind-Striker

Copy link
Copy Markdown
Collaborator

📝 Description

What does this PR do?

Parts 1 and 3 of #945, the follow-up to #929. CorsOriginPolicy falls back to a bounded ASCII-host check when .NET's Uri refuses an origin. That fallback still refused four host characters that the WHATWG URL parser in opencode's CLI accepts. The fallback's invariants also had no corpus rows of their own. Upstream's behaviour is the oracle (external/opencode/packages/cli/src/services/service-config.ts at the 2.3.0 pin).

  • Part 1: the remaining host characters. ", `, { and } are accepted, alone and inside a label. Their percent-encoded forms (%22, %60, %7b, %7d) stay refused, as upstream refuses them. The production change is one line: the fallback's allowlist in CorsOriginPolicy.cs.

  • Part 3: the fallback's invariants. New corpus rows pin:

    • the empty-port, uppercase-scheme and port-0 forms;
    • leading and trailing hyphens;
    • a trailing dot followed by a port;
    • decimal, hexadecimal and partly numeric final labels;
    • mixed names, where an ACE label sits next to a punctuated one (http://xn--9ca.a!b accepted, http://xn--a.a!b refused);
    • a valid and a malformed 63-character ACE label.

    Every one of these rows already matched the policy; they lock its behaviour in.

  • Docs:

    • The canon paragraph on CorsOriginPolicy (docs/architecture/client-runtime.md) now says exactly when the fallback applies: Uri.TryCreate refuses the whole item, and the host is the text after :// up to the first :, or to the end of the item. It also lists the full alphabet. In place of "without imposing DNS length limits", it says that ordinary ASCII names carry no DNS length limit, while ACE (xn--) labels are validated by IdnMapping, which enforces its 63-character label limit.
    • CHANGELOG.md: CORS origin policy: oracle rows for empty labels, DNS length limits and WHATWG-only host characters #929's Fixes entry now covers both issues.

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 147 to 172 rows:

  • 12 for the additional characters and their encoded forms;
  • 11 fallback invariants;
  • the two 63-character ACE rows.

Every verdict comes from upstream's own ServiceConfig.set("cors", origin) via bun tools/oracles/service-config.ts. No existing verdict changed. After the commit, the oracle ran twice more with a clean tree each time.

Local check (macOS arm64, on master a086fb4b), all green:

  • on e4fc68c8:
    • the oracle pair;
    • slopwatch;
    • dotnet build -c Release, and again with -p:IncludeNet472Tests=true;
    • both format passes;
    • verify-clones;
    • SDK tests (9764, net10.0 and net11.0);
    • ServiceElection (22);
    • --help and generate --verify.
  • on the head, after the documentation fix-up:
    • Tools tests, including the canon-source guard and the documentation gates;
    • the whitespace check.

Mutation proof: 18 mutants, applied one at a time under the full analyzer build. Each fails CorsOriginPolicyTests.IsOrigin_Should_Match_Every_Upstream_Cors_Verdict at its corpus row, on net10.0 and net11.0. They cover:

  • each of the four character removals, and a % control;
  • empty port, uppercase scheme and port 0;
  • leading and trailing hyphen, and a trailing dot with a port;
  • decimal, hexadecimal and partly numeric final labels;
  • the two mixed-ACE rows;
  • the valid and the malformed 63-character ACE labels.

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

Review: a fresh cross-family read found nothing blocking. Its CHANGELOG finding is fixed.

📚 Documentation

  • CHANGELOG.md entry updated 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 (KAER), head 81920209a167c866acac92a4847ad4395603b323, --framework net472:

  • Baselines: the service-config isolation guard (1/1) and CorsOriginPolicyTests (1/1) are green. The 63-character ACE rows of the upstream verdict corpus agree on .NET Framework.
  • Mutants F01-F18: 18 of 18 killed. Every kill fails at Assert.That(disagreements).IsEmpty(), and each disagreement list holds the row its mutant targets. F06 (a trailing : ignored) lists "http://!:". On net472 it also lists "http://example.com:", under the mutant only.
  • Final restored tree: both filters green, and the restore diff is empty.

Part of #945.

@Blind-Striker
Blind-Striker added this pull request to the merge queue Nov 17, 2026
Merged via the queue into master with commit 31c7a3c Nov 17, 2026
17 checks passed
@Blind-Striker
Blind-Striker deleted the fix/945-cors-remaining-pr branch November 17, 2026 05:52
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.

1 participant