Skip to content

fix(modernjs): harden SSR bundle serving against path traversal - #4983

Open
tonoizer wants to merge 2 commits into
module-federation:mainfrom
tonoizer:fix/modernjs-ssr-bundle-serving
Open

fix(modernjs): harden SSR bundle serving against path traversal#4983
tonoizer wants to merge 2 commits into
module-federation:mainfrom
tonoizer:fix/modernjs-ssr-bundle-serving

Conversation

@tonoizer

@tonoizer tonoizer commented Aug 11, 2026

Copy link
Copy Markdown
Contributor

Summary

  • Confine Modern.js SSR /bundles static middleware to the bundles root (reject .. / escapes) in both @module-federation/modern-js and @module-federation/modern-js-v3.
  • Harden the SSR JSON middleware the same way: require a real .json extension, strip query/hash, and keep reads under dist/.
  • Set Content-Length from UTF-8 byte length (not JS string length) so non-ASCII federated chunks are not truncated, and charge the file cache by byte size.

Testing

  • pnpm --filter @module-federation/modern-js exec rstest src/server/staticMiddleware.spec.ts (15/15)
  • pnpm --filter @module-federation/modern-js-v3 exec rstest src/server/staticMiddleware.spec.ts (15/15)
  • Manual eslint for both packages (ESLINT_USE_FLAT_CONFIG=false)

Risks

  • Path joining for URL prefixes now uses POSIX-style joins (Windows-safe); filesystem resolution still uses path.resolve under the bundles/dist roots.

Related

Confine /bundles and SSR JSON middleware to their roots and set Content-Length from UTF-8 byte length so non-ASCII federated chunks are not truncated.

Co-authored-by: Cursor <cursoragent@cursor.com>
@changeset-bot

changeset-bot Bot commented Aug 11, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 54021d8

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 48 packages
Name Type
@module-federation/modern-js Patch
@module-federation/modern-js-v3 Patch
shared-tree-shaking-with-server-host Patch
shared-tree-shaking-with-server-provider Patch
@module-federation/runtime Patch
@module-federation/enhanced Patch
@module-federation/rspack Patch
@module-federation/webpack-bundler-runtime Patch
@module-federation/sdk Patch
@module-federation/runtime-tools Patch
@module-federation/managers Patch
@module-federation/manifest Patch
@module-federation/dts-plugin Patch
@module-federation/third-party-dts-extractor Patch
@module-federation/devtools Patch
@module-federation/bridge-react Patch
@module-federation/bridge-vue3 Patch
@module-federation/bridge-shared Patch
@module-federation/bridge-react-webpack-plugin Patch
@module-federation/retry-plugin Patch
@module-federation/rsbuild-plugin Patch
@module-federation/rstest Patch
@module-federation/error-codes Patch
@module-federation/inject-external-runtime-core-plugin Patch
@module-federation/runtime-core Patch
create-module-federation Patch
@module-federation/cli Patch
@module-federation/rspress-plugin Patch
@module-federation/treeshake-server Patch
@module-federation/treeshake-frontend Patch
@module-federation/metro Patch
@module-federation/metro-plugin-rnef Patch
@module-federation/metro-plugin-rock Patch
@module-federation/metro-plugin-rnc-cli Patch
@module-federation/esbuild Patch
@module-federation/nextjs-mf Patch
@module-federation/node Patch
@module-federation/observability-plugin Patch
@module-federation/playground Patch
website-new Patch
@module-federation/storybook-addon Patch
shared-tree-shaking-no-server-host Patch
shared-tree-shaking-no-server-provider Patch
@module-federation/utilities Patch
remote5 Patch
remote6 Patch
node-dynamic-remote-new-version Patch
node-dynamic-remote Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8903f302b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/modernjs/src/server/staticMiddleware.ts Outdated
@tonoizer
tonoizer marked this pull request as draft August 11, 2026 17:46
@tonoizer
tonoizer marked this pull request as ready for review August 11, 2026 17:47

@chatgpt-codex-connector chatgpt-codex-connector Bot 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.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 8903f302b1

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread packages/modernjs/src/cli/ssrPlugin.ts Outdated
@pkg-pr-new

pkg-pr-new Bot commented Aug 17, 2026

Copy link
Copy Markdown

Open in StackBlitz

@module-federation/devtools

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/devtools@54021d8

@module-federation/cli

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/cli@54021d8

create-module-federation

pnpm add https://pkg.pr.new/module-federation/core/create-module-federation@54021d8

@module-federation/dts-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/dts-plugin@54021d8

@module-federation/enhanced

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/enhanced@54021d8

@module-federation/error-codes

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/error-codes@54021d8

@module-federation/esbuild

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/esbuild@54021d8

@module-federation/managers

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/managers@54021d8

@module-federation/manifest

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/manifest@54021d8

@module-federation/metro

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro@54021d8

@module-federation/metro-plugin-rnc-cli

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro-plugin-rnc-cli@54021d8

@module-federation/metro-plugin-rnef

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro-plugin-rnef@54021d8

@module-federation/metro-plugin-rock

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/metro-plugin-rock@54021d8

@module-federation/modern-js

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/modern-js@54021d8

@module-federation/modern-js-v3

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/modern-js-v3@54021d8

