@verdaccio/middleware 8.0.5 → 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.
Files changed (119) hide show
  1. package/build/_virtual/_rolldown/runtime.js +23 -0
  2. package/build/index.js +62 -229
  3. package/build/index.mjs +23 -0
  4. package/build/middlewares/allow.js +42 -50
  5. package/build/middlewares/allow.js.map +1 -1
  6. package/build/middlewares/allow.mjs +44 -0
  7. package/build/middlewares/allow.mjs.map +1 -0
  8. package/build/middlewares/antiLoop.js +21 -40
  9. package/build/middlewares/antiLoop.js.map +1 -1
  10. package/build/middlewares/antiLoop.mjs +25 -0
  11. package/build/middlewares/antiLoop.mjs.map +1 -0
  12. package/build/middlewares/api_urls.js +66 -59
  13. package/build/middlewares/api_urls.js.map +1 -1
  14. package/build/middlewares/api_urls.mjs +59 -0
  15. package/build/middlewares/api_urls.mjs.map +1 -0
  16. package/build/middlewares/body-parser.js +24 -32
  17. package/build/middlewares/body-parser.js.map +1 -1
  18. package/build/middlewares/body-parser.mjs +28 -0
  19. package/build/middlewares/body-parser.mjs.map +1 -0
  20. package/build/middlewares/encode-pkg.js +20 -36
  21. package/build/middlewares/encode-pkg.js.map +1 -1
  22. package/build/middlewares/encode-pkg.mjs +22 -0
  23. package/build/middlewares/encode-pkg.mjs.map +1 -0
  24. package/build/middlewares/error.js +53 -71
  25. package/build/middlewares/error.js.map +1 -1
  26. package/build/middlewares/error.mjs +53 -0
  27. package/build/middlewares/error.mjs.map +1 -0
  28. package/build/middlewares/final.js +46 -57
  29. package/build/middlewares/final.js.map +1 -1
  30. package/build/middlewares/final.mjs +46 -0
  31. package/build/middlewares/final.mjs.map +1 -0
  32. package/build/middlewares/json.js +7 -11
  33. package/build/middlewares/json.js.map +1 -1
  34. package/build/middlewares/json.mjs +10 -0
  35. package/build/middlewares/json.mjs.map +1 -0
  36. package/build/middlewares/log.js +73 -95
  37. package/build/middlewares/log.js.map +1 -1
  38. package/build/middlewares/log.mjs +71 -0
  39. package/build/middlewares/log.mjs.map +1 -0
  40. package/build/middlewares/make-url-relative.js +26 -41
  41. package/build/middlewares/make-url-relative.js.map +1 -1
  42. package/build/middlewares/make-url-relative.mjs +28 -0
  43. package/build/middlewares/make-url-relative.mjs.map +1 -0
  44. package/build/middlewares/match.js +8 -13
  45. package/build/middlewares/match.js.map +1 -1
  46. package/build/middlewares/match.mjs +11 -0
  47. package/build/middlewares/match.mjs.map +1 -0
  48. package/build/middlewares/media.js +14 -19
  49. package/build/middlewares/media.js.map +1 -1
  50. package/build/middlewares/media.mjs +17 -0
  51. package/build/middlewares/media.mjs.map +1 -0
  52. package/build/middlewares/rate-limit.js +8 -10
  53. package/build/middlewares/rate-limit.js.map +1 -1
  54. package/build/middlewares/rate-limit.mjs +9 -0
  55. package/build/middlewares/rate-limit.mjs.map +1 -0
  56. package/build/middlewares/request-options.js +18 -27
  57. package/build/middlewares/request-options.js.map +1 -1
  58. package/build/middlewares/request-options.mjs +19 -0
  59. package/build/middlewares/request-options.mjs.map +1 -0
  60. package/build/middlewares/token-auth.js +90 -105
  61. package/build/middlewares/token-auth.js.map +1 -1
  62. package/build/middlewares/token-auth.mjs +100 -0
  63. package/build/middlewares/token-auth.mjs.map +1 -0
  64. package/build/middlewares/user-agent.js +10 -12
  65. package/build/middlewares/user-agent.js.map +1 -1
  66. package/build/middlewares/user-agent.mjs +13 -0
  67. package/build/middlewares/user-agent.mjs.map +1 -0
  68. package/build/middlewares/validation.js +10 -18
  69. package/build/middlewares/validation.js.map +1 -1
  70. package/build/middlewares/validation.mjs +14 -0
  71. package/build/middlewares/validation.mjs.map +1 -0
  72. package/build/middlewares/web/index.js +4 -35
  73. package/build/middlewares/web/index.mjs +4 -0
  74. package/build/middlewares/web/render-web.js +86 -115
  75. package/build/middlewares/web/render-web.js.map +1 -1
  76. package/build/middlewares/web/render-web.mjs +85 -0
  77. package/build/middlewares/web/render-web.mjs.map +1 -0
  78. package/build/middlewares/web/security.js +29 -41
  79. package/build/middlewares/web/security.js.map +1 -1
  80. package/build/middlewares/web/security.mjs +30 -0
  81. package/build/middlewares/web/security.mjs.map +1 -0
  82. package/build/middlewares/web/utils/manifest.js +17 -18
  83. package/build/middlewares/web/utils/manifest.js.map +1 -1
  84. package/build/middlewares/web/utils/manifest.mjs +21 -0
  85. package/build/middlewares/web/utils/manifest.mjs.map +1 -0
  86. package/build/middlewares/web/utils/renderHTML.js +46 -50
  87. package/build/middlewares/web/utils/renderHTML.js.map +1 -1
  88. package/build/middlewares/web/utils/renderHTML.mjs +48 -0
  89. package/build/middlewares/web/utils/renderHTML.mjs.map +1 -0
  90. package/build/middlewares/web/utils/template.js +19 -20
  91. package/build/middlewares/web/utils/template.js.map +1 -1
  92. package/build/middlewares/web/utils/template.mjs +33 -0
  93. package/build/middlewares/web/utils/template.mjs.map +1 -0
  94. package/build/middlewares/web/utils/ui-options.js +66 -82
  95. package/build/middlewares/web/utils/ui-options.js.map +1 -1
  96. package/build/middlewares/web/utils/ui-options.mjs +69 -0
  97. package/build/middlewares/web/utils/ui-options.mjs.map +1 -0
  98. package/build/middlewares/web/utils/web-utils.js +17 -18
  99. package/build/middlewares/web/utils/web-utils.js.map +1 -1
  100. package/build/middlewares/web/utils/web-utils.mjs +18 -0
  101. package/build/middlewares/web/utils/web-utils.mjs.map +1 -0
  102. package/build/middlewares/web/web-api.js +18 -27
  103. package/build/middlewares/web/web-api.js.map +1 -1
  104. package/build/middlewares/web/web-api.mjs +19 -0
  105. package/build/middlewares/web/web-api.mjs.map +1 -0
  106. package/build/middlewares/web/web-middleware.d.ts +1 -1
  107. package/build/middlewares/web/web-middleware.js +16 -23
  108. package/build/middlewares/web/web-middleware.js.map +1 -1
  109. package/build/middlewares/web/web-middleware.mjs +16 -0
  110. package/build/middlewares/web/web-middleware.mjs.map +1 -0
  111. package/build/middlewares/web/web-urls.js +28 -29
  112. package/build/middlewares/web/web-urls.js.map +1 -1
  113. package/build/middlewares/web/web-urls.mjs +32 -0
  114. package/build/middlewares/web/web-urls.mjs.map +1 -0
  115. package/package.json +47 -34
  116. package/build/index.js.map +0 -1
  117. package/build/middlewares/web/index.js.map +0 -1
  118. package/build/types.js +0 -6
  119. 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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.makeURLrelative = makeURLrelative;
