@@ -28,8 +28,7 @@ import {
2828import { corsOriginDelegate } from "./cors.js" ;
2929import { zipExtensionDist } from "./lib/extension-dist.js" ;
3030import {
31- isPublicOAuthRequest ,
32- isPublicWorkflowMetadataRequest
31+ isPublicAuthExemptRoute
3332} from "./lib/public-routes.js" ;
3433import {
3534 resolveTrustLocalhost ,
@@ -782,29 +781,19 @@ if (enforceAuth && process.env["NODETOOL_TRUST_LOCAL_NETWORKS"]) {
782781app . decorateRequest ( "userId" , null ) ;
783782app . decorateRequest ( "authToken" , null ) ;
784783
784+ // Global @fastify /rate-limit (registered above) runs before this hook on every
785+ // request, including public auth exemptions handled by isPublicAuthExemptRoute.
786+ // lgtm[js/missing-rate-limiting]
785787app . addHook ( "onRequest" , async ( req , reply ) => {
786788 // Let CORS preflight through — the @fastify/cors plugin handles OPTIONS responses
787789 if ( req . method === "OPTIONS" ) return ;
788790
789- // Public routes — no auth required
791+ // Public routes — no auth required (still rate-limited globally above).
790792 const pathname = req . url . split ( "?" ) [ 0 ] ;
791- const sdkDiscoveryRequest = isSdkV1DiscoveryRequest ( pathname , req . method ) ;
792793 if (
793- pathname === "/health" ||
794- pathname === "/ready" ||
795- pathname === "/api/health" ||
796- pathname === "/api/config" ||
797- isPublicOAuthRequest ( pathname ) ||
798- pathname === "/api/assets/packages" ||
799- pathname . startsWith ( "/api/assets/packages/" ) ||
800- pathname === "/api/nodes/metadata" ||
801- pathname . startsWith ( "/api/kie/webhook" ) ||
802- ( sdkDiscoveryRequest &&
803- ! isSdkV1AuthenticationRequired ( process . env , enforceAuth ) ) ||
804- // Trigger webhooks authenticate on their own, per registration secret
805- // (packages/websocket/src/triggers/webhook-route.ts) — no session exists.
806- pathname . startsWith ( "/api/webhooks/" ) ||
807- isPublicWorkflowMetadataRequest ( pathname , req . method )
794+ isPublicAuthExemptRoute ( pathname , req . method ) ||
795+ ( isSdkV1DiscoveryRequest ( pathname , req . method ) &&
796+ ! isSdkV1AuthenticationRequired ( process . env , enforceAuth ) )
808797 ) {
809798 return ;
810799 }
0 commit comments