add `access` route rule to restrict routes to internal or external callers only
Los mantenedores suelen responder en 2 días
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- typescript
- Área
- backend-api-design
Línea de trabajo
Empieza por src/runtime/nitro.ts, src/runtime/internal/app.ts y src/runtime/internal/route-rules.ts para entender la detección del llamador y el orden de las reglas. Revisa los tipos de configuración de rutas y de contexto de la solicitud en src/types/route-rules.ts y src/types/h3.ts, y luego ejecuta los seis casos de test/tests.ts. Se considera terminado cuando los comportamientos propuestos para reglas internas, externas, sin restricciones y heredadas están cubiertos y las pruebas existentes pasan.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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?
- Lenguaje dominante
- TypeScript
- Estrellas
- 11.5k
- Forks
- 968
- Merge medio
- 4 d 9 h
- PR fusionados (30 d)
- 64
Preparar el entorno
Inicia el contenedor de desarrollo del proyecto en tu navegador, con tu propia cuenta de GitHub.
- Sin Dockerfile ni archivo de Docker Compose
- Tiene una plantilla de pull request
- Leer la guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de nitrojs/nitro
-
pending triage
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
Los mantenedores suelen responder en 2 días
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
Los mantenedores suelen responder en 2 días
-
cloudflare: `nitro deploy` fails when a parent directory has a Wrangler configPosiblemente ocupada @draarivpatel-ui la tomó hace 13 días. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 73/100
Los mantenedores suelen responder en 2 días
-
documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
Los mantenedores suelen responder en 2 días
-
pending triage
Dificultad 5/5 Más de una semana Aptitud para principiantes 30/100
nitrojs/nitro#5205 · 1 reacción ·
Los mantenedores suelen responder en 2 días
Todos los issues de nitrojs/nitro
Issues similares
-
bug data-types
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
ClickHouse/clickhouse-js#1293 ·
Los mantenedores suelen responder en 1 día
-
area: middleware enhancement good first issue
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
-
agent/quality testing
Dificultad 1/5 Menos de una hora Aptitud para principiantes 95/100
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 92/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
juspay/agent-distro#203 ·
Los mantenedores suelen responder en 1 día