7
- var _debug = _interopRequireDefault(require("debug"));
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
- * Removes the host from the URL and turns it into a relative URL.
15
- * @param req
16
- * @param res
17
- * @param next
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
- const original = req.url;
21
-
22
- // npm requests can contain the full URL, including the hostname, for example:
23
- // tarball downloads. Removing the hostname makes the URL relative and allows
24
- // the application to handle requests in a more consistent way.
25
-
26
- let url;
27
- try {
28
- // In productive use, the URL is absolute (and base will be ignored)
29
- // In tests, the URL might brelative (and base will be used)
30
- // https://nodejs.org/docs/latest/api/url.html#new-urlinput-base
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":["_debug","_interopRequireDefault","require","_nodeUrl","_core","e","__esModule","default","debug","buildDebug","makeURLrelative","req","res","next","original","url","URL","protocol","headers","host","error","errorUtils","getBadRequest","pathname","search","hash"],"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":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,KAAA,GAAAF,OAAA;AAA6C,SAAAD,uBAAAI,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAI7C,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,wCAAwC,CAAC;;AAElE;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,eAAeA,CAC7BC,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EAChB;EACN,MAAMC,QAAQ,GAAGH,GAAG,CAACI,GAAG;;EAExB;EACA;EACA;;EAEA,IAAIA,GAAG;EACP,IAAI;IACF;IACA;IACA;IACAA,GAAG,GAAG,IAAIC,YAAG,CAACL,GAAG,CAACI,GAAG,EAAE,GAAGJ,GAAG,CAACM,QAAQ,MAAMN,GAAG,CAACO,OAAO,CAACC,IAAI,GAAG,CAAC;EAClE,CAAC,CAAC,OAAOC,KAAK,EAAE;IACd,OAAOP,IAAI,CAACQ,gBAAU,CAACC,aAAa,CAAC,gBAAgBX,GAAG,CAACI,GAAG,KAAKK,KAAK,GAAG,CAAC,CAAC;EAC7E;;EAEA;EACAT,GAAG,CAACI,GAAG,GAAGA,GAAG,CAACQ,QAAQ,GAAGR,GAAG,CAACS,MAAM,GAAGT,GAAG,CAACU,IAAI;EAE9C,IAAIX,QAAQ,KAAKH,GAAG,CAACI,GAAG,EAAE;IACxBP,KAAK,CAAC,2BAA2B,EAAEM,QAAQ,EAAEH,GAAG,CAACI,GAAG,CAAC;EACvD,CAAC,MAAM;IACLP,KAAK,CAAC,iCAAiC,EAAEM,QAAQ,CAAC;EACpD;EACAD,IAAI,CAAC,CAAC;AACR","ignoreList":[]}
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
- "use strict";
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
- return function (req, res, next, value) {
9
- if (regexp.exec(value)) {
10
- next();
11
- } else {
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":["match","regexp","req","res","next","value","exec"],"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":";;;;;;AAEO,SAASA,KAAKA,CAACC,MAAc,EAAO;EACzC,OAAO,UACLC,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EACtBC,KAAa,EACP;IACN,IAAIJ,MAAM,CAACK,IAAI,CAACD,KAAK,CAAC,EAAE;MACtBD,IAAI,CAAC,CAAC;IACR,CAAC,MAAM;MACLA,IAAI,CAAC,OAAO,CAAC;IACf;EACF,CAAC;AACH","ignoreList":[]}
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,11 @@
1
+ //#region src/middlewares/match.ts
2
+ function match(regexp) {
3
+ return function(req, res, next, value) {
4
+ if (regexp.exec(value)) next();
5
+ else next("route");
6
+ };
7
+ }
8
+ //#endregion
9
+ export { match };
10
+
11
+ //# sourceMappingURL=match.mjs.map
@@ -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
- "use strict";
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
- return function (req, res, next) {
10
- const header = req.headers[_core.HEADER_TYPE.CONTENT_TYPE];
11
- if (!header) {
12
- next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNSUPPORTED_MEDIA, 'content-type is missing, expect: ' + expect));
13
- return;
14
- }
15
- if (typeof header !== 'string' || header.split(';')[0].trim() !== expect) {
16
- next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNSUPPORTED_MEDIA, 'wrong content-type, expect: ' + expect + ', got: ' + req.get[_core.HEADER_TYPE.CONTENT_TYPE]));
17
- } else {
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":["_core","require","media","expect","req","res","next","header","headers","HEADER_TYPE","CONTENT_TYPE","errorUtils","getCode","HTTP_STATUS","UNSUPPORTED_MEDIA","split","trim","get"],"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":";;;;;;AAAA,IAAAA,KAAA,GAAAC,OAAA;AAIO,SAASC,KAAKA,CAACC,MAAqB,EAAO;EAChD,OAAO,UAAUC,GAAmB,EAAEC,GAAoB,EAAEC,IAAsB,EAAQ;IACxF,MAAMC,MAAM,GAAGH,GAAG,CAACI,OAAO,CAACC,iBAAW,CAACC,YAAY,CAAC;IACpD,IAAI,CAACH,MAAM,EAAE;MACXD,IAAI,CACFK,gBAAU,CAACC,OAAO,CAChBC,iBAAW,CAACC,iBAAiB,EAC7B,mCAAmC,GAAGX,MACxC,CACF,CAAC;MACD;IACF;IAEA,IAAI,OAAOI,MAAM,KAAK,QAAQ,IAAIA,MAAM,CAACQ,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAACC,IAAI,CAAC,CAAC,KAAKb,MAAM,EAAE;MACxEG,IAAI,CACFK,gBAAU,CAACC,OAAO,CAChBC,iBAAW,CAACC,iBAAiB,EAC7B,8BAA8B,GAAGX,MAAM,GAAG,SAAS,GAAGC,GAAG,CAACa,GAAG,CAACR,iBAAW,CAACC,YAAY,CACxF,CACF,CAAC;IACH,CAAC,MAAM;MACLJ,IAAI,CAAC,CAAC;IACR;EACF,CAAC;AACH","ignoreList":[]}
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- const limiter = new _expressRateLimit.default(rateLimitOptions);
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":["_expressRateLimit","_interopRequireDefault","require","e","__esModule","default","rateLimit","rateLimitOptions","limiter","RateLimit"],"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":";;;;;;AAAA,IAAAA,iBAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA2C,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAIpC,SAASG,SAASA,CAACC,gBAAgC,EAAE;EAC1D,MAAMC,OAAO,GAAG,IAAIC,yBAAS,CAACF,gBAAgB,CAAC;EAC/C,OAAOC,OAAO;AAChB","ignoreList":[]}
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,9 @@
1
+ import RateLimit from "express-rate-limit";
2
+ //#region src/middlewares/rate-limit.ts
3
+ function rateLimit(rateLimitOptions) {
4
+ return new RateLimit(rateLimitOptions);
5
+ }
6
+ //#endregion
7
+ export { rateLimit };
8
+
9
+ //# sourceMappingURL=rate-limit.mjs.map
@@ -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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
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
- const requestOptions = {
12
- // FIXME: decide if host should contain port or not
13
- //
14
- // Express 4:
15
- // - req.host is marked as deprecated since it does not include the port
16
- // - use req.headers['host'] instead, which includes the port
17
- // Express 5:
18
- // - req.host is fully supported and includes the port
19
- // - https://expressjs.com/en/api.html#req.host
20
- host: req.host,
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":["_debug","_interopRequireDefault","require","e","__esModule","default","debug","buildDebug","getRequestOptions","req","requestOptions","host","protocol","headers","remoteAddress","socket","byPassCache","query","write","username","remote_user","name","undefined"],"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":";;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAA+B,SAAAD,uBAAAE,CAAA,WAAAA,CAAA,IAAAA,CAAA,CAAAC,UAAA,GAAAD,CAAA,KAAAE,OAAA,EAAAF,CAAA;AAO/B,MAAMG,KAAK,GAAG,IAAAC,cAAU,EAAC,sCAAsC,CAAC;AAEzD,SAASC,iBAAiBA,CAACC,GAAmB,EAAkB;EACrE,MAAMC,cAAc,GAAG;IACrB;IACA;IACA;IACA;IACA;IACA;IACA;IACA;IACAC,IAAI,EAAEF,GAAG,CAACE,IAAI;IACdC,QAAQ,EAAEH,GAAG,CAACG,QAAQ;IACtBC,OAAO,EAAEJ,GAAG,CAACI,OAA8B;IAC3CC,aAAa,EAAEL,GAAG,CAACM,MAAM,CAACD,aAAa;IACvCE,WAAW,EAAEP,GAAG,CAACQ,KAAK,CAACC,KAAK,KAAK,MAAM;IACvCC,QAAQ,EAAEV,GAAG,CAACW,WAAW,EAAEC,IAAI,IAAIC;EACrC,CAAC;EAEDhB,KAAK,CAAC,qBAAqB,EAAEI,cAAc,CAAC;EAE5C,OAAOA,cAAc;AACvB","ignoreList":[]}
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
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.enforceGeneratedTokenMetadata = enforceGeneratedTokenMetadata;
7
- var _core = require("@verdaccio/core");
8
- const WRITE_METHODS = new Set(['DELETE', 'PATCH', 'POST', 'PUT']);
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
- * Resolve the client address of an incoming request for CIDR matching.
17
- *
18
- * Uses Express' `req.ip`, which already honors the application's `trust proxy`
19
- * setting (`config.server.trustProxy`): when the operator has declared trusted
20
- * proxies, `req.ip` is the upstream-most untrusted address parsed from
21
- * `X-Forwarded-For`; otherwise it is the direct socket peer and the forwarded
22
- * header is ignored entirely.
23
- *
24
- * The middleware must NOT read `X-Forwarded-For` on its own — doing so
25
- * unconditionally would let any client spoof its address (and bypass a token's
26
- * CIDR whitelist) simply by sending the header. Falls back to the raw socket
27
- * address and is normalized (trimmed, IPv4-mapped IPv6 prefix stripped) via
28
- * {@link ipUtils.normalizeAddress}.
29
- *
30
- * @param req the incoming Express request
31
- * @returns the normalized client address, or `undefined` when none can be determined
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
- return _core.ipUtils.normalizeAddress(req.ip || req.socket.remoteAddress);
28
+ return _verdaccio_core.ipUtils.normalizeAddress(req.ip || req.socket.remoteAddress);
35
29
  }
36
-
37
30
  /**
38
- * Find the stored token whose `key` matches the key carried by the request.
39
- *
40
- * @param tokens the tokens persisted for the authenticated user
41
- * @param tokenKey the key extracted from the presented generated token
42
- * @returns the matching {@link Token}, or `undefined` when it has been revoked / never existed
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
- return tokens.find(({
46
- key
47
- }) => key === tokenKey);
38
+ return tokens.find(({ key }) => key === tokenKey);
48
39
  }
49
-
50
40
  /**
51
- * Express middleware that enforces the metadata of npm-style generated tokens
52
- * (created via `POST /-/npm/v1/tokens`).
53
- *
54
- * A generated token embeds a server-issued `key` that is recovered from the
55
- * verified credentials as `remote_user.token.key`. This middleware looks that
56
- * key up in storage and rejects the request when the token:
57
- * - is missing from storage (revoked or never issued);
58
- * - is used from a client address outside its `cidr` whitelist;
59
- * - is `readonly` and the request uses a write method (`DELETE`/`PATCH`/`POST`/`PUT`).
60
- *
61
- * Requests that do not carry a generated token key (e.g. interactive logins)
62
- * pass through untouched. It must run after the JWT/auth middleware has
63
- * populated `remote_user`. Failures fail closed: a storage lookup error yields
64
- * an internal error rather than allowing the request.
65
- *
66
- * @param storage storage exposing {@link TokenReadableStorage.readTokens} to load the user's tokens
67
- * @param logger logger used to record rejected attempts and lookup failures
68
- * @returns an Express {@link RequestHandler} that calls `next()` to allow or `next(error)` to reject
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
- return async function (req, _res, next) {
72
- const remoteUser = req.remote_user;
73
- const tokenKey = remoteUser?.token?.key;
74
- if (!tokenKey) {
75
- return next();
76
- }
77
- const user = remoteUser?.name;
78
- if (typeof user !== 'string') {
79
- return next(_core.errorUtils.getForbidden(_core.API_ERROR.UNAUTHORIZED_ACCESS));
80
- }
81
- try {
82
- const token = findToken(await storage.readTokens({
83
- user
84
- }), tokenKey);
85
- if (!token) {
86
- logger.warn({
87
- tokenKey,
88
- user
89
- }, 'generated token @{tokenKey} for user @{user} is missing');
90
- return next(_core.errorUtils.getForbidden(_core.API_ERROR.UNAUTHORIZED_ACCESS));
91
- }
92
- if (!_core.ipUtils.isAddressAllowed(getClientAddress(req), token.cidr)) {
93
- logger.warn({
94
- tokenKey,
95
- user
96
- }, 'generated token @{tokenKey} for user @{user} was used outside its CIDR whitelist');
97
- return next(_core.errorUtils.getForbidden(_core.API_ERROR.UNAUTHORIZED_ACCESS));
98
- }
99
- if (token.readonly && WRITE_METHODS.has(req.method)) {
100
- logger.warn({
101
- tokenKey,
102
- user
103
- }, 'readonly generated token @{tokenKey} for user @{user} was used for a write request');
104
- return next(_core.errorUtils.getForbidden(_core.API_ERROR.UNAUTHORIZED_ACCESS));
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