@verdaccio/middleware 6.0.0-6-next.29 → 6.0.0-6-next.31
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/CHANGELOG.md +32 -0
- package/build/index.js +0 -2
- package/build/index.js.map +1 -1
- package/build/middleware-utils.js +0 -1
- package/build/middleware-utils.js.map +1 -1
- package/build/middleware.d.ts +4 -4
- package/build/middleware.js +32 -87
- package/build/middleware.js.map +1 -1
- package/package.json +5 -5
- package/src/middleware.ts +4 -7
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,37 @@
|
|
|
1
1
|
# @verdaccio/middleware
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.31
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @verdaccio/core@6.0.0-6-next.52
|
|
8
|
+
- @verdaccio/auth@6.0.0-6-next.31
|
|
9
|
+
- @verdaccio/logger@6.0.0-6-next.20
|
|
10
|
+
- @verdaccio/utils@6.0.0-6-next.20
|
|
11
|
+
|
|
12
|
+
## 6.0.0-6-next.30
|
|
13
|
+
|
|
14
|
+
### Minor Changes
|
|
15
|
+
|
|
16
|
+
- 4b29d715: chore: move improvements from v5 to v6
|
|
17
|
+
|
|
18
|
+
Migrate improvements form v5 to v6:
|
|
19
|
+
|
|
20
|
+
- https://github.com/verdaccio/verdaccio/pull/3158
|
|
21
|
+
- https://github.com/verdaccio/verdaccio/pull/3151
|
|
22
|
+
- https://github.com/verdaccio/verdaccio/pull/2271
|
|
23
|
+
- https://github.com/verdaccio/verdaccio/pull/2787
|
|
24
|
+
- https://github.com/verdaccio/verdaccio/pull/2791
|
|
25
|
+
- https://github.com/verdaccio/verdaccio/pull/2205
|
|
26
|
+
|
|
27
|
+
### Patch Changes
|
|
28
|
+
|
|
29
|
+
- Updated dependencies [4b29d715]
|
|
30
|
+
- @verdaccio/auth@6.0.0-6-next.30
|
|
31
|
+
- @verdaccio/core@6.0.0-6-next.51
|
|
32
|
+
- @verdaccio/logger@6.0.0-6-next.19
|
|
33
|
+
- @verdaccio/utils@6.0.0-6-next.19
|
|
34
|
+
|
|
3
35
|
## 6.0.0-6-next.29
|
|
4
36
|
|
|
5
37
|
### Patch Changes
|
package/build/index.js
CHANGED
|
@@ -3,9 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
|
|
7
6
|
var _middleware = require("./middleware");
|
|
8
|
-
|
|
9
7
|
Object.keys(_middleware).forEach(function (key) {
|
|
10
8
|
if (key === "default" || key === "__esModule") return;
|
|
11
9
|
if (key in exports && exports[key] === _middleware[key]) return;
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './middleware';\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export * from './middleware';\n"],"mappings":";;;;;AAAA;AAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware-utils.js","names":["getVersionFromTarball","name","groups","match","undefined"],"sources":["../src/middleware-utils.ts"],"sourcesContent":["/**\n * return package version from tarball name\n * @param {String} name\n * @returns {String}\n */\nexport function getVersionFromTarball(name: string): string | void {\n const groups = name.match(/.+-(\\d.+)\\.tgz/);\n\n return groups !== null ? groups[1] : undefined;\n}\n"],"mappings":"
|
|
1
|
+
{"version":3,"file":"middleware-utils.js","names":["getVersionFromTarball","name","groups","match","undefined"],"sources":["../src/middleware-utils.ts"],"sourcesContent":["/**\n * return package version from tarball name\n * @param {String} name\n * @returns {String}\n */\nexport function getVersionFromTarball(name: string): string | void {\n const groups = name.match(/.+-(\\d.+)\\.tgz/);\n\n return groups !== null ? groups[1] : undefined;\n}\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACO,SAASA,qBAAqB,CAACC,IAAY,EAAiB;EACjE,MAAMC,MAAM,GAAGD,IAAI,CAACE,KAAK,CAAC,gBAAgB,CAAC;EAE3C,OAAOD,MAAM,KAAK,IAAI,GAAGA,MAAM,CAAC,CAAC,CAAC,GAAGE,SAAS;AAChD"}
|
package/build/middleware.d.ts
CHANGED
|
@@ -2,14 +2,14 @@ import { NextFunction, Request, Response } from 'express';
|
|
|
2
2
|
import { HttpError } from 'http-errors';
|
|
3
3
|
import { Auth } from '@verdaccio/auth';
|
|
4
4
|
import { Config, Logger, Package, RemoteUser } from '@verdaccio/types';
|
|
5
|
-
export
|
|
5
|
+
export type $RequestExtend = Request & {
|
|
6
6
|
remote_user?: RemoteUser;
|
|
7
7
|
log: Logger;
|
|
8
8
|
};
|
|
9
|
-
export
|
|
9
|
+
export type $ResponseExtend = Response & {
|
|
10
10
|
cookies?: any;
|
|
11
11
|
};
|
|
12
|
-
export
|
|
12
|
+
export type $NextFunctionVer = NextFunction & any;
|
|
13
13
|
export declare function match(regexp: RegExp): any;
|
|
14
14
|
export declare function setSecurityWebHeaders(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void;
|
|
15
15
|
export declare function validateName(req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer, value: string, name: string): void;
|
|
@@ -22,7 +22,7 @@ export declare function allow(auth: Auth): Function;
|
|
|
22
22
|
export interface MiddlewareError {
|
|
23
23
|
error: string;
|
|
24
24
|
}
|
|
25
|
-
export
|
|
25
|
+
export type FinalBody = Package | MiddlewareError | string;
|
|
26
26
|
export declare function final(body: FinalBody, req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void;
|
|
27
27
|
export declare const LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
|
|
28
28
|
export declare const LOG_VERDACCIO_ERROR: string;
|
package/build/middleware.js
CHANGED
|
@@ -17,23 +17,14 @@ exports.media = media;
|
|
|
17
17
|
exports.setSecurityWebHeaders = setSecurityWebHeaders;
|
|
18
18
|
exports.validateName = validateName;
|
|
19
19
|
exports.validatePackage = validatePackage;
|
|
20
|
-
|
|
21
20
|
var _debug = _interopRequireDefault(require("debug"));
|
|
22
|
-
|
|
23
21
|
var _lodash = _interopRequireDefault(require("lodash"));
|
|
24
|
-
|
|
25
22
|
var _core = require("@verdaccio/core");
|
|
26
|
-
|
|
27
23
|
var _logger = require("@verdaccio/logger");
|
|
28
|
-
|
|
29
24
|
var _utils = require("@verdaccio/utils");
|
|
30
|
-
|
|
31
25
|
var _middlewareUtils = require("./middleware-utils");
|
|
32
|
-
|
|
33
26
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
34
|
-
|
|
35
27
|
const debug = (0, _debug.default)('verdaccio:middleware');
|
|
36
|
-
|
|
37
28
|
function match(regexp) {
|
|
38
29
|
return function (req, res, next, value) {
|
|
39
30
|
if (regexp.exec(value)) {
|
|
@@ -42,22 +33,21 @@ function match(regexp) {
|
|
|
42
33
|
next('route');
|
|
43
34
|
}
|
|
44
35
|
};
|
|
45
|
-
}
|
|
46
|
-
// @ts-deprecated
|
|
47
|
-
|
|
36
|
+
}
|
|
48
37
|
|
|
38
|
+
// TODO: remove, was relocated to web package
|
|
39
|
+
// @ts-deprecated
|
|
49
40
|
function setSecurityWebHeaders(req, res, next) {
|
|
50
41
|
// disable loading in frames (clickjacking, etc.)
|
|
51
|
-
res.header(_core.HEADERS.FRAMES_OPTIONS, 'deny');
|
|
52
|
-
|
|
53
|
-
res.header(_core.HEADERS.CSP, "connect-src 'self'");
|
|
54
|
-
|
|
55
|
-
res.header(_core.HEADERS.CTO, 'nosniff');
|
|
56
|
-
|
|
42
|
+
res.header(_core.HEADERS.FRAMES_OPTIONS, 'deny');
|
|
43
|
+
// avoid stablish connections outside of domain
|
|
44
|
+
res.header(_core.HEADERS.CSP, "connect-src 'self'");
|
|
45
|
+
// https://stackoverflow.com/questions/18337630/what-is-x-content-type-options-nosniff
|
|
46
|
+
res.header(_core.HEADERS.CTO, 'nosniff');
|
|
47
|
+
// https://stackoverflow.com/questions/9090577/what-is-the-http-header-x-xss-protection
|
|
57
48
|
res.header(_core.HEADERS.XSS, '1; mode=block');
|
|
58
49
|
next();
|
|
59
50
|
}
|
|
60
|
-
|
|
61
51
|
function validateName(req, res, next, value, name) {
|
|
62
52
|
if (value === '-') {
|
|
63
53
|
// special case in couchdb usually
|
|
@@ -68,7 +58,6 @@ function validateName(req, res, next, value, name) {
|
|
|
68
58
|
next(_core.errorUtils.getForbidden('invalid ' + name));
|
|
69
59
|
}
|
|
70
60
|
}
|
|
71
|
-
|
|
72
61
|
function validatePackage(req, res, next, value, name) {
|
|
73
62
|
if (value === '-') {
|
|
74
63
|
// special case in couchdb usually
|
|
@@ -79,52 +68,43 @@ function validatePackage(req, res, next, value, name) {
|
|
|
79
68
|
next(_core.errorUtils.getForbidden('invalid ' + name));
|
|
80
69
|
}
|
|
81
70
|
}
|
|
82
|
-
|
|
83
71
|
function media(expect) {
|
|
84
72
|
return function (req, res, next) {
|
|
85
73
|
if (req.headers[_core.HEADER_TYPE.CONTENT_TYPE] !== expect) {
|
|
86
|
-
next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNSUPPORTED_MEDIA, 'wrong content-type, expect: ' + expect + ', got: ' + req.
|
|
74
|
+
next(_core.errorUtils.getCode(_core.HTTP_STATUS.UNSUPPORTED_MEDIA, 'wrong content-type, expect: ' + expect + ', got: ' + req.get[_core.HEADER_TYPE.CONTENT_TYPE]));
|
|
87
75
|
} else {
|
|
88
76
|
next();
|
|
89
77
|
}
|
|
90
78
|
};
|
|
91
79
|
}
|
|
92
|
-
|
|
93
80
|
function encodeScopePackage(req, res, next) {
|
|
94
81
|
if (req.url.indexOf('@') !== -1) {
|
|
95
82
|
// e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3
|
|
96
83
|
req.url = req.url.replace(/^(\/@[^\/%]+)\/(?!$)/, '$1%2F');
|
|
97
84
|
}
|
|
98
|
-
|
|
99
85
|
next();
|
|
100
86
|
}
|
|
101
|
-
|
|
102
87
|
function expectJson(req, res, next) {
|
|
103
88
|
if (!(0, _utils.isObject)(req.body)) {
|
|
104
89
|
return next(_core.errorUtils.getBadRequest("can't parse incoming json"));
|
|
105
90
|
}
|
|
106
|
-
|
|
107
91
|
next();
|
|
108
92
|
}
|
|
109
|
-
|
|
110
93
|
function antiLoop(config) {
|
|
111
94
|
return function (req, res, next) {
|
|
112
|
-
|
|
95
|
+
var _req$headers;
|
|
96
|
+
if ((req === null || req === void 0 ? void 0 : (_req$headers = req.headers) === null || _req$headers === void 0 ? void 0 : _req$headers.via) != null) {
|
|
113
97
|
const arr = req.headers.via.split(',');
|
|
114
|
-
|
|
115
98
|
for (let i = 0; i < arr.length; i++) {
|
|
116
99
|
const m = arr[i].match(/\s*(\S+)\s+(\S+)/);
|
|
117
|
-
|
|
118
100
|
if (m && m[2] === config.server_id) {
|
|
119
101
|
return next(_core.errorUtils.getCode(_core.HTTP_STATUS.LOOP_DETECTED, 'loop detected'));
|
|
120
102
|
}
|
|
121
103
|
}
|
|
122
104
|
}
|
|
123
|
-
|
|
124
105
|
next();
|
|
125
106
|
};
|
|
126
107
|
}
|
|
127
|
-
|
|
128
108
|
function allow(auth) {
|
|
129
109
|
return function (action) {
|
|
130
110
|
return function (req, res, next) {
|
|
@@ -132,18 +112,15 @@ function allow(auth) {
|
|
|
132
112
|
const packageName = req.params.scope ? `@${req.params.scope}/${req.params.package}` : req.params.package;
|
|
133
113
|
const packageVersion = req.params.filename ? (0, _middlewareUtils.getVersionFromTarball)(req.params.filename) : undefined;
|
|
134
114
|
const remote = req.remote_user;
|
|
135
|
-
|
|
136
115
|
_logger.logger.trace({
|
|
137
116
|
action,
|
|
138
117
|
user: remote === null || remote === void 0 ? void 0 : remote.name
|
|
139
118
|
}, `[middleware/allow][@{action}] allow for @{user}`);
|
|
140
|
-
|
|
141
119
|
auth['allow_' + action]({
|
|
142
120
|
packageName,
|
|
143
121
|
packageVersion
|
|
144
122
|
}, remote, function (error, allowed) {
|
|
145
123
|
req.resume();
|
|
146
|
-
|
|
147
124
|
if (error) {
|
|
148
125
|
next(error);
|
|
149
126
|
} else if (allowed) {
|
|
@@ -157,34 +134,34 @@ function allow(auth) {
|
|
|
157
134
|
};
|
|
158
135
|
};
|
|
159
136
|
}
|
|
160
|
-
|
|
161
|
-
|
|
137
|
+
function final(body, req, res,
|
|
138
|
+
// if we remove `next` breaks test
|
|
162
139
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
163
140
|
next) {
|
|
164
141
|
if (res.statusCode === _core.HTTP_STATUS.UNAUTHORIZED && !res.getHeader(_core.HEADERS.WWW_AUTH)) {
|
|
165
142
|
// they say it's required for 401, so...
|
|
166
143
|
res.header(_core.HEADERS.WWW_AUTH, `${_core.TOKEN_BASIC}, ${_core.TOKEN_BEARER}`);
|
|
167
144
|
}
|
|
168
|
-
|
|
169
145
|
try {
|
|
170
146
|
if (_lodash.default.isString(body) || _lodash.default.isObject(body)) {
|
|
171
147
|
if (!res.getHeader(_core.HEADERS.CONTENT_TYPE)) {
|
|
172
148
|
res.header(_core.HEADERS.CONTENT_TYPE, _core.HEADERS.JSON);
|
|
173
149
|
}
|
|
174
|
-
|
|
175
150
|
if (typeof body === 'object' && _lodash.default.isNil(body) === false) {
|
|
176
151
|
if (typeof body.error === 'string') {
|
|
177
|
-
res.locals._verdaccio_error = body.error;
|
|
152
|
+
res.locals._verdaccio_error = body.error;
|
|
153
|
+
// res._verdaccio_error = (body as MiddlewareError).error;
|
|
178
154
|
}
|
|
179
155
|
|
|
180
156
|
body = JSON.stringify(body, undefined, ' ') + '\n';
|
|
181
|
-
}
|
|
182
|
-
|
|
157
|
+
}
|
|
183
158
|
|
|
159
|
+
// don't send etags with errors
|
|
184
160
|
if (!res.statusCode || res.statusCode >= _core.HTTP_STATUS.OK && res.statusCode < _core.HTTP_STATUS.MULTIPLE_CHOICES) {
|
|
185
161
|
res.header(_core.HEADERS.ETAG, '"' + (0, _utils.stringToMD5)(body) + '"');
|
|
186
162
|
}
|
|
187
|
-
} else {
|
|
163
|
+
} else {
|
|
164
|
+
// send(null), send(204), etc.
|
|
188
165
|
}
|
|
189
166
|
} catch (err) {
|
|
190
167
|
// if verdaccio sends headers first, and then calls res.send()
|
|
@@ -193,87 +170,71 @@ next) {
|
|
|
193
170
|
if (err.message.match(/set headers after they are sent/)) {
|
|
194
171
|
if (_lodash.default.isNil(res.socket) === false) {
|
|
195
172
|
var _res$socket;
|
|
196
|
-
|
|
197
173
|
(_res$socket = res.socket) === null || _res$socket === void 0 ? void 0 : _res$socket.destroy();
|
|
198
174
|
}
|
|
199
|
-
|
|
200
175
|
return;
|
|
201
176
|
}
|
|
202
|
-
|
|
203
177
|
throw err;
|
|
204
178
|
}
|
|
205
|
-
|
|
206
179
|
res.send(body);
|
|
207
|
-
}
|
|
208
|
-
|
|
180
|
+
}
|
|
209
181
|
|
|
182
|
+
// FIXME: deprecated, moved to @verdaccio/dev-commons
|
|
210
183
|
const LOG_STATUS_MESSAGE = "@{status}, user: @{user}(@{remoteIP}), req: '@{request.method} @{request.url}'";
|
|
211
184
|
exports.LOG_STATUS_MESSAGE = LOG_STATUS_MESSAGE;
|
|
212
185
|
const LOG_VERDACCIO_ERROR = `${LOG_STATUS_MESSAGE}, error: @{!error}`;
|
|
213
186
|
exports.LOG_VERDACCIO_ERROR = LOG_VERDACCIO_ERROR;
|
|
214
187
|
const LOG_VERDACCIO_BYTES = `${LOG_STATUS_MESSAGE}, bytes: @{bytes.in}/@{bytes.out}`;
|
|
215
188
|
exports.LOG_VERDACCIO_BYTES = LOG_VERDACCIO_BYTES;
|
|
216
|
-
|
|
217
189
|
function log(req, res, next) {
|
|
218
190
|
// logger
|
|
219
191
|
req.log = _logger.logger.child({
|
|
220
192
|
sub: 'in'
|
|
221
193
|
});
|
|
222
194
|
const _auth = req.headers.authorization;
|
|
223
|
-
|
|
224
195
|
if (_lodash.default.isNil(_auth) === false) {
|
|
225
196
|
req.headers.authorization = '<Classified>';
|
|
226
197
|
}
|
|
227
|
-
|
|
228
|
-
const _cookie = req.headers.cookie;
|
|
229
|
-
|
|
198
|
+
const _cookie = req.get('cookie');
|
|
230
199
|
if (_lodash.default.isNil(_cookie) === false) {
|
|
231
200
|
req.headers.cookie = '<Classified>';
|
|
232
201
|
}
|
|
233
|
-
|
|
234
202
|
req.url = req.originalUrl;
|
|
235
203
|
req.log.info({
|
|
236
204
|
req: req,
|
|
237
205
|
ip: req.ip
|
|
238
206
|
}, "@{ip} requested '@{req.method} @{req.url}'");
|
|
239
207
|
req.originalUrl = req.url;
|
|
240
|
-
|
|
241
208
|
if (_lodash.default.isNil(_auth) === false) {
|
|
242
209
|
req.headers.authorization = _auth;
|
|
243
210
|
}
|
|
244
|
-
|
|
245
211
|
if (_lodash.default.isNil(_cookie) === false) {
|
|
246
212
|
req.headers.cookie = _cookie;
|
|
247
213
|
}
|
|
248
|
-
|
|
249
214
|
let bytesin = 0;
|
|
250
215
|
req.on('data', function (chunk) {
|
|
251
216
|
bytesin += chunk.length;
|
|
252
217
|
});
|
|
253
218
|
let bytesout = 0;
|
|
254
|
-
const _write = res.write;
|
|
219
|
+
const _write = res.write;
|
|
220
|
+
// FIXME: res.write should return boolean
|
|
255
221
|
// @ts-ignore
|
|
256
|
-
|
|
257
222
|
res.write = function (buf) {
|
|
258
223
|
bytesout += buf.length;
|
|
259
224
|
/* eslint prefer-rest-params: "off" */
|
|
260
225
|
// @ts-ignore
|
|
261
|
-
|
|
262
226
|
_write.apply(res, arguments);
|
|
263
227
|
};
|
|
264
|
-
|
|
265
228
|
const log = function () {
|
|
266
|
-
const forwardedFor = req.
|
|
229
|
+
const forwardedFor = req.get('x-forwarded-for');
|
|
267
230
|
const remoteAddress = req.connection.remoteAddress;
|
|
268
231
|
const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;
|
|
269
232
|
let message;
|
|
270
|
-
|
|
271
233
|
if (res.locals._verdaccio_error) {
|
|
272
234
|
message = LOG_VERDACCIO_ERROR;
|
|
273
235
|
} else {
|
|
274
236
|
message = LOG_VERDACCIO_BYTES;
|
|
275
237
|
}
|
|
276
|
-
|
|
277
238
|
req.url = req.originalUrl;
|
|
278
239
|
req.log.http({
|
|
279
240
|
request: {
|
|
@@ -291,45 +252,35 @@ function log(req, res, next) {
|
|
|
291
252
|
}, message);
|
|
292
253
|
req.originalUrl = req.url;
|
|
293
254
|
};
|
|
294
|
-
|
|
295
255
|
req.on('close', function () {
|
|
296
256
|
log();
|
|
297
257
|
});
|
|
298
|
-
const _end = res.end;
|
|
299
|
-
|
|
258
|
+
const _end = res.end;
|
|
259
|
+
// @ts-ignore
|
|
300
260
|
res.end = function (buf) {
|
|
301
261
|
if (buf) {
|
|
302
262
|
bytesout += buf.length;
|
|
303
263
|
}
|
|
304
264
|
/* eslint prefer-rest-params: "off" */
|
|
305
265
|
// @ts-ignore
|
|
306
|
-
|
|
307
|
-
|
|
308
266
|
_end.apply(res, arguments);
|
|
309
|
-
|
|
310
267
|
log();
|
|
311
268
|
};
|
|
312
|
-
|
|
313
269
|
next();
|
|
314
270
|
}
|
|
315
|
-
|
|
316
271
|
function handleError(err, req, res, next) {
|
|
317
272
|
debug('error handler init');
|
|
318
|
-
|
|
319
273
|
if (_lodash.default.isError(err)) {
|
|
320
274
|
debug('is native error');
|
|
321
|
-
|
|
322
275
|
if (err.code === 'ECONNABORT' && res.statusCode === _core.HTTP_STATUS.NOT_MODIFIED) {
|
|
323
276
|
return next();
|
|
324
277
|
}
|
|
325
|
-
|
|
326
278
|
if (_lodash.default.isFunction(res.locals.report_error) === false) {
|
|
327
|
-
debug('is locals error report ref');
|
|
279
|
+
debug('is locals error report ref');
|
|
280
|
+
// in case of very early error this middleware may not be loaded before error is generated
|
|
328
281
|
// fixing that
|
|
329
|
-
|
|
330
282
|
errorReportingMiddleware(req, res, _lodash.default.noop);
|
|
331
283
|
}
|
|
332
|
-
|
|
333
284
|
debug('set locals error report ref');
|
|
334
285
|
res.locals.report_error(err);
|
|
335
286
|
} else {
|
|
@@ -337,16 +288,14 @@ function handleError(err, req, res, next) {
|
|
|
337
288
|
debug('no error to report, jump next layer');
|
|
338
289
|
return next(err);
|
|
339
290
|
}
|
|
340
|
-
}
|
|
341
|
-
|
|
291
|
+
}
|
|
342
292
|
|
|
293
|
+
// Middleware
|
|
343
294
|
function errorReportingMiddleware(req, res, next) {
|
|
344
295
|
debug('error report middleware');
|
|
345
|
-
|
|
346
296
|
res.locals.report_error = res.locals.report_error || function (err) {
|
|
347
297
|
if (err.status && err.status >= _core.HTTP_STATUS.BAD_REQUEST && err.status < 600) {
|
|
348
298
|
debug('is error > 409 %o', err === null || err === void 0 ? void 0 : err.status);
|
|
349
|
-
|
|
350
299
|
if (_lodash.default.isNil(res.headersSent) === false) {
|
|
351
300
|
debug('send status %o', err === null || err === void 0 ? void 0 : err.status);
|
|
352
301
|
res.status(err.status);
|
|
@@ -357,15 +306,12 @@ function errorReportingMiddleware(req, res, next) {
|
|
|
357
306
|
}
|
|
358
307
|
} else {
|
|
359
308
|
debug('is error < 409 %o', err === null || err === void 0 ? void 0 : err.status);
|
|
360
|
-
|
|
361
309
|
_logger.logger.error({
|
|
362
310
|
err: err
|
|
363
311
|
}, 'unexpected error: @{!err.message}\n@{err.stack}');
|
|
364
|
-
|
|
365
312
|
if (!res.status || !res.send) {
|
|
366
313
|
// TODO: decide which debug keep
|
|
367
314
|
_logger.logger.error('this is an error in express.js, please report this');
|
|
368
|
-
|
|
369
315
|
debug('this is an error in express.js, please report this, destroy response %o', err);
|
|
370
316
|
res.destroy();
|
|
371
317
|
} else if (!res.headersSent) {
|
|
@@ -380,7 +326,6 @@ function errorReportingMiddleware(req, res, next) {
|
|
|
380
326
|
}
|
|
381
327
|
}
|
|
382
328
|
};
|
|
383
|
-
|
|
384
329
|
debug('error report middleware next()');
|
|
385
330
|
next();
|
|
386
331
|
}
|
package/build/middleware.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"middleware.js","names":["debug","buildDebug","match","regexp","req","res","next","value","exec","setSecurityWebHeaders","header","HEADERS","FRAMES_OPTIONS","CSP","CTO","XSS","validateName","name","utilValidateName","errorUtils","getForbidden","validatePackage","utilValidatePackage","media","expect","headers","HEADER_TYPE","CONTENT_TYPE","getCode","HTTP_STATUS","UNSUPPORTED_MEDIA","encodeScopePackage","url","indexOf","replace","expectJson","isObject","body","getBadRequest","antiLoop","config","via","arr","split","i","length","m","server_id","LOOP_DETECTED","allow","auth","action","pause","packageName","params","scope","package","packageVersion","filename","getVersionFromTarball","undefined","remote","remote_user","logger","trace","user","error","allowed","resume","getInternalError","API_ERROR","PLUGIN_ERROR","final","statusCode","UNAUTHORIZED","getHeader","WWW_AUTH","TOKEN_BASIC","TOKEN_BEARER","_","isString","JSON","isNil","locals","_verdaccio_error","stringify","OK","MULTIPLE_CHOICES","ETAG","stringToMD5","err","message","socket","destroy","send","LOG_STATUS_MESSAGE","LOG_VERDACCIO_ERROR","LOG_VERDACCIO_BYTES","log","child","sub","_auth","authorization","_cookie","cookie","originalUrl","info","ip","bytesin","on","chunk","bytesout","_write","write","buf","apply","arguments","forwardedFor","remoteAddress","connection","remoteIP","http","request","method","status","bytes","in","out","_end","end","handleError","isError","code","NOT_MODIFIED","isFunction","report_error","errorReportingMiddleware","noop","BAD_REQUEST","headersSent","UNKNOWN_ERROR","INTERNAL_ERROR","INTERNAL_SERVER_ERROR"],"sources":["../src/middleware.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { NextFunction, Request, Response } from 'express';\nimport { HttpError } from 'http-errors';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n API_ERROR,\n HEADERS,\n HEADER_TYPE,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n VerdaccioError,\n errorUtils,\n} from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Config, Logger, Package, RemoteUser } from '@verdaccio/types';\nimport {\n isObject,\n stringToMD5,\n validateName as utilValidateName,\n validatePackage as utilValidatePackage,\n} from '@verdaccio/utils';\n\nimport { getVersionFromTarball } from './middleware-utils';\n\nexport type $RequestExtend = Request & { remote_user?: RemoteUser; log: Logger };\nexport type $ResponseExtend = Response & { cookies?: any };\nexport type $NextFunctionVer = NextFunction & any;\n\nconst debug = buildDebug('verdaccio:middleware');\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\n// TODO: remove, was relocated to web package\n// @ts-deprecated\nexport function setSecurityWebHeaders(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n // disable loading in frames (clickjacking, etc.)\n res.header(HEADERS.FRAMES_OPTIONS, 'deny');\n // avoid stablish connections outside of domain\n res.header(HEADERS.CSP, \"connect-src 'self'\");\n // https://stackoverflow.com/questions/18337630/what-is-x-content-type-options-nosniff\n res.header(HEADERS.CTO, 'nosniff');\n // https://stackoverflow.com/questions/9090577/what-is-the-http-header-x-xss-protection\n res.header(HEADERS.XSS, '1; mode=block');\n next();\n}\n\nexport function validateName(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string,\n name: string\n): void {\n if (value === '-') {\n // special case in couchdb usually\n next('route');\n } else if (utilValidateName(value)) {\n next();\n } else {\n next(errorUtils.getForbidden('invalid ' + name));\n }\n}\n\nexport function validatePackage(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string,\n name: string\n): void {\n if (value === '-') {\n // special case in couchdb usually\n next('route');\n } else if (utilValidatePackage(value)) {\n next();\n } else {\n next(errorUtils.getForbidden('invalid ' + name));\n }\n}\n\nexport function media(expect: string | null): any {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n if (req.headers[HEADER_TYPE.CONTENT_TYPE] !== expect) {\n next(\n errorUtils.getCode(\n HTTP_STATUS.UNSUPPORTED_MEDIA,\n 'wrong content-type, expect: ' +\n expect +\n ', got: ' +\n req.headers[HEADER_TYPE.CONTENT_TYPE]\n )\n );\n } else {\n next();\n }\n };\n}\n\nexport function encodeScopePackage(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n if (req.url.indexOf('@') !== -1) {\n // e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3\n req.url = req.url.replace(/^(\\/@[^\\/%]+)\\/(?!$)/, '$1%2F');\n }\n next();\n}\n\nexport function expectJson(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n if (!isObject(req.body)) {\n return next(errorUtils.getBadRequest(\"can't parse incoming json\"));\n }\n next();\n}\n\nexport function antiLoop(config: Config): Function {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n if (req.headers.via != null) {\n const arr = req.headers.via.split(',');\n\n for (let i = 0; i < arr.length; i++) {\n const m = arr[i].match(/\\s*(\\S+)\\s+(\\S+)/);\n if (m && m[2] === config.server_id) {\n return next(errorUtils.getCode(HTTP_STATUS.LOOP_DETECTED, 'loop detected'));\n }\n }\n }\n next();\n };\n}\n\nexport function allow(auth: Auth): Function {\n return function (action: string): Function {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n req.pause();\n const packageName = req.params.scope\n ? `@${req.params.scope}/${req.params.package}`\n : req.params.package;\n const packageVersion = req.params.filename\n ? getVersionFromTarball(req.params.filename)\n : undefined;\n const remote = req.remote_user;\n logger.trace(\n { action, user: remote?.name },\n `[middleware/allow][@{action}] allow for @{user}`\n );\n auth['allow_' + action](\n { packageName, packageVersion },\n remote,\n function (error, allowed): void {\n req.resume();\n if (error) {\n next(error);\n } else if (allowed) {\n next();\n } else {\n // last plugin (that's our built-in one) returns either\n // cb(err) or cb(null, true), so this should never happen\n throw errorUtils.getInternalError(API_ERROR.PLUGIN_ERROR);\n }\n }\n );\n };\n };\n}\n\nexport interface MiddlewareError {\n error: string;\n}\n\nexport type FinalBody = Package | MiddlewareError | string;\n\nexport function final(\n body: FinalBody,\n req: $RequestExtend,\n res: $ResponseExtend,\n // if we remove `next` breaks test\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n next: $NextFunctionVer\n): void {\n if (res.statusCode === HTTP_STATUS.UNAUTHORIZED && !res.getHeader(HEADERS.WWW_AUTH)) {\n // they say it's required for 401, so...\n res.header(HEADERS.WWW_AUTH, `${TOKEN_BASIC}, ${TOKEN_BEARER}`);\n }\n\n try {\n if (_.isString(body) || _.isObject(body)) {\n if (!res.getHeader(HEADERS.CONTENT_TYPE)) {\n res.header(HEADERS.CONTENT_TYPE, HEADERS.JSON);\n }\n\n if (typeof body === 'object' && _.isNil(body) === false) {\n if (typeof (body as MiddlewareError).error === 'string') {\n res.locals._verdaccio_error = (body as MiddlewareError).error;\n // res._verdaccio_error = (body as MiddlewareError).error;\n }\n body = JSON.stringify(body, undefined, ' ') + '\\n';\n }\n\n // don't send etags with errors\n if (\n !res.statusCode ||\n (res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)\n ) {\n res.header(HEADERS.ETAG, '\"' + stringToMD5(body as string) + '\"');\n }\n } else {\n // send(null), send(204), etc.\n }\n } catch (err: any) {\n // if verdaccio sends headers first, and then calls res.send()\n // as an error handler, we can't report error properly,\n // and should just close socket\n if (err.message.match(/set headers after they are sent/)) {\n if (_.isNil(res.socket) === false) {\n res.socket?.destroy();\n }\n return;\n }\n throw err;\n }\n\n res.send(body);\n}\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 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.headers.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 /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _write.apply(res, arguments);\n };\n\n const log = function (): void {\n const forwardedFor = req.headers['x-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 && 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 /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _end.apply(res, arguments);\n log();\n };\n next();\n}\n\nexport function handleError(\n err: HttpError,\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n) {\n debug('error handler init');\n if (_.isError(err)) {\n debug('is native error');\n if (err.code === 'ECONNABORT' && res.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n return next();\n }\n if (_.isFunction(res.locals.report_error) === false) {\n debug('is locals error report ref');\n // in case of very early error this middleware may not be loaded before error is generated\n // fixing that\n errorReportingMiddleware(req, res, _.noop);\n }\n debug('set locals error report ref');\n res.locals.report_error(err);\n } else {\n // Fall to Middleware.final\n debug('no error to report, jump next layer');\n return next(err);\n }\n}\n\n// Middleware\nexport function errorReportingMiddleware(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n debug('error report middleware');\n res.locals.report_error =\n res.locals.report_error ||\n function (err: VerdaccioError): void {\n if (err.status && err.status >= HTTP_STATUS.BAD_REQUEST && err.status < 600) {\n debug('is error > 409 %o', err?.status);\n if (_.isNil(res.headersSent) === false) {\n debug('send status %o', err?.status);\n res.status(err.status);\n debug('next layer %o', err?.message);\n next({ error: err.message || API_ERROR.UNKNOWN_ERROR });\n }\n } else {\n debug('is error < 409 %o', err?.status);\n logger.error({ err: err }, 'unexpected error: @{!err.message}\\n@{err.stack}');\n if (!res.status || !res.send) {\n // TODO: decide which debug keep\n logger.error('this is an error in express.js, please report this');\n debug('this is an error in express.js, please report this, destroy response %o', err);\n res.destroy();\n } else if (!res.headersSent) {\n debug('report internal error %o', err);\n res.status(HTTP_STATUS.INTERNAL_ERROR);\n next({ error: API_ERROR.INTERNAL_SERVER_ERROR });\n } else {\n // socket should be already closed\n debug('this should not happen, otherwise report %o', err);\n }\n }\n };\n\n debug('error report middleware next()');\n next();\n}\n"],"mappings":";;;;;;;;;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,MAKO,IAAI,CAACxF,GAAG,CAACsI,WAAT,EAAsB;QAC3B3I,KAAK,CAAC,0BAAD,EAA6B0F,GAA7B,CAAL;QACArF,GAAG,CAACuH,MAAJ,CAAW/F,iBAAA,CAAYgH,cAAvB;QACAvI,IAAI,CAAC;UAAE4D,KAAK,EAAEI,eAAA,CAAUwE;QAAnB,CAAD,CAAJ;MACD,CAJM,MAIA;QACL;QACA9I,KAAK,CAAC,6CAAD,EAAgD0F,GAAhD,CAAL;MACD;IACF;EACF,CA5BH;;EA8BA1F,KAAK,CAAC,gCAAD,CAAL;EACAM,IAAI;AACL"}
|
|
1
|
+
{"version":3,"file":"middleware.js","names":["debug","buildDebug","match","regexp","req","res","next","value","exec","setSecurityWebHeaders","header","HEADERS","FRAMES_OPTIONS","CSP","CTO","XSS","validateName","name","utilValidateName","errorUtils","getForbidden","validatePackage","utilValidatePackage","media","expect","headers","HEADER_TYPE","CONTENT_TYPE","getCode","HTTP_STATUS","UNSUPPORTED_MEDIA","get","encodeScopePackage","url","indexOf","replace","expectJson","isObject","body","getBadRequest","antiLoop","config","via","arr","split","i","length","m","server_id","LOOP_DETECTED","allow","auth","action","pause","packageName","params","scope","package","packageVersion","filename","getVersionFromTarball","undefined","remote","remote_user","logger","trace","user","error","allowed","resume","getInternalError","API_ERROR","PLUGIN_ERROR","final","statusCode","UNAUTHORIZED","getHeader","WWW_AUTH","TOKEN_BASIC","TOKEN_BEARER","_","isString","JSON","isNil","locals","_verdaccio_error","stringify","OK","MULTIPLE_CHOICES","ETAG","stringToMD5","err","message","socket","destroy","send","LOG_STATUS_MESSAGE","LOG_VERDACCIO_ERROR","LOG_VERDACCIO_BYTES","log","child","sub","_auth","authorization","_cookie","cookie","originalUrl","info","ip","bytesin","on","chunk","bytesout","_write","write","buf","apply","arguments","forwardedFor","remoteAddress","connection","remoteIP","http","request","method","status","bytes","in","out","_end","end","handleError","isError","code","NOT_MODIFIED","isFunction","report_error","errorReportingMiddleware","noop","BAD_REQUEST","headersSent","UNKNOWN_ERROR","INTERNAL_ERROR","INTERNAL_SERVER_ERROR"],"sources":["../src/middleware.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { NextFunction, Request, Response } from 'express';\nimport { HttpError } from 'http-errors';\nimport _ from 'lodash';\n\nimport { Auth } from '@verdaccio/auth';\nimport {\n API_ERROR,\n HEADERS,\n HEADER_TYPE,\n HTTP_STATUS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n VerdaccioError,\n errorUtils,\n} from '@verdaccio/core';\nimport { logger } from '@verdaccio/logger';\nimport { Config, Logger, Package, RemoteUser } from '@verdaccio/types';\nimport {\n isObject,\n stringToMD5,\n validateName as utilValidateName,\n validatePackage as utilValidatePackage,\n} from '@verdaccio/utils';\n\nimport { getVersionFromTarball } from './middleware-utils';\n\nexport type $RequestExtend = Request & { remote_user?: RemoteUser; log: Logger };\nexport type $ResponseExtend = Response & { cookies?: any };\nexport type $NextFunctionVer = NextFunction & any;\n\nconst debug = buildDebug('verdaccio:middleware');\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\n// TODO: remove, was relocated to web package\n// @ts-deprecated\nexport function setSecurityWebHeaders(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n // disable loading in frames (clickjacking, etc.)\n res.header(HEADERS.FRAMES_OPTIONS, 'deny');\n // avoid stablish connections outside of domain\n res.header(HEADERS.CSP, \"connect-src 'self'\");\n // https://stackoverflow.com/questions/18337630/what-is-x-content-type-options-nosniff\n res.header(HEADERS.CTO, 'nosniff');\n // https://stackoverflow.com/questions/9090577/what-is-the-http-header-x-xss-protection\n res.header(HEADERS.XSS, '1; mode=block');\n next();\n}\n\nexport function validateName(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string,\n name: string\n): void {\n if (value === '-') {\n // special case in couchdb usually\n next('route');\n } else if (utilValidateName(value)) {\n next();\n } else {\n next(errorUtils.getForbidden('invalid ' + name));\n }\n}\n\nexport function validatePackage(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer,\n value: string,\n name: string\n): void {\n if (value === '-') {\n // special case in couchdb usually\n next('route');\n } else if (utilValidatePackage(value)) {\n next();\n } else {\n next(errorUtils.getForbidden('invalid ' + name));\n }\n}\n\nexport function media(expect: string | null): any {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n if (req.headers[HEADER_TYPE.CONTENT_TYPE] !== 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\nexport function encodeScopePackage(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n if (req.url.indexOf('@') !== -1) {\n // e.g.: /@org/pkg/1.2.3 -> /@org%2Fpkg/1.2.3, /@org%2Fpkg/1.2.3 -> /@org%2Fpkg/1.2.3\n req.url = req.url.replace(/^(\\/@[^\\/%]+)\\/(?!$)/, '$1%2F');\n }\n next();\n}\n\nexport function expectJson(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n if (!isObject(req.body)) {\n return next(errorUtils.getBadRequest(\"can't parse incoming json\"));\n }\n next();\n}\n\nexport function antiLoop(config: Config): Function {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n if (req?.headers?.via != null) {\n const arr = req.headers.via.split(',');\n\n for (let i = 0; i < arr.length; i++) {\n const m = arr[i].match(/\\s*(\\S+)\\s+(\\S+)/);\n if (m && m[2] === config.server_id) {\n return next(errorUtils.getCode(HTTP_STATUS.LOOP_DETECTED, 'loop detected'));\n }\n }\n }\n next();\n };\n}\n\nexport function allow(auth: Auth): Function {\n return function (action: string): Function {\n return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {\n req.pause();\n const packageName = req.params.scope\n ? `@${req.params.scope}/${req.params.package}`\n : req.params.package;\n const packageVersion = req.params.filename\n ? getVersionFromTarball(req.params.filename)\n : undefined;\n const remote = req.remote_user;\n logger.trace(\n { action, user: remote?.name },\n `[middleware/allow][@{action}] allow for @{user}`\n );\n auth['allow_' + action](\n { packageName, packageVersion },\n remote,\n function (error, allowed): void {\n req.resume();\n if (error) {\n next(error);\n } else if (allowed) {\n next();\n } else {\n // last plugin (that's our built-in one) returns either\n // cb(err) or cb(null, true), so this should never happen\n throw errorUtils.getInternalError(API_ERROR.PLUGIN_ERROR);\n }\n }\n );\n };\n };\n}\n\nexport interface MiddlewareError {\n error: string;\n}\n\nexport type FinalBody = Package | MiddlewareError | string;\n\nexport function final(\n body: FinalBody,\n req: $RequestExtend,\n res: $ResponseExtend,\n // if we remove `next` breaks test\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n next: $NextFunctionVer\n): void {\n if (res.statusCode === HTTP_STATUS.UNAUTHORIZED && !res.getHeader(HEADERS.WWW_AUTH)) {\n // they say it's required for 401, so...\n res.header(HEADERS.WWW_AUTH, `${TOKEN_BASIC}, ${TOKEN_BEARER}`);\n }\n\n try {\n if (_.isString(body) || _.isObject(body)) {\n if (!res.getHeader(HEADERS.CONTENT_TYPE)) {\n res.header(HEADERS.CONTENT_TYPE, HEADERS.JSON);\n }\n\n if (typeof body === 'object' && _.isNil(body) === false) {\n if (typeof (body as MiddlewareError).error === 'string') {\n res.locals._verdaccio_error = (body as MiddlewareError).error;\n // res._verdaccio_error = (body as MiddlewareError).error;\n }\n body = JSON.stringify(body, undefined, ' ') + '\\n';\n }\n\n // don't send etags with errors\n if (\n !res.statusCode ||\n (res.statusCode >= HTTP_STATUS.OK && res.statusCode < HTTP_STATUS.MULTIPLE_CHOICES)\n ) {\n res.header(HEADERS.ETAG, '\"' + stringToMD5(body as string) + '\"');\n }\n } else {\n // send(null), send(204), etc.\n }\n } catch (err: any) {\n // if verdaccio sends headers first, and then calls res.send()\n // as an error handler, we can't report error properly,\n // and should just close socket\n if (err.message.match(/set headers after they are sent/)) {\n if (_.isNil(res.socket) === false) {\n res.socket?.destroy();\n }\n return;\n }\n throw err;\n }\n\n res.send(body);\n}\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 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 /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _write.apply(res, arguments);\n };\n\n const log = function (): void {\n const forwardedFor = req.get('x-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 && 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 /* eslint prefer-rest-params: \"off\" */\n // @ts-ignore\n _end.apply(res, arguments);\n log();\n };\n next();\n}\n\nexport function handleError(\n err: HttpError,\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n) {\n debug('error handler init');\n if (_.isError(err)) {\n debug('is native error');\n if (err.code === 'ECONNABORT' && res.statusCode === HTTP_STATUS.NOT_MODIFIED) {\n return next();\n }\n if (_.isFunction(res.locals.report_error) === false) {\n debug('is locals error report ref');\n // in case of very early error this middleware may not be loaded before error is generated\n // fixing that\n errorReportingMiddleware(req, res, _.noop);\n }\n debug('set locals error report ref');\n res.locals.report_error(err);\n } else {\n // Fall to Middleware.final\n debug('no error to report, jump next layer');\n return next(err);\n }\n}\n\n// Middleware\nexport function errorReportingMiddleware(\n req: $RequestExtend,\n res: $ResponseExtend,\n next: $NextFunctionVer\n): void {\n debug('error report middleware');\n res.locals.report_error =\n res.locals.report_error ||\n function (err: VerdaccioError): void {\n if (err.status && err.status >= HTTP_STATUS.BAD_REQUEST && err.status < 600) {\n debug('is error > 409 %o', err?.status);\n if (_.isNil(res.headersSent) === false) {\n debug('send status %o', err?.status);\n res.status(err.status);\n debug('next layer %o', err?.message);\n next({ error: err.message || API_ERROR.UNKNOWN_ERROR });\n }\n } else {\n debug('is error < 409 %o', err?.status);\n logger.error({ err: err }, 'unexpected error: @{!err.message}\\n@{err.stack}');\n if (!res.status || !res.send) {\n // TODO: decide which debug keep\n logger.error('this is an error in express.js, please report this');\n debug('this is an error in express.js, please report this, destroy response %o', err);\n res.destroy();\n } else if (!res.headersSent) {\n debug('report internal error %o', err);\n res.status(HTTP_STATUS.INTERNAL_ERROR);\n next({ error: API_ERROR.INTERNAL_SERVER_ERROR });\n } else {\n // socket should be already closed\n debug('this should not happen, otherwise report %o', err);\n }\n }\n };\n\n debug('error report middleware next()');\n next();\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAGA;AAGA;AAUA;AAEA;AAOA;AAA2D;AAM3D,MAAMA,KAAK,GAAG,IAAAC,cAAU,EAAC,sBAAsB,CAAC;AAEzC,SAASC,KAAK,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,EAAE;IACR,CAAC,MAAM;MACLA,IAAI,CAAC,OAAO,CAAC;IACf;EACF,CAAC;AACH;;AAEA;AACA;AACO,SAASG,qBAAqB,CACnCL,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EAChB;EACN;EACAD,GAAG,CAACK,MAAM,CAACC,aAAO,CAACC,cAAc,EAAE,MAAM,CAAC;EAC1C;EACAP,GAAG,CAACK,MAAM,CAACC,aAAO,CAACE,GAAG,EAAE,oBAAoB,CAAC;EAC7C;EACAR,GAAG,CAACK,MAAM,CAACC,aAAO,CAACG,GAAG,EAAE,SAAS,CAAC;EAClC;EACAT,GAAG,CAACK,MAAM,CAACC,aAAO,CAACI,GAAG,EAAE,eAAe,CAAC;EACxCT,IAAI,EAAE;AACR;AAEO,SAASU,YAAY,CAC1BZ,GAAmB,EACnBC,GAAoB,EACpBC,IAAsB,EACtBC,KAAa,EACbU,IAAY,EACN;EACN,IAAIV,KAAK,KAAK,GAAG,EAAE;IACjB;IACAD,IAAI,CAAC,OAAO,CAAC;EACf,CAAC,MAAM,IAAI,IAAAY,m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EwB,GAAG,EAAEA;MAAI,CAAC,EAAE,iDAAiD,CAAC;MAC7E,IAAI,CAACtF,GAAG,CAACwH,MAAM,IAAI,CAACxH,GAAG,CAAC0F,IAAI,EAAE;QAC5B;QACA/B,cAAM,CAACG,KAAK,CAAC,oDAAoD,CAAC;QAClEnE,KAAK,CAAC,yEAAyE,EAAE2F,GAAG,CAAC;QACrFtF,GAAG,CAACyF,OAAO,EAAE;MACf,CAAC,MAAM,IAAI,CAACzF,GAAG,CAACuI,WAAW,EAAE;QAC3B5I,KAAK,CAAC,0BAA0B,EAAE2F,GAAG,CAAC;QACtCtF,GAAG,CAACwH,MAAM,CAAChG,iBAAW,CAACiH,cAAc,CAAC;QACtCxI,IAAI,CAAC;UAAE6D,KAAK,EAAEI,eAAS,CAACwE;QAAsB,CAAC,CAAC;MAClD,CAAC,MAAM;QACL;QACA/I,KAAK,CAAC,6CAA6C,EAAE2F,GAAG,CAAC;MAC3D;IACF;EACF,CAAC;EAEH3F,KAAK,CAAC,gCAAgC,CAAC;EACvCM,IAAI,EAAE;AACR"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@verdaccio/middleware",
|
|
3
|
-
"version": "6.0.0-6-next.
|
|
3
|
+
"version": "6.0.0-6-next.31",
|
|
4
4
|
"description": "loaders logic",
|
|
5
5
|
"main": "./build/index.js",
|
|
6
6
|
"types": "build/index.d.ts",
|
|
@@ -32,10 +32,10 @@
|
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"debug": "4.3.4",
|
|
34
34
|
"body-parser": "1.20.1",
|
|
35
|
-
"@verdaccio/auth": "6.0.0-6-next.
|
|
36
|
-
"@verdaccio/core": "6.0.0-6-next.
|
|
37
|
-
"@verdaccio/logger": "6.0.0-6-next.
|
|
38
|
-
"@verdaccio/utils": "6.0.0-6-next.
|
|
35
|
+
"@verdaccio/auth": "6.0.0-6-next.31",
|
|
36
|
+
"@verdaccio/core": "6.0.0-6-next.52",
|
|
37
|
+
"@verdaccio/logger": "6.0.0-6-next.20",
|
|
38
|
+
"@verdaccio/utils": "6.0.0-6-next.20",
|
|
39
39
|
"lodash": "4.17.21"
|
|
40
40
|
},
|
|
41
41
|
"funding": {
|
package/src/middleware.ts
CHANGED
|
@@ -104,10 +104,7 @@ export function media(expect: string | null): any {
|
|
|
104
104
|
next(
|
|
105
105
|
errorUtils.getCode(
|
|
106
106
|
HTTP_STATUS.UNSUPPORTED_MEDIA,
|
|
107
|
-
'wrong content-type, expect: ' +
|
|
108
|
-
expect +
|
|
109
|
-
', got: ' +
|
|
110
|
-
req.headers[HEADER_TYPE.CONTENT_TYPE]
|
|
107
|
+
'wrong content-type, expect: ' + expect + ', got: ' + req.get[HEADER_TYPE.CONTENT_TYPE]
|
|
111
108
|
)
|
|
112
109
|
);
|
|
113
110
|
} else {
|
|
@@ -141,7 +138,7 @@ export function expectJson(
|
|
|
141
138
|
|
|
142
139
|
export function antiLoop(config: Config): Function {
|
|
143
140
|
return function (req: $RequestExtend, res: $ResponseExtend, next: $NextFunctionVer): void {
|
|
144
|
-
if (req
|
|
141
|
+
if (req?.headers?.via != null) {
|
|
145
142
|
const arr = req.headers.via.split(',');
|
|
146
143
|
|
|
147
144
|
for (let i = 0; i < arr.length; i++) {
|
|
@@ -264,7 +261,7 @@ export function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFuncti
|
|
|
264
261
|
req.headers.authorization = '<Classified>';
|
|
265
262
|
}
|
|
266
263
|
|
|
267
|
-
const _cookie = req.
|
|
264
|
+
const _cookie = req.get('cookie');
|
|
268
265
|
if (_.isNil(_cookie) === false) {
|
|
269
266
|
req.headers.cookie = '<Classified>';
|
|
270
267
|
}
|
|
@@ -298,7 +295,7 @@ export function log(req: $RequestExtend, res: $ResponseExtend, next: $NextFuncti
|
|
|
298
295
|
};
|
|
299
296
|
|
|
300
297
|
const log = function (): void {
|
|
301
|
-
const forwardedFor = req.
|
|
298
|
+
const forwardedFor = req.get('x-forwarded-for');
|
|
302
299
|
const remoteAddress = req.connection.remoteAddress;
|
|
303
300
|
const remoteIP = forwardedFor ? `${forwardedFor} via ${remoteAddress}` : remoteAddress;
|
|
304
301
|
let message;
|