nodefony-protect-route

Restricts Nodefony routes to authorized users using firewall zones and route guards.

Updated Dec 19, 2023
One-click install
npx skills add https://github.com/nodefony/nodefony-core --skill nodefony-protect-route-nodefony
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: nodefony-protect-route
Source: https://github.com/nodefony/nodefony-core/tree/main/src/packages/%40nodefony/devkit/skills/nodefony-protect-route
Command: npx skills add https://github.com/nodefony/nodefony-core --skill nodefony-protect-route-nodefony

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Securing routes in a Nodefony application is error-prone when done by hand: checks written inside controller actions are invisible to the firewall, audits, and route introspection, and quick fixes like disabling CSRF protection silently open the application to attack. This Skill guides you to protect routes using the framework's own building blocks instead. ## Core Features & Use Cases - Two-layer protection: Combine firewall zones (URL prefix patterns in security config) with per-route guards via the @IsGranted decorator. - Role hierarchy: Declare role implications once (e.g. ROLE_ADMIN implies ROLE_BILLING) instead of duplicating role lists on accounts or actions. - Partner and machine access: Open routes to third-party origins via trustedOrigins without disabling CSRF, and serve API clients through a stateless apikey-authenticated zone. - Object-level permissions: Express business rules like "authors edit their own documents" with voters instead of inventing permission tables. - Use Case: You need an admin-only reporting endpoint. Declare the guard with @IsGranted("ROLE_REPORTS"), map ROLE_ADMIN to it in roleHierarchy, then prove it with three identities: anonymous refused, logged-in user without the role refused, admin served. ## Quick Start Ask the AI to protect a specific Nodefony route so only users with a given role can access it, using the framework firewall and guards rather than manual checks.

Frequently Asked Questions about nodefony-protect-route

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I protect a route in Nodefony?

Protect a Nodefony route by combining a firewall zone (a URL prefix pattern in security config) with a per-route guard using the @IsGranted("ROLE_X") decorator on the controller action. Never write manual role checks inside the action, since they are invisible to the firewall and introspection.

How do I give admins access without adding extra roles?

Declare a roleHierarchy in the security manifest, for example mapping ROLE_ADMIN to ["ROLE_BILLING", "ROLE_REPORTS"]. This defines the relationship once, instead of copying roles onto accounts or listing multiple roles on every guarded action.

Why does a partner POST request get rejected with a CSRF error?

The anti-forgery defense rejects unknown origins by design. Fix it by declaring the partner's full origin (scheme, host, port) in csrf.trustedOrigins. Never use @CsrfExempt or disable CSRF, which would let any site post through a logged-in user's browser.

How do I expose an API to scripts or services without cookies?

Place the route under the preconfigured /api/machine zone, which uses the apikey authenticator with stateless: true. A stateless zone opens no session and ignores incoming cookies, which suits clients that store nothing. Keys are issued via POST /nodefony/security/api/keys.

How do I check object-level permissions like document ownership?

Write a voter registered via registerVoterFactory and invoke it with the normal guard, for example @IsGranted("doc.edit", { subject: "id" }). This is the intended extension point, so there is no need to invent a permission table or test ownership inside the action.

How do I verify a route is actually protected?

Test with three identities: an anonymous caller must be refused, a logged-in user without the role must be refused, and an authorized user must be served. Also run npx nodefony inspect routes --json to confirm the guard sits on the intended route.