[{"data":1,"prerenderedAt":798,"buildId":799},["ShallowReactive",2],{"docs-navigation-en":3,"example-\u002Fexamples\u002Fnuxt-security-headers":50,"example-surround-\u002Fexamples\u002Fnuxt-security-headers":628,"examples-en":637},[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,{"id":51,"title":52,"body":53,"category":617,"description":618,"extension":619,"meta":620,"navigation":621,"order":97,"path":622,"seo":623,"stem":624,"uses":625,"__hash__":627},"examples_en\u002Fexamples\u002Fnuxt-security-headers.md","Headers, CSP and request limits with nuxt-security",{"type":54,"value":55,"toc":614},"minimark",[56,60,524,529,604,610],[57,58,59],"p",{},"The guard does not set security headers or a Content Security Policy. nuxt-security does, with strict defaults. This setup keeps those defaults for pages and adjusts the API.",[61,62,68],"pre",{"className":63,"code":64,"filename":65,"language":66,"meta":67,"style":67},"language-ts shiki shiki-themes material-theme-lighter github-light github-dark","export default defineNuxtConfig({\n  modules: ['nuxt-security', '@kurashina-design\u002Fnuxt-bff-guard'],\n  bffGuard: {\n    verifyUser: '.\u002Fserver\u002Fauth\u002Fverify-user.ts',\n  },\n  security: {\n    \u002F\u002F Pages: strict CSP with a nonce, HSTS and the rest of the defaults.\n    nonce: true,\n    headers: {\n      contentSecurityPolicy: {\n        'script-src': [\"'self'\", \"'nonce-{{nonce}}'\", \"'strict-dynamic'\"],\n        'connect-src': [\"'self'\"], \u002F\u002F the browser talks only to your BFF\n      },\n    },\n    requestSizeLimiter: {\n      maxRequestSizeInBytes: 200_000,\n      maxUploadFileRequestInBytes: 8_000_000,\n    },\n  },\n  routeRules: {\n    \u002F\u002F Allow only the methods the API uses.\n    '\u002Fapi\u002F**': {\n      security: { allowedMethodsRestricter: { methods: ['GET', 'POST', 'PATCH', 'DELETE'] } },\n    },\n    \u002F\u002F A larger limit for the one upload route.\n    '\u002Fapi\u002Ffiles': {\n      security: { requestSizeLimiter: { maxUploadFileRequestInBytes: 50_000_000 } },\n    },\n  },\n})\n","nuxt.config.ts","ts","",[69,70,71,95,135,146,163,169,179,186,200,210,220,267,294,300,306,316,330,343,348,353,363,369,384,452,457,463,477,506,511,516],"code",{"__ignoreMap":67},[72,73,76,80,83,87,91],"span",{"class":74,"line":75},"line",1,[72,77,79],{"class":78},"sVHd0","export",[72,81,82],{"class":78}," default",[72,84,86],{"class":85},"sGLFI"," defineNuxtConfig",[72,88,90],{"class":89},"su5hD","(",[72,92,94],{"class":93},"sP7_E","{\n",[72,96,98,102,105,108,112,116,118,121,124,127,129,132],{"class":74,"line":97},2,[72,99,101],{"class":100},"skxfh","  modules",[72,103,104],{"class":93},":",[72,106,107],{"class":89}," [",[72,109,111],{"class":110},"sjJ54","'",[72,113,115],{"class":114},"s_sjI","nuxt-security",[72,117,111],{"class":110},[72,119,120],{"class":93},",",[72,122,123],{"class":110}," '",[72,125,126],{"class":114},"@kurashina-design\u002Fnuxt-bff-guard",[72,128,111],{"class":110},[72,130,131],{"class":89},"]",[72,133,134],{"class":93},",\n",[72,136,138,141,143],{"class":74,"line":137},3,[72,139,140],{"class":100},"  bffGuard",[72,142,104],{"class":93},[72,144,145],{"class":93}," {\n",[72,147,149,152,154,156,159,161],{"class":74,"line":148},4,[72,150,151],{"class":100},"    verifyUser",[72,153,104],{"class":93},[72,155,123],{"class":110},[72,157,158],{"class":114},".\u002Fserver\u002Fauth\u002Fverify-user.ts",[72,160,111],{"class":110},[72,162,134],{"class":93},[72,164,166],{"class":74,"line":165},5,[72,167,168],{"class":93},"  },\n",[72,170,172,175,177],{"class":74,"line":171},6,[72,173,174],{"class":100},"  security",[72,176,104],{"class":93},[72,178,145],{"class":93},[72,180,182],{"class":74,"line":181},7,[72,183,185],{"class":184},"sutJx","    \u002F\u002F Pages: strict CSP with a nonce, HSTS and the rest of the defaults.\n",[72,187,189,192,194,198],{"class":74,"line":188},8,[72,190,191],{"class":100},"    nonce",[72,193,104],{"class":93},[72,195,197],{"class":196},"syTEX"," true",[72,199,134],{"class":93},[72,201,203,206,208],{"class":74,"line":202},9,[72,204,205],{"class":100},"    headers",[72,207,104],{"class":93},[72,209,145],{"class":93},[72,211,213,216,218],{"class":74,"line":212},10,[72,214,215],{"class":100},"      contentSecurityPolicy",[72,217,104],{"class":93},[72,219,145],{"class":93},[72,221,223,226,230,232,234,236,239,242,244,246,249,252,254,256,258,261,263,265],{"class":74,"line":222},11,[72,224,225],{"class":110},"        '",[72,227,229],{"class":228},"sZUrc","script-src",[72,231,111],{"class":110},[72,233,104],{"class":93},[72,235,107],{"class":89},[72,237,238],{"class":110},"\"",[72,240,241],{"class":114},"'self'",[72,243,238],{"class":110},[72,245,120],{"class":93},[72,247,248],{"class":110}," \"",[72,250,251],{"class":114},"'nonce-{{nonce}}'",[72,253,238],{"class":110},[72,255,120],{"class":93},[72,257,248],{"class":110},[72,259,260],{"class":114},"'strict-dynamic'",[72,262,238],{"class":110},[72,264,131],{"class":89},[72,266,134],{"class":93},[72,268,270,272,275,277,279,281,283,285,287,289,291],{"class":74,"line":269},12,[72,271,225],{"class":110},[72,273,274],{"class":228},"connect-src",[72,276,111],{"class":110},[72,278,104],{"class":93},[72,280,107],{"class":89},[72,282,238],{"class":110},[72,284,241],{"class":114},[72,286,238],{"class":110},[72,288,131],{"class":89},[72,290,120],{"class":93},[72,292,293],{"class":184}," \u002F\u002F the browser talks only to your BFF\n",[72,295,297],{"class":74,"line":296},13,[72,298,299],{"class":93},"      },\n",[72,301,303],{"class":74,"line":302},14,[72,304,305],{"class":93},"    },\n",[72,307,309,312,314],{"class":74,"line":308},15,[72,310,311],{"class":100},"    requestSizeLimiter",[72,313,104],{"class":93},[72,315,145],{"class":93},[72,317,319,322,324,328],{"class":74,"line":318},16,[72,320,321],{"class":100},"      maxRequestSizeInBytes",[72,323,104],{"class":93},[72,325,327],{"class":326},"srdBf"," 200_000",[72,329,134],{"class":93},[72,331,333,336,338,341],{"class":74,"line":332},17,[72,334,335],{"class":100},"      maxUploadFileRequestInBytes",[72,337,104],{"class":93},[72,339,340],{"class":326}," 8_000_000",[72,342,134],{"class":93},[72,344,346],{"class":74,"line":345},18,[72,347,305],{"class":93},[72,349,351],{"class":74,"line":350},19,[72,352,168],{"class":93},[72,354,356,359,361],{"class":74,"line":355},20,[72,357,358],{"class":100},"  routeRules",[72,360,104],{"class":93},[72,362,145],{"class":93},[72,364,366],{"class":74,"line":365},21,[72,367,368],{"class":184},"    \u002F\u002F Allow only the methods the API uses.\n",[72,370,372,375,378,380,382],{"class":74,"line":371},22,[72,373,374],{"class":110},"    '",[72,376,377],{"class":228},"\u002Fapi\u002F**",[72,379,111],{"class":110},[72,381,104],{"class":93},[72,383,145],{"class":93},[72,385,387,390,392,395,398,400,402,405,407,409,411,414,416,418,420,423,425,427,429,432,434,436,438,441,443,446,449],{"class":74,"line":386},23,[72,388,389],{"class":100},"      security",[72,391,104],{"class":93},[72,393,394],{"class":93}," {",[72,396,397],{"class":100}," allowedMethodsRestricter",[72,399,104],{"class":93},[72,401,394],{"class":93},[72,403,404],{"class":100}," methods",[72,406,104],{"class":93},[72,408,107],{"class":89},[72,410,111],{"class":110},[72,412,413],{"class":114},"GET",[72,415,111],{"class":110},[72,417,120],{"class":93},[72,419,123],{"class":110},[72,421,422],{"class":114},"POST",[72,424,111],{"class":110},[72,426,120],{"class":93},[72,428,123],{"class":110},[72,430,431],{"class":114},"PATCH",[72,433,111],{"class":110},[72,435,120],{"class":93},[72,437,123],{"class":110},[72,439,440],{"class":114},"DELETE",[72,442,111],{"class":110},[72,444,445],{"class":89},"] ",[72,447,448],{"class":93},"}",[72,450,451],{"class":93}," },\n",[72,453,455],{"class":74,"line":454},24,[72,456,305],{"class":93},[72,458,460],{"class":74,"line":459},25,[72,461,462],{"class":184},"    \u002F\u002F A larger limit for the one upload route.\n",[72,464,466,468,471,473,475],{"class":74,"line":465},26,[72,467,374],{"class":110},[72,469,470],{"class":228},"\u002Fapi\u002Ffiles",[72,472,111],{"class":110},[72,474,104],{"class":93},[72,476,145],{"class":93},[72,478,480,482,484,486,489,491,493,496,498,501,504],{"class":74,"line":479},27,[72,481,389],{"class":100},[72,483,104],{"class":93},[72,485,394],{"class":93},[72,487,488],{"class":100}," requestSizeLimiter",[72,490,104],{"class":93},[72,492,394],{"class":93},[72,494,495],{"class":100}," maxUploadFileRequestInBytes",[72,497,104],{"class":93},[72,499,500],{"class":326}," 50_000_000",[72,502,503],{"class":93}," }",[72,505,451],{"class":93},[72,507,509],{"class":74,"line":508},28,[72,510,305],{"class":93},[72,512,514],{"class":74,"line":513},29,[72,515,168],{"class":93},[72,517,519,521],{"class":74,"line":518},30,[72,520,448],{"class":93},[72,522,523],{"class":89},")\n",[525,526,528],"h2",{"id":527},"what-each-layer-answers","What each layer answers",[530,531,532,548],"table",{},[533,534,535],"thead",{},[536,537,538,542,545],"tr",{},[539,540,541],"th",{},"Status",[539,543,544],{},"Comes from",[539,546,547],{},"Before the guard?",[549,550,551,563,573,583,593],"tbody",{},[536,552,553,557,560],{},[554,555,556],"td",{},"413",[554,558,559],{},"requestSizeLimiter",[554,561,562],{},"yes",[536,564,565,568,571],{},[554,566,567],{},"405",[554,569,570],{},"allowedMethodsRestricter",[554,572,562],{},[536,574,575,578,581],{},[554,576,577],{},"429",[554,579,580],{},"rateLimiter",[554,582,562],{},[536,584,585,588,591],{},[554,586,587],{},"400",[554,589,590],{},"xssValidator",[554,592,562],{},[536,594,595,598,601],{},[554,596,597],{},"401 \u002F 403 \u002F 503",[554,599,600],{},"Nuxt BFF Guard",[554,602,603],{},"–",[57,605,606,609],{},[69,607,608],{},"connect-src 'self'"," fits the BFF idea: the browser only calls your own server, and upstream APIs are called from handlers.",[611,612,613],"style",{},"html pre.shiki code .sVHd0, html code.shiki .sVHd0{--shiki-light:#39ADB5;--shiki-light-font-style:italic;--shiki-default:#D73A49;--shiki-default-font-style:inherit;--shiki-dark:#F97583;--shiki-dark-font-style:inherit}html pre.shiki code .sGLFI, html code.shiki .sGLFI{--shiki-light:#6182B8;--shiki-default:#6F42C1;--shiki-dark:#B392F0}html pre.shiki code .su5hD, html code.shiki .su5hD{--shiki-light:#90A4AE;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sP7_E, html code.shiki .sP7_E{--shiki-light:#39ADB5;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .skxfh, html code.shiki .skxfh{--shiki-light:#E53935;--shiki-default:#24292E;--shiki-dark:#E1E4E8}html pre.shiki code .sjJ54, html code.shiki .sjJ54{--shiki-light:#39ADB5;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .s_sjI, html code.shiki .s_sjI{--shiki-light:#91B859;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .sutJx, html code.shiki .sutJx{--shiki-light:#90A4AE;--shiki-light-font-style:italic;--shiki-default:#6A737D;--shiki-default-font-style:inherit;--shiki-dark:#6A737D;--shiki-dark-font-style:inherit}html pre.shiki code .syTEX, html code.shiki .syTEX{--shiki-light:#FF5370;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html pre.shiki code .sZUrc, html code.shiki .sZUrc{--shiki-light:#E53935;--shiki-default:#032F62;--shiki-dark:#9ECBFF}html pre.shiki code .srdBf, html code.shiki .srdBf{--shiki-light:#F76D47;--shiki-default:#005CC5;--shiki-dark:#79B8FF}html .light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html.light .shiki span {color: var(--shiki-light);background: var(--shiki-light-bg);font-style: var(--shiki-light-font-style);font-weight: var(--shiki-light-font-weight);text-decoration: var(--shiki-light-text-decoration);}html .default .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .shiki span {color: var(--shiki-default);background: var(--shiki-default-bg);font-style: var(--shiki-default-font-style);font-weight: var(--shiki-default-font-weight);text-decoration: var(--shiki-default-text-decoration);}html .dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}html.dark .shiki span {color: var(--shiki-dark);background: var(--shiki-dark-bg);font-style: var(--shiki-dark-font-style);font-weight: var(--shiki-dark-font-weight);text-decoration: var(--shiki-dark-text-decoration);}",{"title":67,"searchDepth":97,"depth":97,"links":615},[616],{"id":527,"depth":97,"text":528},"security","A baseline nuxt-security setup next to the guard, tuned for a BFF.","md",{},true,"\u002Fexamples\u002Fnuxt-security-headers",{"title":52,"description":618},"examples\u002Fnuxt-security-headers",[115,626,559,570],"headers","qJyidpgUNFVlCIYza7FZ84_8HT06a8JH8ChPDjnhW4M",[629,633],{"path":630,"title":631,"description":632,"category":617,"order":75},"\u002Fexamples\u002Fnuxt-security-rate-limit","Rate limits with nuxt-security","Slow down credential stuffing and token guessing before verifyUser runs.",{"path":634,"title":635,"description":636,"category":617,"order":137},"\u002Fexamples\u002Fnuxt-csurf","CSRF tokens with nuxt-csurf","Add a synchronizer token on top of the origin check, without breaking Bearer clients.",[638,646,652,659,664,671,679,687,694,702,710,713,715,719,725,732,740,746,754,760,767,773,779,784,791],{"path":639,"title":640,"description":641,"category":642,"order":75,"uses":643},"\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",[644,645,115],"access: 'visitor'","@nuxtjs\u002Fturnstile",{"path":647,"title":648,"description":649,"category":642,"order":97,"uses":650},"\u002Fexamples\u002Fpaid-api-proxy","Search box that calls a paid API","Keep other sites and scripts from spending your API quota through your BFF.",[644,580,651],"defineCachedFunction",{"path":653,"title":654,"description":655,"category":642,"order":137,"uses":656},"\u002Fexamples\u002Fclient-data","JSON for client-side pages","Data that your pages fetch in the browser, kept from being embedded by other sites.",[644,657,658],"access: 'public'","useFetch",{"path":660,"title":661,"description":662,"category":642,"order":148,"uses":663},"\u002Fexamples\u002Fmember-site-contact","Visitor routes inside a member app","Keep 'user' as the default and open a few routes to visitors without accounts.",[644,14],{"path":665,"title":666,"description":667,"category":668,"order":75,"uses":669},"\u002Fexamples\u002Fnuxt-auth-utils","nuxt-auth-utils","Use the sealed Cookie session of nuxt-auth-utils as the user check.","auth",[666,670],"requireUserSession",{"path":672,"title":673,"description":674,"category":668,"order":97,"uses":675},"\u002Fexamples\u002Fsidebase-nuxt-auth","Auth.js with @sidebase\u002Fnuxt-auth","Check the Auth.js session, and accept the same JWT as a Bearer token.",[676,677,678],"@sidebase\u002Fnuxt-auth","getServerSession","getToken",{"path":680,"title":681,"description":682,"category":668,"order":137,"uses":683},"\u002Fexamples\u002Fsupabase","Supabase","Verify the Supabase session with getClaims, and tell bad tokens from outages.",[684,685,686],"@nuxtjs\u002Fsupabase","getClaims","isAuthRetryableFetchError",{"path":688,"title":689,"description":690,"category":668,"order":148,"uses":691},"\u002Fexamples\u002Fclerk","Clerk","Read the auth object that Clerk's middleware put on the event.",[692,693],"@clerk\u002Fnuxt","event.context.auth",{"path":695,"title":696,"description":697,"category":668,"order":165,"uses":698},"\u002Fexamples\u002Ffirebase","Firebase Authentication","Session Cookies for the browser, ID tokens for apps, and error codes mapped to 401 or 503.",[699,700,701],"firebase-admin","verifySessionCookie","verifyIdToken",{"path":703,"title":704,"description":705,"category":668,"order":171,"uses":706},"\u002Fexamples\u002Fjwt-jose","Any OpenID Connect provider (JWT)","Verify access tokens from Auth0, Keycloak, Cognito, Entra ID and others with jose.",[707,708,709],"jose","jwtVerify","createRemoteJWKSet",{"path":630,"title":631,"description":632,"category":617,"order":75,"uses":711},[115,580,712],"routeRules",{"path":622,"title":52,"description":618,"category":617,"order":97,"uses":714},[115,626,559,570],{"path":634,"title":635,"description":636,"category":617,"order":137,"uses":716},[717,718,712],"nuxt-csurf","useCsrfFetch",{"path":720,"title":721,"description":722,"category":617,"order":148,"uses":723},"\u002Fexamples\u002Fturnstile","Bot checks on public routes with Turnstile","Public sign-in and sign-up routes skip verifyUser, so give them their own check.",[645,724],"verifyTurnstileToken",{"path":726,"title":727,"description":728,"category":617,"order":165,"uses":729},"\u002Fexamples\u002Fcors-bearer-clients","A frontend on another origin","CORS with nuxt-security for a separate app that calls the BFF with Bearer tokens.",[115,730,731],"corsHandler","viaBearer",{"path":733,"title":734,"description":735,"category":736,"order":75,"uses":737},"\u002Fexamples\u002Frecord-authorization","Per-record authorization","The guard says who the user is. The handler decides what they may touch.","patterns",[738,739],"event.context","createError",{"path":741,"title":742,"description":743,"category":736,"order":97,"uses":744},"\u002Fexamples\u002Froles","Roles and app-wide access","Reject whole groups of users in verifyUser, and check roles per route.",[14,745],"403",{"path":747,"title":748,"description":749,"category":736,"order":137,"uses":750},"\u002Fexamples\u002Fupstream-proxy","Calling an upstream API","Attach the user's token after the guard, never in middleware or routeRules.proxy.",[751,752,753],"$fetch","routeRules.proxy","server\u002Futils",{"path":755,"title":756,"description":757,"category":736,"order":148,"uses":758},"\u002Fexamples\u002Fssr-and-server-functions","SSR and server functions","Call your own API during server rendering, or skip HTTP entirely.",[658,759,753],"useRequestFetch",{"path":761,"title":762,"description":763,"category":736,"order":165,"uses":764},"\u002Fexamples\u002Fwebhooks","Webhooks","Server-to-server callbacks belong outside server\u002Fapi, with their own signature check.",[765,766,590],"server\u002Froutes","readRawBody",{"path":768,"title":769,"description":770,"category":736,"order":171,"uses":771},"\u002Fexamples\u002Fbearer-clients","Mobile apps and CLI tools","One BFF for the browser and for clients that send Bearer tokens.",[731,772],"Authorization",{"path":774,"title":775,"description":776,"category":736,"order":181,"uses":777},"\u002Fexamples\u002Fmore-route-folders","Checking more folders at build time","Extend routePatterns to server\u002Froutes and layers.",[778],"routePatterns",{"path":780,"title":781,"description":782,"category":736,"order":188,"uses":783},"\u002Fexamples\u002Fpublic-cache","Caching public data","Cache what is the same for everyone on a separate public route.",[651,657],{"path":785,"title":786,"description":787,"category":736,"order":202,"uses":788},"\u002Fexamples\u002Fclient-errors","Handling 401, 403 and 503 in the app","Sign out on 401, explain 403, retry on 503.",[789,790],"$fetch.create","onResponseError",{"path":792,"title":793,"description":794,"category":736,"order":212,"uses":795},"\u002Fexamples\u002Ftesting","Testing the protection","An end-to-end test that every protected route refuses anonymous calls.",[796,797],"@nuxt\u002Ftest-utils","vitest",1796451483605,"a99f93bd-e267-45a7-90df-9194cd77468d"]