@verdaccio/middleware 8.0.7 → 8.1.0
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/build/_virtual/_rolldown/runtime.js +23 -0
- package/build/index.js +62 -229
- package/build/index.mjs +23 -0
- package/build/middlewares/allow.js +42 -50
- package/build/middlewares/allow.js.map +1 -1
- package/build/middlewares/allow.mjs +44 -0
- package/build/middlewares/allow.mjs.map +1 -0
- package/build/middlewares/antiLoop.js +21 -40
- package/build/middlewares/antiLoop.js.map +1 -1
- package/build/middlewares/antiLoop.mjs +25 -0
- package/build/middlewares/antiLoop.mjs.map +1 -0
- package/build/middlewares/api_urls.js +66 -59
- package/build/middlewares/api_urls.js.map +1 -1
- package/build/middlewares/api_urls.mjs +59 -0
- package/build/middlewares/api_urls.mjs.map +1 -0
- package/build/middlewares/body-parser.js +24 -32
- package/build/middlewares/body-parser.js.map +1 -1
- package/build/middlewares/body-parser.mjs +28 -0
- package/build/middlewares/body-parser.mjs.map +1 -0
- package/build/middlewares/encode-pkg.js +20 -36
- package/build/middlewares/encode-pkg.js.map +1 -1
- package/build/middlewares/encode-pkg.mjs +22 -0
- package/build/middlewares/encode-pkg.mjs.map +1 -0
- package/build/middlewares/error.js +53 -71
- package/build/middlewares/error.js.map +1 -1
- package/build/middlewares/error.mjs +53 -0
- package/build/middlewares/error.mjs.map +1 -0
- package/build/middlewares/final.js +46 -57
- package/build/middlewares/final.js.map +1 -1
- package/build/middlewares/final.mjs +46 -0
- package/build/middlewares/final.mjs.map +1 -0
- package/build/middlewares/json.js +7 -11
- package/build/middlewares/json.js.map +1 -1
- package/build/middlewares/json.mjs +10 -0
- package/build/middlewares/json.mjs.map +1 -0
- package/build/middlewares/log.js +73 -94
- package/build/middlewares/log.js.map +1 -1
- package/build/middlewares/log.mjs +71 -0
- package/build/middlewares/log.mjs.map +1 -0
- package/build/middlewares/make-url-relative.js +26 -41
- package/build/middlewares/make-url-relative.js.map +1 -1
- package/build/middlewares/make-url-relative.mjs +28 -0
- package/build/middlewares/make-url-relative.mjs.map +1 -0
- package/build/middlewares/match.js +8 -13
- package/build/middlewares/match.js.map +1 -1
- package/build/middlewares/match.mjs +11 -0
- package/build/middlewares/match.mjs.map +1 -0
- package/build/middlewares/media.js +14 -19
- package/build/middlewares/media.js.map +1 -1
- package/build/middlewares/media.mjs +17 -0
- package/build/middlewares/media.mjs.map +1 -0
- package/build/middlewares/rate-limit.js +8 -10
- package/build/middlewares/rate-limit.js.map +1 -1
- package/build/middlewares/rate-limit.mjs +9 -0
- package/build/middlewares/rate-limit.mjs.map +1 -0
- package/build/middlewares/request-options.js +18 -27
- package/build/middlewares/request-options.js.map +1 -1
- package/build/middlewares/request-options.mjs +19 -0
- package/build/middlewares/request-options.mjs.map +1 -0
- package/build/middlewares/token-auth.js +90 -105
- package/build/middlewares/token-auth.js.map +1 -1
- package/build/middlewares/token-auth.mjs +100 -0
- package/build/middlewares/token-auth.mjs.map +1 -0
- package/build/middlewares/user-agent.js +10 -12
- package/build/middlewares/user-agent.js.map +1 -1
- package/build/middlewares/user-agent.mjs +13 -0
- package/build/middlewares/user-agent.mjs.map +1 -0
- package/build/middlewares/validation.js +10 -18
- package/build/middlewares/validation.js.map +1 -1
- package/build/middlewares/validation.mjs +14 -0
- package/build/middlewares/validation.mjs.map +1 -0
- package/build/middlewares/web/index.js +4 -35
- package/build/middlewares/web/index.mjs +4 -0
- package/build/middlewares/web/render-web.js +86 -113
- package/build/middlewares/web/render-web.js.map +1 -1
- package/build/middlewares/web/render-web.mjs +85 -0
- package/build/middlewares/web/render-web.mjs.map +1 -0
- package/build/middlewares/web/security.js +29 -41
- package/build/middlewares/web/security.js.map +1 -1
- package/build/middlewares/web/security.mjs +30 -0
- package/build/middlewares/web/security.mjs.map +1 -0
- package/build/middlewares/web/utils/manifest.js +17 -18
- package/build/middlewares/web/utils/manifest.js.map +1 -1
- package/build/middlewares/web/utils/manifest.mjs +21 -0
- package/build/middlewares/web/utils/manifest.mjs.map +1 -0
- package/build/middlewares/web/utils/renderHTML.js +46 -50
- package/build/middlewares/web/utils/renderHTML.js.map +1 -1
- package/build/middlewares/web/utils/renderHTML.mjs +48 -0
- package/build/middlewares/web/utils/renderHTML.mjs.map +1 -0
- package/build/middlewares/web/utils/template.js +19 -20
- package/build/middlewares/web/utils/template.js.map +1 -1
- package/build/middlewares/web/utils/template.mjs +33 -0
- package/build/middlewares/web/utils/template.mjs.map +1 -0
- package/build/middlewares/web/utils/ui-options.js +66 -82
- package/build/middlewares/web/utils/ui-options.js.map +1 -1
- package/build/middlewares/web/utils/ui-options.mjs +69 -0
- package/build/middlewares/web/utils/ui-options.mjs.map +1 -0
- package/build/middlewares/web/utils/web-utils.js +17 -18
- package/build/middlewares/web/utils/web-utils.js.map +1 -1
- package/build/middlewares/web/utils/web-utils.mjs +18 -0
- package/build/middlewares/web/utils/web-utils.mjs.map +1 -0
- package/build/middlewares/web/web-api.js +18 -27
- package/build/middlewares/web/web-api.js.map +1 -1
- package/build/middlewares/web/web-api.mjs +19 -0
- package/build/middlewares/web/web-api.mjs.map +1 -0
- package/build/middlewares/web/web-middleware.d.ts +1 -1
- package/build/middlewares/web/web-middleware.js +16 -23
- package/build/middlewares/web/web-middleware.js.map +1 -1
- package/build/middlewares/web/web-middleware.mjs +16 -0
- package/build/middlewares/web/web-middleware.mjs.map +1 -0
- package/build/middlewares/web/web-urls.js +28 -29
- package/build/middlewares/web/web-urls.js.map +1 -1
- package/build/middlewares/web/web-urls.mjs +32 -0
- package/build/middlewares/web/web-urls.mjs.map +1 -0
- package/package.json +24 -11
- package/build/index.js.map +0 -1
- package/build/middlewares/web/index.js.map +0 -1
- package/build/types.js +0 -6
- package/build/types.js.map +0 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.mjs","names":[],"sources":["../../src/middlewares/log.ts"],"sourcesContent":["import _ from 'lodash';\n\nimport { HEADERS } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\n// FIXME: deprecated, moved to @verdaccio/dev-commons\nexport const LOG_STATUS_MESSAGE =\n \"@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'\";\nexport const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;\nexport const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;\n\nexport const log = (logger) => {\n return function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n // logger\n req.log = logger.child({ sub: 'in' });\n\n const _auth = req.headers.authorization;\n if (_.isNil(_auth) === false) {\n req.headers.authorization = '<Classified>';\n }\n\n const _cookie = req.get('cookie');\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = '<Classified>';\n }\n\n req.url = req.originalUrl;\n req.log.info({ req: req, ip: req.ip }, \"@{ip} requested '@{req.method} @{req.url}'\");\n req.originalUrl = req.url;\n\n if (_.isNil(_auth) === false) {\n req.headers.authorization = _auth;\n }\n\n if (_.isNil(_cookie) === false) {\n req.headers.cookie = _cookie;\n }\n\n let bytesin = 0;\n req.on('data', function (chunk): void {\n bytesin += chunk.length;\n });\n\n let bytesout = 0;\n const _write = res.write;\n // FIXME: res.write should return boolean\n // @ts-ignore\n res.write = function (buf): boolean {\n bytesout += buf.length;\n // @ts-ignore\n _write.apply(res, arguments);\n };\n\n const log = function (): void {\n const forwardedFor = req.get(HEADERS.FORWARDED_FOR);\n const remoteAddress = req.connection.remoteAddress;\n const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;\n let message;\n if (res.locals._verdaccio_error) {\n message = LOG_VERDACCIO_ERROR;\n } else {\n message = LOG_VERDACCIO_BYTES;\n }\n\n req.url = req.originalUrl;\n req.log.http(\n {\n request: {\n method: req.method,\n url: req.url,\n },\n user: req.remote_user?.name || null,\n remoteIP,\n status: res.statusCode,\n error: res.locals._verdaccio_error,\n bytes: {\n in: bytesin,\n out: bytesout,\n },\n },\n message\n );\n req.originalUrl = req.url;\n };\n\n req.on('close', function (): void {\n log();\n });\n\n const _end = res.end;\n // @ts-ignore\n res.end = function (buf): void {\n if (buf) {\n bytesout += buf.length;\n }\n // @ts-ignore\n _end.apply(res, arguments);\n log();\n };\n next();\n };\n};\n"],"mappings":";;;AAOA,IAAa,qBACX;AACF,IAAa,sBAAsB,GAAG,mBAAmB;AACzD,IAAa,sBAAsB,GAAG,mBAAmB;AAEzD,IAAa,OAAO,WAAW;CAC7B,OAAO,SAAS,IAAI,KAAqB,KAAsB,MAA8B;EAE3F,IAAI,MAAM,OAAO,MAAM,EAAE,KAAK,KAAK,CAAC;EAEpC,MAAM,QAAQ,IAAI,QAAQ;EAC1B,IAAI,EAAE,MAAM,KAAK,MAAM,OACrB,IAAI,QAAQ,gBAAgB;EAG9B,MAAM,UAAU,IAAI,IAAI,QAAQ;EAChC,IAAI,EAAE,MAAM,OAAO,MAAM,OACvB,IAAI,QAAQ,SAAS;EAGvB,IAAI,MAAM,IAAI;EACd,IAAI,IAAI,KAAK;GAAO;GAAK,IAAI,IAAI;EAAG,GAAG,4CAA4C;EACnF,IAAI,cAAc,IAAI;EAEtB,IAAI,EAAE,MAAM,KAAK,MAAM,OACrB,IAAI,QAAQ,gBAAgB;EAG9B,IAAI,EAAE,MAAM,OAAO,MAAM,OACvB,IAAI,QAAQ,SAAS;EAGvB,IAAI,UAAU;EACd,IAAI,GAAG,QAAQ,SAAU,OAAa;GACpC,WAAW,MAAM;EACnB,CAAC;EAED,IAAI,WAAW;EACf,MAAM,SAAS,IAAI;EAGnB,IAAI,QAAQ,SAAU,KAAc;GAClC,YAAY,IAAI;GAEhB,OAAO,MAAM,KAAK,SAAS;EAC7B;EAEA,MAAM,MAAM,WAAkB;GAC5B,MAAM,eAAe,IAAI,IAAI,QAAQ,aAAa;GAClD,MAAM,gBAAgB,IAAI,WAAW;GACrC,MAAM,WAAW,eAAe,GAAG,aAAa,OAAO,kBAAkB;GACzE,IAAI;GACJ,IAAI,IAAI,OAAO,kBACb,UAAU;QAEV,UAAU;GAGZ,IAAI,MAAM,IAAI;GACd,IAAI,IAAI,KACN;IACE,SAAS;KACP,QAAQ,IAAI;KACZ,KAAK,IAAI;IACX;IACA,MAAM,IAAI,aAAa,QAAQ;IAC/B;IACA,QAAQ,IAAI;IACZ,OAAO,IAAI,OAAO;IAClB,OAAO;KACL,IAAI;KACJ,KAAK;IACP;GACF,GACA,OACF;GACA,IAAI,cAAc,IAAI;EACxB;EAEA,IAAI,GAAG,SAAS,WAAkB;GAChC,IAAI;EACN,CAAC;EAED,MAAM,OAAO,IAAI;EAEjB,IAAI,MAAM,SAAU,KAAW;GAC7B,IAAI,KACF,YAAY,IAAI;GAGlB,KAAK,MAAM,KAAK,SAAS;GACzB,IAAI;EACN;EACA,KAAK;CACP;AACF"}
|
|
@@ -1,45 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
var
|
|
8
|
-
var _nodeUrl = require("node:url");
|
|
9
|
-
var _core = require("@verdaccio/core");
|
|
10
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
11
|
-
const debug = (0, _debug.default)('verdaccio:middleware:make-url-relative');
|
|
12
|
-
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let _verdaccio_core = require("@verdaccio/core");
|
|
3
|
+
let debug = require("debug");
|
|
4
|
+
debug = require_runtime.__toESM(debug);
|
|
5
|
+
let node_url = require("node:url");
|
|
6
|
+
//#region src/middlewares/make-url-relative.ts
|
|
7
|
+
var debug$1 = (0, debug.default)("verdaccio:middleware:make-url-relative");
|
|
13
8
|
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
9
|
+
* Removes the host from the URL and turns it into a relative URL.
|
|
10
|
+
* @param req
|
|
11
|
+
* @param res
|
|
12
|
+
* @param next
|
|
13
|
+
*/
|
|
19
14
|
function makeURLrelative(req, res, next) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
url = new _nodeUrl.URL(req.url, `${req.protocol}://${req.headers.host}/`);
|
|
32
|
-
} catch (error) {
|
|
33
|
-
return next(_core.errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
// Rebuild the URL without hostname
|
|
37
|
-
req.url = url.pathname + url.search + url.hash;
|
|
38
|
-
if (original !== req.url) {
|
|
39
|
-
debug('makeURLrelative: %o -> %o', original, req.url);
|
|
40
|
-
} else {
|
|
41
|
-
debug('makeURLrelative: %o (unchanged)', original);
|
|
42
|
-
}
|
|
43
|
-
next();
|
|
15
|
+
const original = req.url;
|
|
16
|
+
let url;
|
|
17
|
+
try {
|
|
18
|
+
url = new node_url.URL(req.url, `${req.protocol}://${req.headers.host}/`);
|
|
19
|
+
} catch (error) {
|
|
20
|
+
return next(_verdaccio_core.errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));
|
|
21
|
+
}
|
|
22
|
+
req.url = url.pathname + url.search + url.hash;
|
|
23
|
+
if (original !== req.url) debug$1("makeURLrelative: %o -> %o", original, req.url);
|
|
24
|
+
else debug$1("makeURLrelative: %o (unchanged)", original);
|
|
25
|
+
next();
|
|
44
26
|
}
|
|
27
|
+
//#endregion
|
|
28
|
+
exports.makeURLrelative = makeURLrelative;
|
|
29
|
+
|
|
45
30
|
//# sourceMappingURL=make-url-relative.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"make-url-relative.js","names":[
|
|
1
|
+
{"version":3,"file":"make-url-relative.js","names":[],"sources":["../../src/middlewares/make-url-relative.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { URL } from 'node:url';\n\nimport { errorUtils } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:make-url-relative');\n\n/**\n * Removes the host from the URL and turns it into a relative URL.\n * @param req\n * @param res\n * @param next\n */\nexport function makeURLrelative(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n const original = req.url;\n\n // npm requests can contain the full URL, including the hostname, for example:\n // tarball downloads. Removing the hostname makes the URL relative and allows\n // the application to handle requests in a more consistent way.\n\n let url;\n try {\n // In productive use, the URL is absolute (and base will be ignored)\n // In tests, the URL might brelative (and base will be used)\n // https://nodejs.org/docs/latest/api/url.html#new-urlinput-base\n url = new URL(req.url, `${req.protocol}://${req.headers.host}/`);\n } catch (error) {\n return next(errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));\n }\n\n // Rebuild the URL without hostname\n req.url = url.pathname + url.search + url.hash;\n\n if (original !== req.url) {\n debug('makeURLrelative: %o -> %o', original, req.url);\n } else {\n debug('makeURLrelative: %o (unchanged)', original);\n }\n next();\n}\n"],"mappings":";;;;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,wCAAwC;;;;;;;AAQjE,SAAgB,gBACd,KACA,KACA,MACM;CACN,MAAM,WAAW,IAAI;CAMrB,IAAI;CACJ,IAAI;EAIF,MAAM,IAAI,SAAA,IAAI,IAAI,KAAK,GAAG,IAAI,SAAS,KAAK,IAAI,QAAQ,KAAK,EAAE;CACjE,SAAS,OAAO;EACd,OAAO,KAAK,gBAAA,WAAW,cAAc,gBAAgB,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;CAC5E;CAGA,IAAI,MAAM,IAAI,WAAW,IAAI,SAAS,IAAI;CAE1C,IAAI,aAAa,IAAI,KACnB,QAAM,6BAA6B,UAAU,IAAI,GAAG;MAEpD,QAAM,mCAAmC,QAAQ;CAEnD,KAAK;AACP"}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { errorUtils } from "@verdaccio/core";
|
|
2
|
+
import buildDebug from "debug";
|
|
3
|
+
import { URL } from "node:url";
|
|
4
|
+
//#region src/middlewares/make-url-relative.ts
|
|
5
|
+
var debug = buildDebug("verdaccio:middleware:make-url-relative");
|
|
6
|
+
/**
|
|
7
|
+
* Removes the host from the URL and turns it into a relative URL.
|
|
8
|
+
* @param req
|
|
9
|
+
* @param res
|
|
10
|
+
* @param next
|
|
11
|
+
*/
|
|
12
|
+
function makeURLrelative(req, res, next) {
|
|
13
|
+
const original = req.url;
|
|
14
|
+
let url;
|
|
15
|
+
try {
|
|
16
|
+
url = new URL(req.url, `${req.protocol}://${req.headers.host}/`);
|
|
17
|
+
} catch (error) {
|
|
18
|
+
return next(errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));
|
|
19
|
+
}
|
|
20
|
+
req.url = url.pathname + url.search + url.hash;
|
|
21
|
+
if (original !== req.url) debug("makeURLrelative: %o -> %o", original, req.url);
|
|
22
|
+
else debug("makeURLrelative: %o (unchanged)", original);
|
|
23
|
+
next();
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
export { makeURLrelative };
|
|
27
|
+
|
|
28
|
+
//# sourceMappingURL=make-url-relative.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"make-url-relative.mjs","names":[],"sources":["../../src/middlewares/make-url-relative.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { URL } from 'node:url';\n\nimport { errorUtils } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:make-url-relative');\n\n/**\n * Removes the host from the URL and turns it into a relative URL.\n * @param req\n * @param res\n * @param next\n */\nexport function makeURLrelative(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n const original = req.url;\n\n // npm requests can contain the full URL, including the hostname, for example:\n // tarball downloads. Removing the hostname makes the URL relative and allows\n // the application to handle requests in a more consistent way.\n\n let url;\n try {\n // In productive use, the URL is absolute (and base will be ignored)\n // In tests, the URL might brelative (and base will be used)\n // https://nodejs.org/docs/latest/api/url.html#new-urlinput-base\n url = new URL(req.url, `${req.protocol}://${req.headers.host}/`);\n } catch (error) {\n return next(errorUtils.getBadRequest(`Invalid URL: ${req.url} (${error})`));\n }\n\n // Rebuild the URL without hostname\n req.url = url.pathname + url.search + url.hash;\n\n if (original !== req.url) {\n debug('makeURLrelative: %o -> %o', original, req.url);\n } else {\n debug('makeURLrelative: %o (unchanged)', original);\n }\n next();\n}\n"],"mappings":";;;;AAOA,IAAM,QAAQ,WAAW,wCAAwC;;;;;;;AAQjE,SAAgB,gBACd,KACA,KACA,MACM;CACN,MAAM,WAAW,IAAI;CAMrB,IAAI;CACJ,IAAI;EAIF,MAAM,IAAI,IAAI,IAAI,KAAK,GAAG,IAAI,SAAS,KAAK,IAAI,QAAQ,KAAK,EAAE;CACjE,SAAS,OAAO;EACd,OAAO,KAAK,WAAW,cAAc,gBAAgB,IAAI,IAAI,IAAI,MAAM,EAAE,CAAC;CAC5E;CAGA,IAAI,MAAM,IAAI,WAAW,IAAI,SAAS,IAAI;CAE1C,IAAI,aAAa,IAAI,KACnB,MAAM,6BAA6B,UAAU,IAAI,GAAG;MAEpD,MAAM,mCAAmC,QAAQ;CAEnD,KAAK;AACP"}
|
|
@@ -1,16 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.match = match;
|
|
1
|
+
//#region src/middlewares/match.ts
|
|
7
2
|
function match(regexp) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
next('route');
|
|
13
|
-
}
|
|
14
|
-
};
|
|
3
|
+
return function(req, res, next, value) {
|
|
4
|
+
if (regexp.exec(value)) next();
|
|
5
|
+
else next("route");
|
|
6
|
+
};
|
|
15
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.match = match;
|
|
10
|
+
|
|
16
11
|
//# sourceMappingURL=match.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"match.js","names":[
|
|
1
|
+
{"version":3,"file":"match.js","names":[],"sources":["../../src/middlewares/match.ts"],"sourcesContent":["import type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function match(regexp: RegExp): any {\n return function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string\n ): void {\n if (regexp.exec(value)) {\n next();\n } else {\n next('route');\n }\n };\n}\n"],"mappings":";AAEA,SAAgB,MAAM,QAAqB;CACzC,OAAO,SACL,KACA,KACA,MACA,OACM;EACN,IAAI,OAAO,KAAK,KAAK,GACnB,KAAK;OAEL,KAAK,OAAO;CAEhB;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"match.mjs","names":[],"sources":["../../src/middlewares/match.ts"],"sourcesContent":["import type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function match(regexp: RegExp): any {\n return function (\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string\n ): void {\n if (regexp.exec(value)) {\n next();\n } else {\n next('route');\n }\n };\n}\n"],"mappings":";AAEA,SAAgB,MAAM,QAAqB;CACzC,OAAO,SACL,KACA,KACA,MACA,OACM;EACN,IAAI,OAAO,KAAK,KAAK,GACnB,KAAK;OAEL,KAAK,OAAO;CAEhB;AACF"}
|
|
@@ -1,22 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.media = media;
|
|
7
|
-
var _core = require("@verdaccio/core");
|
|
1
|
+
let _verdaccio_core = require("@verdaccio/core");
|
|
2
|
+
//#region src/middlewares/media.ts
|
|
8
3
|
function media(expect) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
next();
|
|
19
|
-
}
|
|
20
|
-
};
|
|
4
|
+
return function(req, res, next) {
|
|
5
|
+
const header = req.headers[_verdaccio_core.HEADER_TYPE.CONTENT_TYPE];
|
|
6
|
+
if (!header) {
|
|
7
|
+
next(_verdaccio_core.errorUtils.getCode(_verdaccio_core.HTTP_STATUS.UNSUPPORTED_MEDIA, "content-type is missing, expect: " + expect));
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (typeof header !== "string" || header.split(";")[0].trim() !== expect) next(_verdaccio_core.errorUtils.getCode(_verdaccio_core.HTTP_STATUS.UNSUPPORTED_MEDIA, "wrong content-type, expect: " + expect + ", got: " + req.get[_verdaccio_core.HEADER_TYPE.CONTENT_TYPE]));
|
|
11
|
+
else next();
|
|
12
|
+
};
|
|
21
13
|
}
|
|
14
|
+
//#endregion
|
|
15
|
+
exports.media = media;
|
|
16
|
+
|
|
22
17
|
//# sourceMappingURL=media.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"media.js","names":[
|
|
1
|
+
{"version":3,"file":"media.js","names":[],"sources":["../../src/middlewares/media.ts"],"sourcesContent":["import { HEADER_TYPE, HTTP_STATUS, errorUtils } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function media(expect: string | null): any {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n const header = req.headers[HEADER_TYPE.CONTENT_TYPE];\n if (!header) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'content-type is missing, expect: ' + expect\n )\n );\n return;\n }\n\n if (typeof header !== 'string' || header.split(';')[0].trim() !== expect) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'wrong content-type, expect: ' + expect + ', got: ' + req.get[HEADER_TYPE.CONTENT_TYPE]\n )\n );\n } else {\n next();\n }\n };\n}\n"],"mappings":";;AAIA,SAAgB,MAAM,QAA4B;CAChD,OAAO,SAAU,KAAqB,KAAsB,MAA8B;EACxF,MAAM,SAAS,IAAI,QAAQ,gBAAA,YAAY;EACvC,IAAI,CAAC,QAAQ;GACX,KACE,gBAAA,WAAW,QACT,gBAAA,YAAY,mBACZ,sCAAsC,MACxC,CACF;GACA;EACF;EAEA,IAAI,OAAO,WAAW,YAAY,OAAO,MAAM,GAAG,EAAE,GAAG,KAAK,MAAM,QAChE,KACE,gBAAA,WAAW,QACT,gBAAA,YAAY,mBACZ,iCAAiC,SAAS,YAAY,IAAI,IAAI,gBAAA,YAAY,aAC5E,CACF;OAEA,KAAK;CAET;AACF"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { HEADER_TYPE, HTTP_STATUS, errorUtils } from "@verdaccio/core";
|
|
2
|
+
//#region src/middlewares/media.ts
|
|
3
|
+
function media(expect) {
|
|
4
|
+
return function(req, res, next) {
|
|
5
|
+
const header = req.headers[HEADER_TYPE.CONTENT_TYPE];
|
|
6
|
+
if (!header) {
|
|
7
|
+
next(errorUtils.getCode(HTTP_STATUS.UNSUPPORTED_MEDIA, "content-type is missing, expect: " + expect));
|
|
8
|
+
return;
|
|
9
|
+
}
|
|
10
|
+
if (typeof header !== "string" || header.split(";")[0].trim() !== expect) next(errorUtils.getCode(HTTP_STATUS.UNSUPPORTED_MEDIA, "wrong content-type, expect: " + expect + ", got: " + req.get[HEADER_TYPE.CONTENT_TYPE]));
|
|
11
|
+
else next();
|
|
12
|
+
};
|
|
13
|
+
}
|
|
14
|
+
//#endregion
|
|
15
|
+
export { media };
|
|
16
|
+
|
|
17
|
+
//# sourceMappingURL=media.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"media.mjs","names":[],"sources":["../../src/middlewares/media.ts"],"sourcesContent":["import { HEADER_TYPE, HTTP_STATUS, errorUtils } from '@verdaccio/core';\n\nimport type { $NextFunctionVer, $RequestExtend, $ResponseExtend } from '../types';\n\nexport function media(expect: string | null): any {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n const header = req.headers[HEADER_TYPE.CONTENT_TYPE];\n if (!header) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'content-type is missing, expect: ' + expect\n )\n );\n return;\n }\n\n if (typeof header !== 'string' || header.split(';')[0].trim() !== expect) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'wrong content-type, expect: ' + expect + ', got: ' + req.get[HEADER_TYPE.CONTENT_TYPE]\n )\n );\n } else {\n next();\n }\n };\n}\n"],"mappings":";;AAIA,SAAgB,MAAM,QAA4B;CAChD,OAAO,SAAU,KAAqB,KAAsB,MAA8B;EACxF,MAAM,SAAS,IAAI,QAAQ,YAAY;EACvC,IAAI,CAAC,QAAQ;GACX,KACE,WAAW,QACT,YAAY,mBACZ,sCAAsC,MACxC,CACF;GACA;EACF;EAEA,IAAI,OAAO,WAAW,YAAY,OAAO,MAAM,GAAG,EAAE,GAAG,KAAK,MAAM,QAChE,KACE,WAAW,QACT,YAAY,mBACZ,iCAAiC,SAAS,YAAY,IAAI,IAAI,YAAY,aAC5E,CACF;OAEA,KAAK;CAET;AACF"}
|
|
@@ -1,13 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.rateLimit = rateLimit;
|
|
7
|
-
var _expressRateLimit = _interopRequireDefault(require("express-rate-limit"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let express_rate_limit = require("express-rate-limit");
|
|
3
|
+
express_rate_limit = require_runtime.__toESM(express_rate_limit);
|
|
4
|
+
//#region src/middlewares/rate-limit.ts
|
|
9
5
|
function rateLimit(rateLimitOptions) {
|
|
10
|
-
|
|
11
|
-
return limiter;
|
|
6
|
+
return new express_rate_limit.default(rateLimitOptions);
|
|
12
7
|
}
|
|
8
|
+
//#endregion
|
|
9
|
+
exports.rateLimit = rateLimit;
|
|
10
|
+
|
|
13
11
|
//# sourceMappingURL=rate-limit.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rate-limit.js","names":[
|
|
1
|
+
{"version":3,"file":"rate-limit.js","names":[],"sources":["../../src/middlewares/rate-limit.ts"],"sourcesContent":["import RateLimit from 'express-rate-limit';\n\nimport type { RateLimit as RateLimitType } from '@verdaccio/types';\n\nexport function rateLimit(rateLimitOptions?: RateLimitType) {\n const limiter = new RateLimit(rateLimitOptions);\n return limiter;\n}\n"],"mappings":";;;;AAIA,SAAgB,UAAU,kBAAkC;CAE1D,OAAO,IADa,mBAAA,QAAU,gBACvB;AACT"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rate-limit.mjs","names":[],"sources":["../../src/middlewares/rate-limit.ts"],"sourcesContent":["import RateLimit from 'express-rate-limit';\n\nimport type { RateLimit as RateLimitType } from '@verdaccio/types';\n\nexport function rateLimit(rateLimitOptions?: RateLimitType) {\n const limiter = new RateLimit(rateLimitOptions);\n return limiter;\n}\n"],"mappings":";;AAIA,SAAgB,UAAU,kBAAkC;CAE1D,OAAO,IADa,UAAU,gBACvB;AACT"}
|
|
@@ -1,30 +1,21 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.getRequestOptions = getRequestOptions;
|
|
7
|
-
var _debug = _interopRequireDefault(require("debug"));
|
|
8
|
-
function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
|
|
9
|
-
const debug = (0, _debug.default)('verdaccio:middleware:request-options');
|
|
1
|
+
const require_runtime = require("../_virtual/_rolldown/runtime.js");
|
|
2
|
+
let debug = require("debug");
|
|
3
|
+
debug = require_runtime.__toESM(debug);
|
|
4
|
+
//#region src/middlewares/request-options.ts
|
|
5
|
+
var debug$1 = (0, debug.default)("verdaccio:middleware:request-options");
|
|
10
6
|
function getRequestOptions(req) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
protocol: req.protocol,
|
|
22
|
-
headers: req.headers,
|
|
23
|
-
remoteAddress: req.socket.remoteAddress,
|
|
24
|
-
byPassCache: req.query.write === 'true',
|
|
25
|
-
username: req.remote_user?.name ?? undefined
|
|
26
|
-
};
|
|
27
|
-
debug('request options: %o', requestOptions);
|
|
28
|
-
return requestOptions;
|
|
7
|
+
const requestOptions = {
|
|
8
|
+
host: req.host,
|
|
9
|
+
protocol: req.protocol,
|
|
10
|
+
headers: req.headers,
|
|
11
|
+
remoteAddress: req.socket.remoteAddress,
|
|
12
|
+
byPassCache: req.query.write === "true",
|
|
13
|
+
username: req.remote_user?.name ?? void 0
|
|
14
|
+
};
|
|
15
|
+
debug$1("request options: %o", requestOptions);
|
|
16
|
+
return requestOptions;
|
|
29
17
|
}
|
|
18
|
+
//#endregion
|
|
19
|
+
exports.getRequestOptions = getRequestOptions;
|
|
20
|
+
|
|
30
21
|
//# sourceMappingURL=request-options.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-options.js","names":[
|
|
1
|
+
{"version":3,"file":"request-options.js","names":[],"sources":["../../src/middlewares/request-options.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { IncomingHttpHeaders } from 'node:http';\n\nimport type { RequestOptions } from '@verdaccio/url';\n\nimport type { $RequestExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:request-options');\n\nexport function getRequestOptions(req: $RequestExtend): RequestOptions {\n const requestOptions = {\n // FIXME: decide if host should contain port or not\n //\n // Express 4:\n // - req.host is marked as deprecated since it does not include the port\n // - use req.headers['host'] instead, which includes the port\n // Express 5:\n // - req.host is fully supported and includes the port\n // - https://expressjs.com/en/api.html#req.host\n host: req.host,\n protocol: req.protocol,\n headers: req.headers as IncomingHttpHeaders,\n remoteAddress: req.socket.remoteAddress,\n byPassCache: req.query.write === 'true',\n username: req.remote_user?.name ?? undefined,\n };\n\n debug('request options: %o', requestOptions);\n\n return requestOptions;\n}\n"],"mappings":";;;;AAOA,IAAM,WAAA,GAAA,MAAA,SAAmB,sCAAsC;AAE/D,SAAgB,kBAAkB,KAAqC;CACrE,MAAM,iBAAiB;EASrB,MAAM,IAAI;EACV,UAAU,IAAI;EACd,SAAS,IAAI;EACb,eAAe,IAAI,OAAO;EAC1B,aAAa,IAAI,MAAM,UAAU;EACjC,UAAU,IAAI,aAAa,QAAQ,KAAA;CACrC;CAEA,QAAM,uBAAuB,cAAc;CAE3C,OAAO;AACT"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import buildDebug from "debug";
|
|
2
|
+
//#region src/middlewares/request-options.ts
|
|
3
|
+
var debug = buildDebug("verdaccio:middleware:request-options");
|
|
4
|
+
function getRequestOptions(req) {
|
|
5
|
+
const requestOptions = {
|
|
6
|
+
host: req.host,
|
|
7
|
+
protocol: req.protocol,
|
|
8
|
+
headers: req.headers,
|
|
9
|
+
remoteAddress: req.socket.remoteAddress,
|
|
10
|
+
byPassCache: req.query.write === "true",
|
|
11
|
+
username: req.remote_user?.name ?? void 0
|
|
12
|
+
};
|
|
13
|
+
debug("request options: %o", requestOptions);
|
|
14
|
+
return requestOptions;
|
|
15
|
+
}
|
|
16
|
+
//#endregion
|
|
17
|
+
export { getRequestOptions };
|
|
18
|
+
|
|
19
|
+
//# sourceMappingURL=request-options.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"request-options.mjs","names":[],"sources":["../../src/middlewares/request-options.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport type { IncomingHttpHeaders } from 'node:http';\n\nimport type { RequestOptions } from '@verdaccio/url';\n\nimport type { $RequestExtend } from '../types';\n\nconst debug = buildDebug('verdaccio:middleware:request-options');\n\nexport function getRequestOptions(req: $RequestExtend): RequestOptions {\n const requestOptions = {\n // FIXME: decide if host should contain port or not\n //\n // Express 4:\n // - req.host is marked as deprecated since it does not include the port\n // - use req.headers['host'] instead, which includes the port\n // Express 5:\n // - req.host is fully supported and includes the port\n // - https://expressjs.com/en/api.html#req.host\n host: req.host,\n protocol: req.protocol,\n headers: req.headers as IncomingHttpHeaders,\n remoteAddress: req.socket.remoteAddress,\n byPassCache: req.query.write === 'true',\n username: req.remote_user?.name ?? undefined,\n };\n\n debug('request options: %o', requestOptions);\n\n return requestOptions;\n}\n"],"mappings":";;AAOA,IAAM,QAAQ,WAAW,sCAAsC;AAE/D,SAAgB,kBAAkB,KAAqC;CACrE,MAAM,iBAAiB;EASrB,MAAM,IAAI;EACV,UAAU,IAAI;EACd,SAAS,IAAI;EACb,eAAe,IAAI,OAAO;EAC1B,aAAa,IAAI,MAAM,UAAU;EACjC,UAAU,IAAI,aAAa,QAAQ,KAAA;CACrC;CAEA,MAAM,uBAAuB,cAAc;CAE3C,OAAO;AACT"}
|
|
@@ -1,115 +1,100 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Minimal storage surface required to enforce generated token metadata. Typed
|
|
12
|
-
* structurally so this package does not need to depend on `@verdaccio/store`.
|
|
13
|
-
*/
|
|
14
|
-
|
|
1
|
+
let _verdaccio_core = require("@verdaccio/core");
|
|
2
|
+
//#region src/middlewares/token-auth.ts
|
|
3
|
+
var WRITE_METHODS = new Set([
|
|
4
|
+
"DELETE",
|
|
5
|
+
"PATCH",
|
|
6
|
+
"POST",
|
|
7
|
+
"PUT"
|
|
8
|
+
]);
|
|
15
9
|
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
10
|
+
* Resolve the client address of an incoming request for CIDR matching.
|
|
11
|
+
*
|
|
12
|
+
* Uses Express' `req.ip`, which already honors the application's `trust proxy`
|
|
13
|
+
* setting (`config.server.trustProxy`): when the operator has declared trusted
|
|
14
|
+
* proxies, `req.ip` is the upstream-most untrusted address parsed from
|
|
15
|
+
* `X-Forwarded-For`; otherwise it is the direct socket peer and the forwarded
|
|
16
|
+
* header is ignored entirely.
|
|
17
|
+
*
|
|
18
|
+
* The middleware must NOT read `X-Forwarded-For` on its own — doing so
|
|
19
|
+
* unconditionally would let any client spoof its address (and bypass a token's
|
|
20
|
+
* CIDR whitelist) simply by sending the header. Falls back to the raw socket
|
|
21
|
+
* address and is normalized (trimmed, IPv4-mapped IPv6 prefix stripped) via
|
|
22
|
+
* {@link ipUtils.normalizeAddress}.
|
|
23
|
+
*
|
|
24
|
+
* @param req the incoming Express request
|
|
25
|
+
* @returns the normalized client address, or `undefined` when none can be determined
|
|
26
|
+
*/
|
|
33
27
|
function getClientAddress(req) {
|
|
34
|
-
|
|
28
|
+
return _verdaccio_core.ipUtils.normalizeAddress(req.ip || req.socket.remoteAddress);
|
|
35
29
|
}
|
|
36
|
-
|
|
37
30
|
/**
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
* Find the stored token whose `key` matches the key carried by the request.
|
|
32
|
+
*
|
|
33
|
+
* @param tokens the tokens persisted for the authenticated user
|
|
34
|
+
* @param tokenKey the key extracted from the presented generated token
|
|
35
|
+
* @returns the matching {@link Token}, or `undefined` when it has been revoked / never existed
|
|
36
|
+
*/
|
|
44
37
|
function findToken(tokens, tokenKey) {
|
|
45
|
-
|
|
46
|
-
key
|
|
47
|
-
}) => key === tokenKey);
|
|
38
|
+
return tokens.find(({ key }) => key === tokenKey);
|
|
48
39
|
}
|
|
49
|
-
|
|
50
40
|
/**
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
41
|
+
* Express middleware that enforces the metadata of npm-style generated tokens
|
|
42
|
+
* (created via `POST /-/npm/v1/tokens`).
|
|
43
|
+
*
|
|
44
|
+
* A generated token embeds a server-issued `key` that is recovered from the
|
|
45
|
+
* verified credentials as `remote_user.token.key`. This middleware looks that
|
|
46
|
+
* key up in storage and rejects the request when the token:
|
|
47
|
+
* - is missing from storage (revoked or never issued);
|
|
48
|
+
* - is used from a client address outside its `cidr` whitelist;
|
|
49
|
+
* - is `readonly` and the request uses a write method (`DELETE`/`PATCH`/`POST`/`PUT`).
|
|
50
|
+
*
|
|
51
|
+
* Requests that do not carry a generated token key (e.g. interactive logins)
|
|
52
|
+
* pass through untouched. It must run after the JWT/auth middleware has
|
|
53
|
+
* populated `remote_user`. Failures fail closed: a storage lookup error yields
|
|
54
|
+
* an internal error rather than allowing the request.
|
|
55
|
+
*
|
|
56
|
+
* @param storage storage exposing {@link TokenReadableStorage.readTokens} to load the user's tokens
|
|
57
|
+
* @param logger logger used to record rejected attempts and lookup failures
|
|
58
|
+
* @returns an Express {@link RequestHandler} that calls `next()` to allow or `next(error)` to reject
|
|
59
|
+
*/
|
|
70
60
|
function enforceGeneratedTokenMetadata(storage, logger) {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return next();
|
|
107
|
-
} catch (error) {
|
|
108
|
-
logger.error({
|
|
109
|
-
error: error.msg
|
|
110
|
-
}, 'generated token metadata lookup failed: @{error}');
|
|
111
|
-
return next(_core.errorUtils.getInternalError(error.message));
|
|
112
|
-
}
|
|
113
|
-
};
|
|
61
|
+
return async function(req, _res, next) {
|
|
62
|
+
const remoteUser = req.remote_user;
|
|
63
|
+
const tokenKey = remoteUser?.token?.key;
|
|
64
|
+
if (!tokenKey) return next();
|
|
65
|
+
const user = remoteUser?.name;
|
|
66
|
+
if (typeof user !== "string") return next(_verdaccio_core.errorUtils.getForbidden(_verdaccio_core.API_ERROR.UNAUTHORIZED_ACCESS));
|
|
67
|
+
try {
|
|
68
|
+
const token = findToken(await storage.readTokens({ user }), tokenKey);
|
|
69
|
+
if (!token) {
|
|
70
|
+
logger.warn({
|
|
71
|
+
tokenKey,
|
|
72
|
+
user
|
|
73
|
+
}, "generated token @{tokenKey} for user @{user} is missing");
|
|
74
|
+
return next(_verdaccio_core.errorUtils.getForbidden(_verdaccio_core.API_ERROR.UNAUTHORIZED_ACCESS));
|
|
75
|
+
}
|
|
76
|
+
if (!_verdaccio_core.ipUtils.isAddressAllowed(getClientAddress(req), token.cidr)) {
|
|
77
|
+
logger.warn({
|
|
78
|
+
tokenKey,
|
|
79
|
+
user
|
|
80
|
+
}, "generated token @{tokenKey} for user @{user} was used outside its CIDR whitelist");
|
|
81
|
+
return next(_verdaccio_core.errorUtils.getForbidden(_verdaccio_core.API_ERROR.UNAUTHORIZED_ACCESS));
|
|
82
|
+
}
|
|
83
|
+
if (token.readonly && WRITE_METHODS.has(req.method)) {
|
|
84
|
+
logger.warn({
|
|
85
|
+
tokenKey,
|
|
86
|
+
user
|
|
87
|
+
}, "readonly generated token @{tokenKey} for user @{user} was used for a write request");
|
|
88
|
+
return next(_verdaccio_core.errorUtils.getForbidden(_verdaccio_core.API_ERROR.UNAUTHORIZED_ACCESS));
|
|
89
|
+
}
|
|
90
|
+
return next();
|
|
91
|
+
} catch (error) {
|
|
92
|
+
logger.error({ error: error.msg }, "generated token metadata lookup failed: @{error}");
|
|
93
|
+
return next(_verdaccio_core.errorUtils.getInternalError(error.message));
|
|
94
|
+
}
|
|
95
|
+
};
|
|
114
96
|
}
|
|
97
|
+
//#endregion
|
|
98
|
+
exports.enforceGeneratedTokenMetadata = enforceGeneratedTokenMetadata;
|
|
99
|
+
|
|
115
100
|
//# sourceMappingURL=token-auth.js.map
|