@module-federation/native-federation-tests

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/native-federation-tests@54021d8

@module-federation/native-federation-typescript

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/native-federation-typescript@54021d8

@module-federation/nextjs-mf

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/nextjs-mf@54021d8

@module-federation/node

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/node@54021d8

@module-federation/observability-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/observability-plugin@54021d8

@module-federation/playground

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/playground@54021d8

@module-federation/retry-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/retry-plugin@54021d8

@module-federation/rsbuild-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rsbuild-plugin@54021d8

@module-federation/rspack

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rspack@54021d8

@module-federation/rspress-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rspress-plugin@54021d8

@module-federation/rstest

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/rstest@54021d8

@module-federation/runtime

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime@54021d8

@module-federation/runtime-core

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime-core@54021d8

@module-federation/runtime-tools

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/runtime-tools@54021d8

@module-federation/sdk

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/sdk@54021d8

@module-federation/storybook-addon

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/storybook-addon@54021d8

@module-federation/third-party-dts-extractor

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/third-party-dts-extractor@54021d8

@module-federation/treeshake-frontend

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/treeshake-frontend@54021d8

@module-federation/treeshake-server

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/treeshake-server@54021d8

@module-federation/typescript

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/typescript@54021d8

@module-federation/utilities

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/utilities@54021d8

@module-federation/webpack-bundler-runtime

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/webpack-bundler-runtime@54021d8

@module-federation/bridge-react

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-react@54021d8

@module-federation/bridge-react-webpack-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-react-webpack-plugin@54021d8

@module-federation/bridge-shared

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-shared@54021d8

@module-federation/bridge-vue3

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/bridge-vue3@54021d8

@module-federation/inject-external-runtime-core-plugin

pnpm add https://pkg.pr.new/module-federation/core/@module-federation/inject-external-runtime-core-plugin@54021d8

commit: 54021d8

@github-actions

Copy link
Copy Markdown
Contributor

Bundle Size Report

8 package(s) changed, 35 unchanged.

Package dist + ESM entry

Package Total dist (raw) Delta ESM gzip Delta
@module-federation/modern-js 201.6 kB +1014 B (+0.5%) 1.2 kB no change
@module-federation/modern-js-v3 194.9 kB +1014 B (+0.5%) 876 B no change

Bundle targets

Package Web bundle (gzip) Delta Node bundle (gzip) Delta
@module-federation/cli 2.3 kB -3 B (-0.1%) 2.4 kB -31 B (-1.3%)
@module-federation/core 1.0 kB -2 B (-0.2%) 1.0 kB -33 B (-3.0%)
@module-federation/devtools 30.3 kB -1 B (-0.0%) 30.3 kB -24 B (-0.1%)
@module-federation/enhanced 2.7 kB -1 B (-0.0%) 2.8 kB -43 B (-1.5%)
@module-federation/metro-plugin-rnc-cli 416 B no change 435 B -25 B (-5.4%)
@module-federation/modern-js 5.1 kB +69 B (+1.3%) 5.1 kB +69 B (+1.3%)
@module-federation/modern-js-v3 5.0 kB +68 B (+1.3%) 5.0 kB +68 B (+1.3%)
@module-federation/node 9.2 kB +3 B (+0.0%) 9.2 kB -28 B (-0.3%)

Consumer scenarios

Scenario Web output (gzip) Delta Node output (gzip) Delta Gap (node-web) Delta
Enhanced remoteEntry 21.6 kB -11 B (-0.0%) 23.1 kB -14 B (-0.1%) +1.5 kB -3 B

Total dist (raw): 35.88 MB (+2.0 kB (+0.0%))
Total ESM gzip: 109.3 kB (no change)
Total web bundle (gzip): 238.3 kB (+133 B (+0.1%))
Total node bundle (gzip): 240.6 kB (-47 B (-0.0%))
Tracked ./bundler entry gzip: 556 B (no change)
Tracked ./bundler web bundle (gzip): 4.8 kB (no change)
Tracked ./bundler node bundle (gzip): 4.8 kB (no change)

Bundle sizes are generated with rslib (Rspack). Package-root metrics preserve the historical report. Tracked subpath exports such as ./bundler are measured separately so ENV_TARGET-driven tree-shaking is visible. Bare imports are externalized to keep package-level sizes consistent, and assets are emitted as resources.

@2heal1

2heal1 commented Aug 18, 2026

Copy link
Copy Markdown
Member

Thanks for working on this. The path traversal and UTF-8 Content-Length issues addressed by this PR are valid.

However, the current PR does not pass the @module-federation/modern-js-v3 test suite. In ssrPlugin.spec.ts, dev.setupMiddlewares is configured as an array of handlers, but the test harness
invokes it as a function:

config.dev.setupMiddlewares(middlewares);

This causes all three ssrPlugin tests to fail with TypeError: config.dev.setupMiddlewares is not a function.

Separately, we are currently planning the future direction of the Modern.js Module Federation integration. This includes reconsidering the ownership and design of its SSR asset-serving
behavior, so we do not plan to move forward with this targeted implementation at the moment.

We will revisit these security and correctness fixes as part of that broader planning. For now, we are going to close this PR. Thanks again for identifying and working on these issues.

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.

2 participants