[{"data":1,"prerenderedAt":429,"buildId":430},["ShallowReactive",2],{"docs-navigation-en":3,"examples-en":50,"page-\u002Fdocs\u002Fscope":237,"surround-\u002Fdocs\u002Fscope":424},[4],{"title":5,"path":6,"stem":7,"children":8,"page":49},"Docs","\u002Fdocs","docs",[9,13,17,21,25,29,33,37,41,45],{"title":10,"path":11,"stem":12},"Getting started","\u002Fdocs\u002Fgetting-started","docs\u002F01.getting-started",{"title":14,"path":15,"stem":16},"verifyUser","\u002Fdocs\u002Fverify-user","docs\u002F02.verify-user",{"title":18,"path":19,"stem":20},"Sites without users","\u002Fdocs\u002Fsites-without-users","docs\u002F03.sites-without-users",{"title":22,"path":23,"stem":24},"Build-time route check","\u002Fdocs\u002Froute-coverage","docs\u002F04.route-coverage",{"title":26,"path":27,"stem":28},"Public routes","\u002Fdocs\u002Fpublic-routes","docs\u002F05.public-routes",{"title":30,"path":31,"stem":32},"Same-origin writes","\u002Fdocs\u002Fsame-origin","docs\u002F06.same-origin",{"title":34,"path":35,"stem":36},"Scope and caching","\u002Fdocs\u002Fscope","docs\u002F07.scope",{"title":38,"path":39,"stem":40},"Configuration","\u002Fdocs\u002Fconfiguration","docs\u002F08.configuration",{"title":42,"path":43,"stem":44},"Migrating an existing BFF guard","\u002Fdocs\u002Fmigration","docs\u002F09.migration",{"title":46,"path":47,"stem":48},"Contributing","\u002Fdocs\u002Fcontributing","docs\u002F10.contributing",false,[51,61,69,77,83,90,98,106,113,122,131,138,146,153,159,166,174,180,188,194,202,208,215,221,229],{"path":52,"title":53,"description":54,"category":55,"order":56,"uses":57},"\u002Fexamples\u002Fcontact-form","Contact form on a corporate site","A mail-sending route that only your own pages can call, with a bot check and a rate limit.","visitor",1,[58,59,60],"access: 'visitor'","@nuxtjs\u002Fturnstile","nuxt-security",{"path":62,"title":63,"description":64,"category":55,"order":65,"uses":66},"\u002Fexamples\u002Fpaid-api-proxy","Search box that calls a paid API","Keep other sites and scripts from spending your API quota through your BFF.",2,[58,67,68],"rateLimiter","defineCachedFunction",{"path":70,"title":71,"description":72,"category":55,"order":73,"uses":74},"\u002Fexamples\u002Fclient-data","JSON for client-side pages","Data that your pages fetch in the browser, kept from being embedded by other sites.",3,[58,75,76],"access: 'public'","useFetch",{"path":78,"title":79,"description":80,"category":55,"order":81,"uses":82},"\u002Fexamples\u002Fmember-site-contact","Visitor routes inside a member app","Keep 'user' as the default and open a few routes to visitors without accounts.",4,[58,14],{"path":84,"title":85,"description":86,"category":87,"order":56,"uses":88},"\u002Fexamples\u002Fnuxt-auth-utils","nuxt-auth-utils","Use the sealed Cookie session of nuxt-auth-utils as the user check.","auth",[85,89],"requireUserSession",{"path":91,"title":92,"description":93,"category":87,"order":65,"uses":94},"\u002Fexamples\u002Fsidebase-nuxt-auth","Auth.js with @sidebase\u002Fnuxt-auth","Check the Auth.js session, and accept the same JWT as a Bearer token.",[95,96,97],"@sidebase\u002Fnuxt-auth","getServerSession","getToken",{"path":99,"title":100,"description":101,"category":87,"order":73,"uses":102},"\u002Fexamples\u002Fsupabase","Supabase","Verify the Supabase session with getClaims, and tell bad tokens from outages.",[103,104,105],"@nuxtjs\u002Fsupabase","getClaims","isAuthRetryableFetchError",{"path":107,"title":108,"description":109,"category":87,"order":81,"uses":110},"\u002Fexamples\u002Fclerk","Clerk","Read the auth object that Clerk's middleware put on the event.",[111,112],"@clerk\u002Fnuxt","event.context.auth",{"path":114,"title":115,"description":116,"category":87,"order":117,"uses":118},"\u002Fexamples\u002Ffirebase","Firebase Authentication","Session Cookies for the browser, ID tokens for apps, and error codes mapped to 401 or 503.",5,[119,120,121],"firebase-admin","verifySessionCookie","verifyIdToken",{"path":123,"title":124,"description":125,"category":87,"order":126,"uses":127},"\u002Fexamples\u002Fjwt-jose","Any OpenID Connect provider (JWT)","Verify access tokens from Auth0, Keycloak, Cognito, Entra ID and others with jose.",6,[128,129,130],"jose","jwtVerify","createRemoteJWKSet",{"path":132,"title":133,"description":134,"category":135,"order":56,"uses":136},"\u002Fexamples\u002Fnuxt-security-rate-limit","Rate limits with nuxt-security","Slow down credential stuffing and token guessing before verifyUser runs.","security",[60,67,137],"routeRules",{"path":139,"title":140,"description":141,"category":135,"order":65,"uses":142},"\u002Fexamples\u002Fnuxt-security-headers","Headers, CSP and request limits with nuxt-security","A baseline nuxt-security setup next to the guard, tuned for a BFF.",[60,143,144,145],"headers","requestSizeLimiter","allowedMethodsRestricter",{"path":147,"title":148,"description":149,"category":135,"order":73,"uses":150},"\u002Fexamples\u002Fnuxt-csurf","CSRF tokens with nuxt-csurf","Add a synchronizer token on top of the origin check, without breaking Bearer clients.",[151,152,137],"nuxt-csurf","useCsrfFetch",{"path":154,"title":155,"description":156,"category":135,"order":81,"uses":157},"\u002Fexamples\u002Fturnstile","Bot checks on public routes with Turnstile","Public sign-in and sign-up routes skip verifyUser, so give them their own check.",[59,158],"verifyTurnstileToken",{"path":160,"title":161,"description":162,"category":135,"order":117,"uses":163},"\u002Fexamples\u002Fcors-bearer-clients","A frontend on another origin","CORS with nuxt-security for a separate app that calls the BFF with Bearer tokens.",[60,164,165],"corsHandler","viaBearer",{"path":167,"title":168,"description":169,"category":170,"order":56,"uses":171},"\u002Fexamples\u002Frecord-authorization","Per-record authorization","The guard says who the user is. The handler decides what they may touch.","patterns",[172,173],"event.context","createError",{"path":175,"title":176,"description":177,"category":170,"order":65,"uses":178},"\u002Fexamples\u002Froles","Roles and app-wide access","Reject whole groups of users in verifyUser, and check roles per route.",[14,179],"403",{"path":181,"title":182,"description":183,"category":170,"order":73,"uses":184},"\u002Fexamples\u002Fupstream-proxy","Calling an upstream API","Attach the user's token after the guard, never in middleware or routeRules.proxy.",[185,186,187],"$fetch","routeRules.proxy","server\u002Futils",{"path":189,"title":190,"description":191,"category":170,"order":81,"uses":192},"\u002Fexamples\u002Fssr-and-server-functions","SSR and server functions","Call your own API during server rendering, or skip HTTP entirely.",[76,193,187],"useRequestFetch",{"path":195,"title":196,"description":197,"category":170,"order":117,"uses":198},"\u002Fexamples\u002Fwebhooks","Webhooks","Server-to-server callbacks belong outside server\u002Fapi, with their own signature check.",[199,200,201],"server\u002Froutes","readRawBody","xssValidator",{"path":203,"title":204,"description":205,"category":170,"order":126,"uses":206},"\u002Fexamples\u002Fbearer-clients","Mobile apps and CLI tools","One BFF for the browser and for clients that send Bearer tokens.",[165,207],"Authorization",{"path":209,"title":210,"description":211,"category":170,"order":212,"uses":213},"\u002Fexamples\u002Fmore-route-folders","Checking more folders at build time","Extend routePatterns to server\u002Froutes and layers.",7,[214],"routePatterns",{"path":216,"title":217,"description":218,"category":170,"order":219,"uses":220},"\u002Fexamples\u002Fpublic-cache","Caching public data","Cache what is the same for everyone on a separate public route.",8,[68,75],{"path":222,"title":223,"description":224,"category":170,"order":225,"uses":226},"\u002Fexamples\u002Fclient-errors","Handling 401, 403 and 503 in the app","Sign out on 401, explain 403, retry on 503.",9,[227,228],"$fetch.create","onResponseError",{"path":230,"title":231,"description":232,"category":170,"order":233,"uses":234},"\u002Fexamples\u002Ftesting","Testing the protection","An end-to-end test that every protected route refuses anonymous calls.",10,[235,236],"@nuxt\u002Ftest-utils","vitest",{"id":238,"title":34,"body":239,"description":418,"extension":419,"meta":420,"navigation":421,"path":35,"seo":422,"stem":36,"__hash__":423},"docs_en\u002Fdocs\u002F07.scope.md",{"type":240,"value":241,"toc":410},"minimark",[242,251,256,259,270,281,284,297,301,308,330,334,349,381,387,391,403,407],[243,244,245,246,250],"p",{},"The guard protects one thing: a route handler wrapped in ",[247,248,249],"code",{},"defineBffHandler"," does not run for an unverified user. Anything that answers before that handler is outside its reach.",[252,253,255],"h2",{"id":254},"what-the-guard-does-not-prevent","What the guard does not prevent",[243,257,258],{},"The guard stops two things: people who are not signed in calling your BFF, and other websites using a signed-in user's browser to call it.",[243,260,261,262,265,266,269],{},"It does not stop a signed-in user from calling the BFF directly, for example with curl and their own Cookie or token. Outside a browser, ",[247,263,264],{},"Origin"," and ",[247,267,268],{},"Sec-Fetch-Site"," can be set to anything, and Bearer clients are allowed on purpose. No server-side check can tell your own frontend from a client the user controls with the same credentials.",[243,271,272,273,277,278,280],{},"On a ",[274,275,276],"a",{"href":19},"site without users",", the same holds for scripts that copy the ",[247,279,268],{}," header your pages send.",[243,282,283],{},"If you need to make that harder:",[285,286,287,294],"ul",{},[288,289,290,291,293],"li",{},"Verify an app attestation or bot-check token in ",[247,292,14],{}," and throw 403 without it, for example Firebase App Check, reCAPTCHA Enterprise or Cloudflare Turnstile. This raises the cost of scripting; it is not a guarantee.",[288,295,296],{},"Limit the damage: rate limits, and per-record authorization so that a user can do nothing through the API that the screens would not let them do.",[252,298,300],{"id":299},"runs-before-the-guard","Runs before the guard",[243,302,303,304,307],{},"Nitro runs every middleware before any route handler: first your own ",[247,305,306],{},"server\u002Fmiddleware",", then middleware that modules add, such as nuxt-security, nuxt-csurf or Clerk. Then the router picks the handler.",[285,309,310,317,324],{},[288,311,312,316],{},[313,314,315],"strong",{},"Your middleware"," runs for every request, before the guard. Do not attach tokens or forward requests upstream there; do it in the handler after the guard.",[288,318,319,323],{},[313,320,321],{},[247,322,186],{}," forwards the request without running your handler. Protect such a path at its own entry point, or replace the proxy with a handler that calls upstream.",[288,325,326,329],{},[313,327,328],{},"Security middleware"," such as rate limiters and size limits answer first too, which is what you want.",[252,331,333],{"id":332},"caches","Caches",[243,335,336,337,340,341,344,345,348],{},"Do not combine protected routes with Nitro's ",[247,338,339],{},"cache"," or ",[247,342,343],{},"swr"," route rules, ",[247,346,347],{},"defineCachedEventHandler",", or a CDN cache.",[285,350,351,364,378],{},[288,352,353,354,357,358,360,361,363],{},"Inside Nitro's cache wrapper, the handler sees only the request headers listed in ",[247,355,356],{},"varies",". Without them, ",[247,359,14],{}," gets no Cookie or ",[247,362,207],{}," and every request answers 401.",[288,365,366,367,340,370,373,374,377],{},"Nitro 2.14 refuses to store responses marked ",[247,368,369],{},"private",[247,371,372],{},"no-store",", and the guard sets ",[247,375,376],{},"Cache-Control: private, no-store",". If your handler overwrites that header with a cacheable value, later requests get the stored body and the guard does not run.",[288,379,380],{},"A CDN in front of the app can serve a stored response before the request reaches Nitro at all.",[243,382,383,384,386],{},"Public data that is the same for everyone can use a separate public route with its own cache. See ",[274,385,217],{"href":216},".",[252,388,390],{"id":389},"server-side-calls","Server-side calls",[243,392,393,394,396,397,400,401,386],{},"SSR and server-side ",[247,395,185],{}," calls to your own API go through the same guard. Forward the user's Cookie with ",[247,398,399],{},"useRequestFetch()",", or better, call a server function directly instead of an HTTP route. See ",[274,402,190],{"href":189},[252,404,406],{"id":405},"logging","Logging",[243,408,409],{},"The guard logs every denial with path, method and status, never query strings or header values. Keep credentials out of URL paths. In development it also warns about protected requests that carry neither a Cookie nor a Bearer token.",{"title":411,"searchDepth":65,"depth":65,"links":412},"",[413,414,415,416,417],{"id":254,"depth":65,"text":255},{"id":299,"depth":65,"text":300},{"id":332,"depth":65,"text":333},{"id":389,"depth":65,"text":390},{"id":405,"depth":65,"text":406},"What the guard covers, and the setups that would bypass it.","md",{},true,{"title":34,"description":418},"M0mGDN_ylDNW-CK-a7lECCXymIqTCDDFIxY_wksip-Q",[425,427],{"title":30,"path":31,"stem":32,"description":426,"children":-1},"How the guard blocks cross-site request forgery for Cookie-based writes.",{"title":38,"path":39,"stem":40,"description":428,"children":-1},"All options of the bffGuard key.",1796451485279,"a99f93bd-e267-45a7-90df-9194cd77468d"]