Skip to content

fix(dev): restrict /_nitro/tasks endpoint to local requests#4389

Open
winstoncrooker wants to merge 1 commit into
nitrojs:mainfrom
winstoncrooker:fix/dev-tasks-local-only
Open

fix(dev): restrict /_nitro/tasks endpoint to local requests#4389
winstoncrooker wants to merge 1 commit into
nitrojs:mainfrom
winstoncrooker:fix/dev-tasks-local-only

Conversation

@winstoncrooker

Copy link
Copy Markdown

Summary

The development task runner endpoints, /_nitro/tasks and /_nitro/tasks/:name, execute server tasks with caller-supplied payload ({ ...getQuery(event), ...body }) and have no access control. The dev server binds all network interfaces by default (devServer.hostname is unset in src/config/defaults.ts), so any host that can reach the dev server can enumerate the project's tasks and invoke them — for example a db:* migration or seed task — with attacker-controlled input. A co-located process or a different local user can do the same over loopback.

The VFS debug viewer already restricts itself to loopback requests (createVFSHandler in src/dev/vfs.ts), so the framework already treats dev debug surfaces as local-only; the task runner just did not follow the same rule. (The preview server also hard-codes --host localhost, while the dev server defaults to all interfaces.)

Change

  • Extract the loopback check from vfs.ts into a shared isLocalDevRequest helper (src/dev/_request.ts).
  • Apply it to /_nitro/tasks and /_nitro/tasks/** at the dev-app layer — the same layer as the VFS viewer, where the real client socket is visible (the task routes are otherwise handled by the worker via the catch-all).

Verification

With test/fixture (which enables experimental.tasks), running the dev server:

  • GET /_nitro/tasks and GET /_nitro/tasks/db:migrate continue to work (HTTP 200) over loopback (127.0.0.1).
  • The same requests to the machine's LAN address now return 403 Forbidden IP instead of executing.
  • /_vfs/ behaves identically to before (loopback 200, non-loopback 403), now via the shared helper.

Scope and alternatives

Dev-server only; production output is unaffected, and the task routes require the experimental tasks feature. An Origin/CSRF check would additionally harden the drive-by-from-a-visited-page vector, and binding the dev server to localhost by default (as the preview server already does) would be a broader option. This change keeps to the minimal, behavior-preserving fix that mirrors the existing VFS gate. Happy to add a regression test or take a different approach if you prefer.

🤖 Generated with Claude Code

The dev task runner (/_nitro/tasks and /_nitro/tasks/:name) executes server
tasks with caller-supplied payload and had no access control, while the dev
server binds all interfaces by default (devServer.hostname is unset). Any host
that can reach the dev server could enumerate and run tasks. The VFS viewer
already restricts itself to loopback requests; this applies the same check to
the task runner, sharing the logic in a new isLocalDevRequest helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@winstoncrooker winstoncrooker requested a review from pi0 as a code owner June 27, 2026 04:04
@vercel

vercel Bot commented Jun 27, 2026

Copy link
Copy Markdown

@winstoncrooker 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 Jun 27, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Adds isLocalDevRequest to classify loopback-origin dev requests from request socket/runtime data and normalized client IPs. src/dev/app.ts now blocks non-local /_nitro/tasks requests, and src/dev/vfs.ts reuses the same helper for its 403 check.

Changes

Local dev access control

Layer / File(s) Summary
Local request helper
src/dev/_request.ts
Defines isLocalDevRequest to resolve and normalize the request IP and return whether it matches loopback addresses.
Dev access enforcement
src/dev/app.ts, src/dev/vfs.ts
Imports the shared helper, adds assertLocalTaskRequest for /_nitro/tasks routes, and replaces the VFS inline locality check with the shared helper and generic 403 status text.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Possibly related PRs

  • nitrojs/nitro#4188: Adjusts the same /_nitro/tasks dev surface with route handling and payload parsing changes.
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title follows conventional commit style and accurately reflects the dev-task local-access restriction.
Description check ✅ Passed The description is clearly related to the change set and explains the task-route access control fix.
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.
✨ Finishing Touches
🧪 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.

@coderabbitai coderabbitai 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.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@src/dev/app.ts`:
- Line 73: The 403 thrown from the development app bootstrap should use an
actionable message instead of the current generic “Forbidden IP” text. Update
the HTTPError in app.ts so it clearly tells local developers that access is
restricted to localhost/loopback and what to change, and keep the logic in the
dev server access check that rejects non-local requests without echoing the
client IP.

In `@src/dev/vfs.ts`:
- Line 8: The VFS access denial in the code path that throws HTTPError should
use an actionable localhost-focused message instead of the generic “Forbidden
IP”. Update the statusText in the vfs denial logic so it tells local developers
that only localhost access is allowed, without exposing the computed IP, and
keep the change within the existing HTTPError throw site.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 782191b5-dd67-4b23-88ee-99ab1d4f6b99

📥 Commits

Reviewing files that changed from the base of the PR and between 83acc44 and 1d0ec6c.

📒 Files selected for processing (3)
  • src/dev/_request.ts
  • src/dev/app.ts
  • src/dev/vfs.ts

Comment thread src/dev/app.ts
// all interfaces by default (`devServer.hostname` is unset).
const assertLocalTaskRequest = (event: H3Event) => {
if (!isLocalDevRequest(event)) {
throw new HTTPError({ statusText: "Forbidden IP", status: 403 });

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Use an actionable 403 message.

Line 73 returns only "Forbidden IP", which doesn’t tell a local developer what to fix. Prefer a message that states the localhost requirement without echoing the client IP. As per coding guidelines, "Include actionable context in error messages."

Proposed fix
-        throw new HTTPError({ statusText: "Forbidden IP", status: 403 });
+        throw new HTTPError({
+          message: "Dev task runner is only available from localhost.",
+          status: 403,
+        });
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
throw new HTTPError({ statusText: "Forbidden IP", status: 403 });
throw new HTTPError({
message: "Dev task runner is only available from localhost.",
status: 403,
});
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/dev/app.ts` at line 73, The 403 thrown from the development app bootstrap
should use an actionable message instead of the current generic “Forbidden IP”
text. Update the HTTPError in app.ts so it clearly tells local developers that
access is restricted to localhost/loopback and what to change, and keep the
logic in the dev server access check that rejects non-local requests without
echoing the client IP.

Source: Coding guidelines

Comment thread src/dev/vfs.ts
status: 403,
});
if (!isLocalDevRequest(event)) {
throw new HTTPError({ statusText: "Forbidden IP", status: 403 });

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.

📐 Maintainability & Code Quality | 🟡 Minor | ⚡ Quick win

Make the VFS denial message actionable.

"Forbidden IP" is generic and doesn’t tell a local developer the expected access pattern. Prefer a localhost-specific message without exposing the computed IP. As per coding guidelines, "Include actionable context in error messages."

Proposed fix
-      throw new HTTPError({ statusText: "Forbidden IP", status: 403 });
+      throw new HTTPError({
+        message: "VFS viewer is only available from localhost.",
+        status: 403,
+      });
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/dev/vfs.ts` at line 8, The VFS access denial in the code path that throws
HTTPError should use an actionable localhost-focused message instead of the
generic “Forbidden IP”. Update the statusText in the vfs denial logic so it
tells local developers that only localhost access is allowed, without exposing
the computed IP, and keep the change within the existing HTTPError throw site.

Source: Coding guidelines

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