Skip to content

fix(router-core): harden string encoding/decoding boundaries - #8141

Draft
Sheraff wants to merge 1 commit into
mainfrom
feat/string-encoding-hardening
Draft

fix(router-core): harden string encoding/decoding boundaries#8141
Sheraff wants to merge 1 commit into
mainfrom
feat/string-encoding-hardening

Conversation

@Sheraff

@Sheraff Sheraff commented Aug 21, 2026

Copy link
Copy Markdown
Collaborator

Summary

Centralizes and hardens every string encoding/decoding surface in the router, guided by a full inventory (now maintained as packages/router-core/docs/string-handling.md).

Fix: URIError crash via route masks and matchRoute

Malformed percent-encoding in a URL segment (e.g. /post/%E4%BD, /post/%zz) made extractParams throw URIError. The main matcher (findRouteMatch) caught it, but findFlatMatch (route masks) and findSingleMatch (router.matchRoute) did not — such URLs crashed matching outright. findMatch is now the single choke point converting URIError into "no match" (404), which is byte-neutral vs. the previous per-caller guard and structurally prevents a future fourth entry point from re-introducing the bug. Behavior is otherwise unchanged: malformed sequences still 404; valid ones decode exactly as before.

Centralization + enforcement

  • New router-core/src/string-encoding.ts owns all URL-path primitives (decodePath, encodePathParam, compileDecodeCharMap, escapeHtml, ...) with trust-boundary docs
  • ESLint bans raw encodeURIComponent / decodeURI* / btoa / atob outside that module (documented exceptions for the matcher's no-match contract and ssr/serializer base64)
  • Branded string kinds (EncodedPathParam, DecodedPathParam, EncodedPath, DecodedPath) wired through real signatures — e.g. custom decoders are type-contracted to receive encoded values

Tests added (fast-check property-based + concrete regressions)

Surface Coverage
Matcher totality of all 3 entry points against arbitrary/hostile paths; encode→interpolate→decode→match round-trips; open-redirect defense
Search params parse never throws; null prototypes always; JSON round-trip symmetry; __proto__ safety
SSR inline scripts adversarial scroll-restoration keys can't break <script> context and round-trip semantically; injected code provably never executes; seroval factory interpolation canary
Frame protocol client frame-decoder (previously untested): exact round-trips, chunk-boundary independence, DoS caps (16MiB/frame etc.), fast-fail on hostile length headers
Server functions GET payload size cap rejects before invoking the fn; malformed payloads → 500 not crash; method check before parsing; server context wins over client context
Build-time IDs virtual-module base64url payload round-trips; distinct violations → distinct IDs; hostile payloads degrade to safe defaults
Early hints / prerender Link-header param injection impossible outside quoted strings; protocol-relative prerender paths rejected

Documented quirks (deliberately not changed)

  • Legacy * splat syntax collision: splat value '*' interpolates to /files/* and resolves to the legacy route with empty params (reproduced; fix sketched in docs, needs e2e coverage)
  • Default search-param parser JSON-coerces values that look like JSON ('?q=%2042' → number)
  • Early-hints href is interpolated verbatim (manifest-controlled today)

Test plan

  • router-core: 110 files / 1663 tests pass (incl. new property suites)
  • start-client-core: 94 pass · start-server-core: 130 pass · start-plugin-core: 513 pass · react-router: 1036 pass
  • eslint clean (new boundary rules active), typecheck clean across TS versions
  • benchmarks: matcher module −40 raw bytes vs base; package-wide gzip net −165 incl. new module (tests/string-encoding.bench.ts)

Centralize all URL-path encoding/decoding primitives in a single
string-encoding module with trust-boundary documentation, branded
string kinds, and ESLint enforcement banning raw encodeURIComponent/
decodeURI*/btoa/atob elsewhere.

Fixes a real crash: malformed percent-encoding (e.g. /post/%E4%BD)
threw URIError out of extractParams through findFlatMatch (route
masks) and findSingleMatch (router.matchRoute), which had no guard.
findMatch is now the single choke point converting URIError into a
null match (404), byte-neutral vs the previous per-caller guard.

Adds fast-check property-based and concrete security tests for every
encoding surface identified in docs/string-handling.md:
- matcher totality, path param round-trips, open-redirect defense
- search-param parse safety, null prototypes, JSON coercion contract
- SSR inline-script XSS resistance (adversarial scroll-restoration
  keys) and seroval factory interpolation canary
- frame protocol round-trips and client frame-decoder DoS limits
- server-fn payload handling (size cap, method check, context merge,
  malformed input)
- virtual-module base64url ID round-trips and hostile payload fallbacks
- early-hints Link-header injection resistance and prerender SSRF

Documents known quirks (legacy '*' splat collision, search-param JSON
coercion, early-hints href interpolation) instead of silently changing
behavior.
@nx-cloud

nx-cloud Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

View your CI Pipeline Execution ↗ for commit b1fcee2

Command Status Duration Result
nx affected --targets=test:eslint,test:unit,tes... ❌ Failed 11m 59s View ↗
nx run-many --target=build --exclude=examples/*... ✅ Succeeded 1m 29s View ↗

☁️ Nx Cloud last updated this comment at 2026-08-21 22:00:01 UTC

@github-actions

Copy link
Copy Markdown
Contributor

🚀 Changeset Version Preview

7 package(s) bumped directly, 16 bumped as dependents.

🟩 Patch bumps

Package Version Reason
@tanstack/react-router 1.170.31 → 1.170.32 Changeset
@tanstack/router-core 1.171.26 → 1.171.27 Changeset
@tanstack/solid-router 1.170.29 → 1.170.30 Changeset
@tanstack/start-client-core 1.170.26 → 1.170.27 Changeset
@tanstack/start-plugin-core 1.171.38 → 1.171.39 Changeset
@tanstack/start-server-core 1.169.30 → 1.169.31 Changeset
@tanstack/vue-router 1.170.28 → 1.170.29 Changeset
@tanstack/react-start 1.168.48 → 1.168.49 Dependent
@tanstack/react-start-client 1.168.29 → 1.168.30 Dependent
@tanstack/react-start-rsc 0.1.47 → 0.1.48 Dependent
@tanstack/react-start-server 1.167.36 → 1.167.37 Dependent
@tanstack/router-cli 1.167.32 → 1.167.33 Dependent
@tanstack/router-generator 1.167.32 → 1.167.33 Dependent
@tanstack/router-plugin 1.168.34 → 1.168.35 Dependent
@tanstack/router-vite-plugin 1.167.34 → 1.167.35 Dependent
@tanstack/solid-start 1.168.46 → 1.168.47 Dependent
@tanstack/solid-start-client 1.168.28 → 1.168.29 Dependent
@tanstack/solid-start-server 1.167.35 → 1.167.36 Dependent
@tanstack/start-static-server-functions 1.167.31 → 1.167.32 Dependent
@tanstack/start-storage-context 1.167.28 → 1.167.29 Dependent
@tanstack/vue-start 1.168.45 → 1.168.46 Dependent
@tanstack/vue-start-client 1.167.31 → 1.167.32 Dependent
@tanstack/vue-start-server 1.167.35 → 1.167.36 Dependent

@coderabbitai

coderabbitai Bot commented Aug 21, 2026

Copy link
Copy Markdown
Contributor

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 5f470c6e-bc8c-4ae5-a98f-d24e87a5f512

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@socket-security

Copy link
Copy Markdown

Review the following changes in direct dependencies. Learn more about Socket for GitHub.

Diff Package Supply Chain
Security
Vulnerability Quality Maintenance License
Addedfast-check@​4.9.010010010087100

View full report

@pkg-pr-new

pkg-pr-new Bot commented Aug 21, 2026

Copy link
Copy Markdown
More templates

@tanstack/arktype-adapter

npm i https://pkg.pr.new/@tanstack/arktype-adapter@8141

@tanstack/eslint-plugin-router

npm i https://pkg.pr.new/@tanstack/eslint-plugin-router@8141

@tanstack/eslint-plugin-start

npm i https://pkg.pr.new/@tanstack/eslint-plugin-start@8141

@tanstack/history

npm i https://pkg.pr.new/@tanstack/history@8141

@tanstack/nitro-v2-vite-plugin

npm i https://pkg.pr.new/@tanstack/nitro-v2-vite-plugin@8141

@tanstack/react-router

npm i https://pkg.pr.new/@tanstack/react-router@8141

@tanstack/react-router-devtools

npm i https://pkg.pr.new/@tanstack/react-router-devtools@8141

@tanstack/react-router-ssr-query

npm i https://pkg.pr.new/@tanstack/react-router-ssr-query@8141

@tanstack/react-start

npm i https://pkg.pr.new/@tanstack/react-start@8141

@tanstack/react-start-client

npm i https://pkg.pr.new/@tanstack/react-start-client@8141

@tanstack/react-start-rsc

npm i https://pkg.pr.new/@tanstack/react-start-rsc@8141

@tanstack/react-start-server

npm i https://pkg.pr.new/@tanstack/react-start-server@8141

@tanstack/router-cli

npm i https://pkg.pr.new/@tanstack/router-cli@8141

@tanstack/router-core

npm i https://pkg.pr.new/@tanstack/router-core@8141

@tanstack/router-devtools

npm i https://pkg.pr.new/@tanstack/router-devtools@8141

@tanstack/router-devtools-core

npm i https://pkg.pr.new/@tanstack/router-devtools-core@8141

@tanstack/router-generator

npm i https://pkg.pr.new/@tanstack/router-generator@8141

@tanstack/router-plugin

npm i https://pkg.pr.new/@tanstack/router-plugin@8141

@tanstack/router-ssr-query-core

npm i https://pkg.pr.new/@tanstack/router-ssr-query-core@8141

@tanstack/router-utils

npm i https://pkg.pr.new/@tanstack/router-utils@8141

@tanstack/router-vite-plugin

npm i https://pkg.pr.new/@tanstack/router-vite-plugin@8141

@tanstack/solid-router

npm i https://pkg.pr.new/@tanstack/solid-router@8141

@tanstack/solid-router-devtools

npm i https://pkg.pr.new/@tanstack/solid-router-devtools@8141

@tanstack/solid-router-ssr-query

npm i https://pkg.pr.new/@tanstack/solid-router-ssr-query@8141

@tanstack/solid-start

npm i https://pkg.pr.new/@tanstack/solid-start@8141

@tanstack/solid-start-client

npm i https://pkg.pr.new/@tanstack/solid-start-client@8141

@tanstack/solid-start-server

npm i https://pkg.pr.new/@tanstack/solid-start-server@8141

@tanstack/start-client-core

npm i https://pkg.pr.new/@tanstack/start-client-core@8141

@tanstack/start-fn-stubs

npm i https://pkg.pr.new/@tanstack/start-fn-stubs@8141

@tanstack/start-plugin-core

npm i https://pkg.pr.new/@tanstack/start-plugin-core@8141

@tanstack/start-server-core

npm i https://pkg.pr.new/@tanstack/start-server-core@8141

@tanstack/start-static-server-functions

npm i https://pkg.pr.new/@tanstack/start-static-server-functions@8141

@tanstack/start-storage-context

npm i https://pkg.pr.new/@tanstack/start-storage-context@8141

@tanstack/valibot-adapter

npm i https://pkg.pr.new/@tanstack/valibot-adapter@8141

@tanstack/virtual-file-routes

npm i https://pkg.pr.new/@tanstack/virtual-file-routes@8141

@tanstack/vue-router

npm i https://pkg.pr.new/@tanstack/vue-router@8141

@tanstack/vue-router-devtools

npm i https://pkg.pr.new/@tanstack/vue-router-devtools@8141

@tanstack/vue-router-ssr-query

npm i https://pkg.pr.new/@tanstack/vue-router-ssr-query@8141

@tanstack/vue-start

npm i https://pkg.pr.new/@tanstack/vue-start@8141

@tanstack/vue-start-client

npm i https://pkg.pr.new/@tanstack/vue-start-client@8141

@tanstack/vue-start-server

npm i https://pkg.pr.new/@tanstack/vue-start-server@8141

@tanstack/zod-adapter

npm i https://pkg.pr.new/@tanstack/zod-adapter@8141

commit: b1fcee2

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Benchmarks

  • Commit: 255546ac944f
  • Measured at: 2026-08-21T21:49:02.592Z
  • Baseline source: history:cb281d70c1f5
  • Dashboard: bundle-size history

The following scenarios have bundle-size changes compared with the baseline:

Scenario Current (gzip) Delta vs baseline Initial gzip Raw Brotli Trend
react-router.minimal 83.84 KiB -9 B (-0.01%) 83.71 KiB 262.73 KiB 72.95 KiB ▆▆▃▃▁▁▅▅▅▃█▆
react-router.full 87.34 KiB -3 B (-0.00%) 87.21 KiB 274.45 KiB 76.06 KiB ▅▅▃▃▁▁▇▇▇▄█▇
solid-router.minimal 33.20 KiB +4 B (+0.01%) 33.08 KiB 96.60 KiB 29.96 KiB ▁▁▁▁▆▆▇▇▇▇██
solid-router.full 38.04 KiB +9 B (+0.02%) 37.92 KiB 111.24 KiB 34.19 KiB ▁▁▁▁▆▆███▇▇█
vue-router.minimal 49.53 KiB -6 B (-0.01%) 49.41 KiB 138.63 KiB 44.76 KiB ▁▁▁▁▂▂███▄▇▆
vue-router.full 55.13 KiB -9 B (-0.02%) 55.01 KiB 156.84 KiB 49.64 KiB ▁▁▁▁▂▂███▄▇▅
react-start.minimal 96.74 KiB -3 B (-0.00%) 96.61 KiB 305.02 KiB 83.76 KiB ▂▂▁▁▅▅▇▇▇▆██
react-start.deferred-hydration 97.47 KiB -2 B (-0.00%) 96.62 KiB 306.38 KiB 84.50 KiB ▂▂▁▁▆▆▇▇▇▇██
react-start.full 99.90 KiB -6 B (-0.01%) 99.77 KiB 314.74 KiB 86.57 KiB ▁▁▁▁▅▅▇▇▇▆██
react-start.rsbuild.minimal 100.06 KiB +2 B (+0.00%) 99.88 KiB 315.29 KiB 86.36 KiB ▂▂▁▁▄▄███▆▇▇
react-start.rsbuild.minimal-iife 100.46 KiB +1 B (+0.00%) 100.30 KiB 316.23 KiB 86.68 KiB ▂▂▁▁▄▄███▆▇▇
react-start.rsbuild.full 103.37 KiB -10 B (-0.01%) 103.20 KiB 325.38 KiB 89.09 KiB ▂▂▁▁▄▄███▆▇▆
solid-start.minimal 46.04 KiB -2 B (-0.00%) 45.91 KiB 137.71 KiB 41.00 KiB ▁▁▁▁▇▇███▇██
solid-start.deferred-hydration 49.11 KiB -7 B (-0.01%) 45.97 KiB 145.17 KiB 43.74 KiB ▁▁▁▁▇▇███▇██
solid-start.full 51.12 KiB -4 B (-0.01%) 50.99 KiB 153.10 KiB 45.30 KiB ▁▁▁▁▆▆▇▇▇▇██
vue-start.minimal 65.68 KiB -3 B (-0.00%) 65.55 KiB 189.49 KiB 58.36 KiB ▁▁▁▁▆▆███▇██
vue-start.full 69.50 KiB -12 B (-0.02%) 69.37 KiB 201.80 KiB 61.75 KiB ▁▁▁▁▆▆███▇█▇

Current gzip tracks all emitted client JS chunks. Initial gzip tracks only the entry/import graph. Trend sparkline is historical current gzip ending with this PR measurement; lower is better.

@codspeed-hq

codspeed-hq Bot commented Aug 21, 2026

Copy link
Copy Markdown

Merging this PR will regress 10 benchmarks

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 8 improved benchmarks
❌ 10 regressed benchmarks
✅ 162 untouched benchmarks

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Memory mem client mount-unmount (solid) 481.8 KB 540.9 KB -10.93%
Memory mem server aborted-requests (react) 865.1 KB 948.9 KB -8.83%
Simulation client-nested-params navigation loop (react) 210.7 ms 227.4 ms -7.31%
Memory mem client interrupted-navigations (vue) 352.7 KB 377.4 KB -6.54%
Memory mem server error-paths redirect (react) 296.3 KB 313 KB -5.36%
Memory mem server request-churn (vue) 822.9 KB 866.4 KB -5.03%
Simulation client-async-pipeline navigation loop (react) 102.8 ms 107.4 ms -4.25%
Memory mem client navigation-churn (solid) 589.5 KB 613.6 KB -3.92%
Memory mem server streaming-peak chunked (vue) 11.2 MB 11.6 MB -3.55%
Memory mem client navigation-churn (vue) 1.6 MB 1.6 MB -3.35%
Memory mem server error-paths unmatched (react) 1,830.3 KB 416.5 KB ×4.4
Memory mem server error-paths not-found (vue) 2,071.7 KB 485.5 KB ×4.3
Memory mem server request-churn (react) 712.7 KB 656.6 KB +8.55%
Memory mem server server-fn-churn (react) 399.9 KB 370.9 KB +7.82%
Memory mem server error-paths not-found (react) 435.6 KB 407.4 KB +6.91%
Memory mem client unique-location-churn (vue) 463.2 KB 433.9 KB +6.75%
Memory mem server peak-large-page (solid) 1.1 MB 1.1 MB +6.04%
Memory mem server request-churn (solid) 746.4 KB 723.3 KB +3.19%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing feat/string-encoding-hardening (b1fcee2) with main (cb281d7)

Open in CodSpeed

@nx-cloud nx-cloud Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud is proposing a fix for your failed CI:

We corrected TypeScript type errors and ESLint import ordering issues introduced by the new test files added in this PR. The fixes address invalid fast-check API usage (maxKeys on fc.record), missing type imports (AsyncLocalStorage, proper ViolationInfo casting), untyped search-param return access, and import ordering/style violations across path.ts, router.ts, and frame-decoder.test.ts. These changes bring all six failing tasks (test:unit, test:types ×3, test:eslint ×2) back to green without altering any production logic.

Warning

  • We could not verify this fix.
  • The suggested diff is too large to display here, but you can view it on Nx Cloud ↗

Apply fix via Nx Cloud  Reject fix via Nx Cloud


Or Apply changes locally with:

npx nx-cloud apply-locally lS7L-msA5

Apply fix locally with your editor ↗   View interactive diff ↗



🎓 Learn more about Self-Healing CI on nx.dev

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant