add `access` route rule to restrict routes to internal or external callers only
メンテナーはふだん 2 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 初心者へのやさしさ
- 35/100
- issue の種類
- 機能追加
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- typescript
調査の方向性
caller の検出とルールの順序を理解するために、まず src/runtime/nitro.ts、src/runtime/internal/app.ts、src/runtime/internal/route-rules.ts から始めてください。次に、src/types/route-rules.ts と src/types/h3.ts にあるルート設定とリクエストコンテキストの型を確認し、その後 test/tests.ts の 6 つのケースを実行してください。内部、外部、制限なし、継承されたルールについて提案された動作がカバーされ、既存のテストがパスすれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Describe the feature
feat: add access route rule to restrict routes to internal or external callers only
Problem
Nitro's serverFetch() lets handlers call other routes in-process without going through the network. This is powerful, but currently there's no way to enforce who is allowed to reach a given route. Two common needs that are currently impossible to express:
- Internal-only helpers — routes that should only ever be called from within other handlers via
serverFetch(), and should not be reachable over HTTP (e.g. internal aggregation endpoints, service-layer helpers). - External-only routes — routes that should only accept real HTTP requests and never be called in-process (e.g. webhooks that rely on raw request integrity, or endpoints where calling them internally would be a programming error).
Proposed solution
A new access option in routeRules:
routeRules: {
// Only callable via serverFetch() from within other handlers
'/internal/**': { access: 'internal' },
// Only callable via real HTTP requests
'/api/webhook': { access: 'external' },
// Cancel a restriction inherited from a parent pattern (existing convention)
'/internal/public': { access: false },
}
| Value | Behavior |
|---|---|
"internal" |
Only reachable via serverFetch() in-process |
"external" |
Only reachable via real HTTP requests |
false |
Cancel a restriction inherited from a less-specific pattern |
| unset | Both (default — fully backwards-compatible) |
Disallowed callers receive 404 so the route's existence is not revealed.
Implementation
I've built a full implementation on a fork: MichaelDickBasecom/nitro @ feat/access-route-rule
Key pieces:
Detection — serverFetch() sets req.context.nitro.internal = true after the caller-provided context is merged, so it can't be spoofed by passing a crafted context object. Requests entering through the runtime's HTTP entry point never carry this flag. (src/runtime/nitro.ts, src/runtime/internal/app.ts)
Rule handler — registered as a runtime route rule with order: -2, so it runs before basicAuth (order: -1), redirect, proxy, and cache. Blocked callers are rejected before any auth challenge or forwarding happens. (src/runtime/internal/route-rules.ts)
Types — access is added to both NitroRouteConfig (user-facing) and the nitro request context. (src/types/route-rules.ts, src/types/h3.ts)
Tests — 6 test cases covering all combinations of caller type vs. restriction, including serverFetch being called from within a handler (the "proxy" fixture). (test/tests.ts)
All existing tests continue to pass.
Happy to open a PR if this direction looks good to the maintainers. Open to feedback on the rule name, the 404 vs 403 choice for blocked callers, or anything else.
Additional information
- Would you be willing to help implement this feature?
- 主要言語
- TypeScript
- スター
- 11.5k
- フォーク
- 968
- 平均マージ
- 4日 9時間
- マージ済み PR(30日)
- 64
環境構築
このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートあり
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
nitrojs/nitro のほかの issue
-
pending triage
難易度 1/5 1時間未満 初心者へのやさしさ 92/100
メンテナーはふだん 2 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 2 日以内に返信
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler config対応中かも @draarivpatel-ui が 13 日前に担当しました。 オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 73/100
メンテナーはふだん 2 日以内に返信
-
documentation
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
メンテナーはふだん 2 日以内に返信
-
pending triage
難易度 5/5 1週間以上 初心者へのやさしさ 30/100
nitrojs/nitro#5205 · リアクション 1 件 ·
メンテナーはふだん 2 日以内に返信
似ている issue
-
bug data-types
難易度 2/5 1〜3時間 初心者へのやさしさ 88/100
ClickHouse/clickhouse-js#1293 ·
メンテナーはふだん 1 日以内に返信
-
area: middleware enhancement good first issue
難易度 2/5 1〜3時間 初心者へのやさしさ 68/100
-
agent/quality testing
難易度 1/5 1時間未満 初心者へのやさしさ 95/100
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 92/100
メンテナーはふだん 2 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
juspay/agent-distro#203 ·
メンテナーはふだん 1 日以内に返信