@willbooster/shared-lib-next 1.0.0 → 1.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/middleware.cjs +1 -1
- package/dist/middleware.cjs.map +1 -1
- package/dist/middleware.js +1 -1
- package/dist/middleware.js.map +1 -1
- package/package.json +1 -1
package/dist/middleware.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";var e=require("
|
|
1
|
+
"use strict";var e=require("next/server.js");exports.BasicAuthMiddleware=function(r){var n,t,s;const l=null!=(n=r.username)?n:process.env.BASIC_AUTH_USERNAME,u=null!=(t=r.password)?t:process.env.BASIC_AUTH_PASSWORD,o=null!=(s=r.realm)?s:process.env.BASIC_AUTH_REALM;return l||u?r=>{var n;const t=null!=(n=r.headers.get("authorization"))?n:"",[s,a]=t.split(" "),i=Buffer.from(`${l}:${u}`),c=Buffer.from(null!=a?a:"","base64");return"basic"===(null==s?void 0:s.toLowerCase())&&0!==c.length&&i.length===c.length&&function(e,r){if(e.length!==r.length)return!1;let n=0;for(const[s,l]of e.entries()){var t;n|=l^(null!=(t=r[s])?t:0)}return 0===n}(c,i)?e.NextResponse.next():new e.NextResponse("Unauthorized",{headers:{"WWW-Authenticate":`Basic realm="${o||"Secure Area"}"`},status:401})}:()=>e.NextResponse.next()};
|
|
2
2
|
//# sourceMappingURL=middleware.cjs.map
|
package/dist/middleware.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.cjs","sources":["../src/middleware.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"middleware.cjs","sources":["../src/middleware.ts"],"sourcesContent":["import { NextResponse } from 'next/server.js';\nimport type { NextRequest } from 'next/server.js';\n\ntype BasicAuthMiddlewareOptions = {\n username?: string;\n password?: string;\n realm?: string;\n};\n\n/**\n * Timing-safe comparison of two buffers to prevent timing attacks.\n * This implementation works in all JavaScript environments (Node.js, Edge, Browser).\n */\nfunction timingSafeEqual(a: Buffer, b: Buffer): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let result = 0;\n for (const [i, element] of a.entries()) {\n result |= element ^ (b[i] ?? 0);\n }\n return result === 0;\n}\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): (request: NextRequest) => NextResponse {\n const username = options.username ?? process.env.BASIC_AUTH_USERNAME;\n const password = options.password ?? process.env.BASIC_AUTH_PASSWORD;\n const realm = options.realm ?? process.env.BASIC_AUTH_REALM;\n\n if (!username && !password) return () => NextResponse.next();\n\n return (request) => {\n const authorizationHeader = request.headers.get('authorization') ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${username}:${password}`);\n const provided = Buffer.from(encodedCredentials ?? '', 'base64');\n\n if (\n type?.toLowerCase() !== 'basic' ||\n provided.length === 0 ||\n expected.length !== provided.length ||\n !timingSafeEqual(provided, expected)\n ) {\n return new NextResponse('Unauthorized', {\n headers: { 'WWW-Authenticate': `Basic realm=\"${realm || 'Secure Area'}\"` },\n status: 401,\n });\n }\n\n return NextResponse.next();\n };\n}\n"],"names":["options","_options$username","_options$password","_options$realm","username","process","env","BASIC_AUTH_USERNAME","password","BASIC_AUTH_PASSWORD","realm","BASIC_AUTH_REALM","request","_request$headers$get","authorizationHeader","headers","get","type","encodedCredentials","split","expected","Buffer","from","provided","toLowerCase","length","a","b","result","i","element","entries","_b$i","timingSafeEqual","NextResponse","next","status"],"mappings":"yEAyBO,SAA6BA,GAA6E,IAAAC,EAAAC,EAAAC,EAC/G,MAAMC,EAA2B,OAAnBH,EAAGD,EAAQI,UAAQH,EAAII,QAAQC,IAAIC,oBAC3CC,EAA2B,OAAnBN,EAAGF,EAAQQ,UAAQN,EAAIG,QAAQC,IAAIG,oBAC3CC,EAAqB,OAAhBP,EAAGH,EAAQU,OAAKP,EAAIE,QAAQC,IAAIK,iBAE3C,OAAKP,GAAaI,EAEVI,IAAY,IAAAC,EAClB,MAAMC,EAA0D,OAAvCD,EAAGD,EAAQG,QAAQC,IAAI,kBAAgBH,EAAI,IAC7DI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGlB,KAAYI,KACtCe,EAAWF,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,MAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMO,gBACc,IAApBD,EAASE,QACTL,EAASK,SAAWF,EAASE,QA5BnC,SAAyBC,EAAWC,GAClC,GAAID,EAAED,SAAWE,EAAEF,OACjB,OAAO,EAGT,IAAIG,EAAS,EACb,IAAK,MAAOC,EAAGC,KAAYJ,EAAEK,UAAW,CAAA,IAAAC,EACtCJ,GAAUE,GAAe,OAARE,EAAIL,EAAEE,IAAEG,EAAI,EAC/B,CACA,OAAkB,IAAXJ,CACT,CAmBOK,CAAgBV,EAAUH,GAQtBc,EAAAA,aAAaC,OANX,IAAID,EAAAA,aAAa,eAAgB,CACtCnB,QAAS,CAAE,mBAAoB,gBAAgBL,GAAS,kBACxD0B,OAAQ,OAhBqB,IAAMF,EAAAA,aAAaC,MAsBxD"}
|
package/dist/middleware.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import
|
|
1
|
+
import{NextResponse as e}from"next/server.js";function r(r){var n,t,s;const l=null!=(n=r.username)?n:process.env.BASIC_AUTH_USERNAME,o=null!=(t=r.password)?t:process.env.BASIC_AUTH_PASSWORD,u=null!=(s=r.realm)?s:process.env.BASIC_AUTH_REALM;return l||o?r=>{var n;const t=null!=(n=r.headers.get("authorization"))?n:"",[s,a]=t.split(" "),i=Buffer.from(`${l}:${o}`),c=Buffer.from(null!=a?a:"","base64");return"basic"===(null==s?void 0:s.toLowerCase())&&0!==c.length&&i.length===c.length&&function(e,r){if(e.length!==r.length)return!1;let n=0;for(const[s,l]of e.entries()){var t;n|=l^(null!=(t=r[s])?t:0)}return 0===n}(c,i)?e.next():new e("Unauthorized",{headers:{"WWW-Authenticate":`Basic realm="${u||"Secure Area"}"`},status:401})}:()=>e.next()}export{r as BasicAuthMiddleware};
|
|
2
2
|
//# sourceMappingURL=middleware.js.map
|
package/dist/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","sources":["../src/middleware.ts"],"sourcesContent":["import
|
|
1
|
+
{"version":3,"file":"middleware.js","sources":["../src/middleware.ts"],"sourcesContent":["import { NextResponse } from 'next/server.js';\nimport type { NextRequest } from 'next/server.js';\n\ntype BasicAuthMiddlewareOptions = {\n username?: string;\n password?: string;\n realm?: string;\n};\n\n/**\n * Timing-safe comparison of two buffers to prevent timing attacks.\n * This implementation works in all JavaScript environments (Node.js, Edge, Browser).\n */\nfunction timingSafeEqual(a: Buffer, b: Buffer): boolean {\n if (a.length !== b.length) {\n return false;\n }\n\n let result = 0;\n for (const [i, element] of a.entries()) {\n result |= element ^ (b[i] ?? 0);\n }\n return result === 0;\n}\n\nexport function BasicAuthMiddleware(options: BasicAuthMiddlewareOptions): (request: NextRequest) => NextResponse {\n const username = options.username ?? process.env.BASIC_AUTH_USERNAME;\n const password = options.password ?? process.env.BASIC_AUTH_PASSWORD;\n const realm = options.realm ?? process.env.BASIC_AUTH_REALM;\n\n if (!username && !password) return () => NextResponse.next();\n\n return (request) => {\n const authorizationHeader = request.headers.get('authorization') ?? '';\n const [type, encodedCredentials] = authorizationHeader.split(' ');\n const expected = Buffer.from(`${username}:${password}`);\n const provided = Buffer.from(encodedCredentials ?? '', 'base64');\n\n if (\n type?.toLowerCase() !== 'basic' ||\n provided.length === 0 ||\n expected.length !== provided.length ||\n !timingSafeEqual(provided, expected)\n ) {\n return new NextResponse('Unauthorized', {\n headers: { 'WWW-Authenticate': `Basic realm=\"${realm || 'Secure Area'}\"` },\n status: 401,\n });\n }\n\n return NextResponse.next();\n };\n}\n"],"names":["BasicAuthMiddleware","options","_options$username","_options$password","_options$realm","username","process","env","BASIC_AUTH_USERNAME","password","BASIC_AUTH_PASSWORD","realm","BASIC_AUTH_REALM","request","_request$headers$get","authorizationHeader","headers","get","type","encodedCredentials","split","expected","Buffer","from","provided","toLowerCase","length","a","b","result","i","element","entries","_b$i","timingSafeEqual","NextResponse","next","status"],"mappings":"8CAyBO,SAASA,EAAoBC,GAA6E,IAAAC,EAAAC,EAAAC,EAC/G,MAAMC,EAA2B,OAAnBH,EAAGD,EAAQI,UAAQH,EAAII,QAAQC,IAAIC,oBAC3CC,EAA2B,OAAnBN,EAAGF,EAAQQ,UAAQN,EAAIG,QAAQC,IAAIG,oBAC3CC,EAAqB,OAAhBP,EAAGH,EAAQU,OAAKP,EAAIE,QAAQC,IAAIK,iBAE3C,OAAKP,GAAaI,EAEVI,IAAY,IAAAC,EAClB,MAAMC,EAA0D,OAAvCD,EAAGD,EAAQG,QAAQC,IAAI,kBAAgBH,EAAI,IAC7DI,EAAMC,GAAsBJ,EAAoBK,MAAM,KACvDC,EAAWC,OAAOC,KAAK,GAAGlB,KAAYI,KACtCe,EAAWF,OAAOC,KAAuB,MAAlBJ,EAAAA,EAAsB,GAAI,UAEvD,MAC0B,WAApB,MAAJD,OAAI,EAAJA,EAAMO,gBACc,IAApBD,EAASE,QACTL,EAASK,SAAWF,EAASE,QA5BnC,SAAyBC,EAAWC,GAClC,GAAID,EAAED,SAAWE,EAAEF,OACjB,OAAO,EAGT,IAAIG,EAAS,EACb,IAAK,MAAOC,EAAGC,KAAYJ,EAAEK,UAAW,CAAA,IAAAC,EACtCJ,GAAUE,GAAe,OAARE,EAAIL,EAAEE,IAAEG,EAAI,EAC/B,CACA,OAAkB,IAAXJ,CACT,CAmBOK,CAAgBV,EAAUH,GAQtBc,EAAaC,OANX,IAAID,EAAa,eAAgB,CACtCnB,QAAS,CAAE,mBAAoB,gBAAgBL,GAAS,kBACxD0B,OAAQ,OAhBqB,IAAMF,EAAaC,MAsBxD"}
|