add `access` route rule to restrict routes to internal or external callers only
I maintainer di solito rispondono entro 2 giorni
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
- Tipo di issue
- Funzionalità
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
- Ambito
- backend-api-design
Direzione di ricerca
Inizia da src/runtime/nitro.ts, src/runtime/internal/app.ts e src/runtime/internal/route-rules.ts per comprendere il rilevamento del chiamante e l'ordine delle regole. Esamina i tipi per la configurazione delle route e per il contesto della richiesta in src/types/route-rules.ts e src/types/h3.ts, quindi esegui i sei casi in test/tests.ts. Il lavoro è completato quando i comportamenti proposti per le regole interne, esterne, senza restrizioni ed ereditate sono coperti e i test esistenti hanno esito positivo.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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?
- Lingua principale
- TypeScript
- Stelle
- 11.5k
- Fork
- 968
- Merge medio
- 4g 9h
- PR unite (30g)
- 64
Preparare l'ambiente
Avvia il container di sviluppo del progetto nel browser, con il tuo account GitHub.
- Nessun Dockerfile né file Docker Compose
- Ha un modello di pull request
- Leggi la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di nitrojs/nitro
-
pending triage
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 92/100
I maintainer di solito rispondono entro 2 giorni
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
I maintainer di solito rispondono entro 2 giorni
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configForse già presa @draarivpatel-ui l’ha presa 13 giorni fa. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 73/100
I maintainer di solito rispondono entro 2 giorni
-
documentation
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
I maintainer di solito rispondono entro 2 giorni
-
pending triage
Difficoltà 5/5 Più di una settimana Idoneità per principianti 30/100
nitrojs/nitro#5205 · 1 reazione ·
I maintainer di solito rispondono entro 2 giorni
Tutte le issue di nitrojs/nitro
Issue simili
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
amosblomqvist/learnharness#1141 ·
I maintainer di solito rispondono entro 4 giorni
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
ranxianglei/billion-context#8319 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 88/100
tencent-connect/dsh-qqbot#148 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
JimLiu/open-artifact#126 ·
-
redis.expireTime() returns relative TTL seconds on live host instead of Unix timestamp secondsAperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100