Skip to content

fix(cloudflare): fix baseURL traversal for wrangler assets dir - #4257

Merged
pi0 merged 2 commits into
nitrojs:mainfrom
jel-massih:fix/cloudflare-baseurl-traversal
Sep 3, 2026
Merged

pi0 merged 2 commits into
nitrojs:mainfrom
jel-massih:fix/cloudflare-baseurl-traversal

Conversation

@jel-massih

@jel-massih jel-massih commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

"..".repeat(N) concatenates without a separator, so for N >= 2 it produces "...." / "......" instead of "../.." / "../../..". With a 2+ segment baseURL (e.g. /foo/bar), cloudflare-module builds generate a wrangler.json whose assets.directory resolves to a non-existent .... subdirectory, breaking wrangler deploy and static asset serving.

Fix: "..".repeat(N) → "../".repeat(N) so the traversal works as expected

Reproduction Steps:

Build any cloudflare-module (or cloudflare-durable) project with a baseURL of 2+ segments, e.g.:

// nitro.config.ts
export default defineNitroConfig({
  preset: "cloudflare-module",
  baseURL: "/foo/bar",
});

Then check the generated .output/server/wrangler.json: assets.directory value

Before fix:

{
  "compatibility_date": "2026-05-08",
  "main": "index.mjs",
  "assets": {
    "binding": "ASSETS",
    "directory": "../public/foo/bar/...."
  },
  ...
}

After fix:

{
  "compatibility_date": "2026-05-08",
  "main": "index.mjs",
  "assets": {
    "binding": "ASSETS",
    "directory": "../public"
  },
...
}

@jel-massih
jel-massih requested a review from pi0 as a code owner May 11, 2026 02:40
@vercel

vercel Bot commented May 11, 2026

Copy link
Copy Markdown

@jel-massih is attempting to deploy a commit to the Nitro Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented May 11, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Team

Run ID: 9a3d2e29-8389-46df-80b3-c4242ea4ce8f

📥 Commits

Reviewing files that changed from the base of the PR and between 5113c78 and b7969ff.

📒 Files selected for processing (1)
  • src/presets/cloudflare/utils.ts

📝 Walkthrough

Walkthrough

The Cloudflare preset now generates the module target's assets directory path with repeated ../ segments. This changes the relative path format produced by writeWranglerConfig.

Changes

Wrangler Module Target Path Formatting

Layer / File(s) Summary
Assets Directory Path Formatting
src/presets/cloudflare/utils.ts
The module target repeats ../ for each base URL segment when it computes overrides.assets.directory.

Estimated code review effort: 1 (Trivial) | ~2 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title follows conventional commits format with 'fix' type prefix and includes a specific, accurate description of the fix related to baseURL traversal for Cloudflare wrangler assets directory.
Description check ✅ Passed The PR description clearly explains the bug, provides reproduction steps with before/after examples, and directly relates to the code changes made.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@jel-massih jel-massih changed the title fix(cloudflare): fix baseURL traversal for assets dir fix(cloudflare): fix baseURL traversal for wrangler assets dir May 11, 2026
@pi0

pi0 commented May 11, 2026

Copy link
Copy Markdown
Member

Thnx. Can you please provide reproductin steps?

@jel-massih

Copy link
Copy Markdown
Contributor Author

Thnx. Can you please provide reproductin steps?

Sure! Updated PR with hopefully useful repro steps.

Validated issue with basically these commands

mkdir nitro-cf-baseurl-repro && cd nitro-cf-baseurl-repro
npm init -y
npm pkg set type=module
echo 'export default { preset: "cloudflare-module", baseURL: "/foo/bar" }' > nitro.config.ts
npx nitro build
grep -A2 assets .output/server/wrangler.json

with grep output:

  "assets": {
    "binding": "ASSETS",
    "directory": "../public/foo/bar/...."

@pi0x pi0x added bug Something isn't working (PRs; issues use the Bug type) preset:cloudflare v3 labels Sep 2, 2026
…e-baseurl-traversal

# Conflicts:
#	src/presets/cloudflare/utils.ts
@coderabbitai

coderabbitai Bot commented Sep 3, 2026

Copy link
Copy Markdown
Contributor

Note

GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer.

@pi0
pi0 merged commit 98793c7 into nitrojs:main Sep 3, 2026
2 of 4 checks passed
@pi0x pi0x mentioned this pull request Sep 3, 2026
@pi0x pi0x removed the v3 label Nov 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working (PRs; issues use the Bug type) preset:cloudflare

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants