@verdaccio/auth 6.0.0-6-next.26 → 6.0.0-6-next.28
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 +87 -0
- package/build/auth.d.ts +18 -33
- package/build/auth.js +53 -47
- package/build/auth.js.map +1 -1
- package/build/index.d.ts +1 -1
- package/build/index.js +1 -15
- package/build/index.js.map +1 -1
- package/build/utils.d.ts +10 -5
- package/build/utils.js +8 -2
- package/build/utils.js.map +1 -1
- package/package.json +9 -9
- package/src/auth.ts +117 -126
- package/src/index.ts +1 -1
- package/src/utils.ts +12 -13
- package/test/auth-utils.spec.ts +4 -3
- package/test/auth.spec.ts +65 -30
- package/test/helper/plugin.ts +14 -3
- package/test/partials/plugin/verdaccio-fail/fail.js +11 -0
- package/test/partials/plugin/verdaccio-fail/package.json +5 -0
- package/test/partials/plugin/verdaccio-fail-invalid-method/fail.js +11 -0
- package/test/partials/plugin/verdaccio-fail-invalid-method/package.json +5 -0
- package/test/partials/plugin/verdaccio-passthroug/package.json +5 -0
- package/test/partials/plugin/{authenticate.passthroug.js → verdaccio-passthroug/passthroug.js} +0 -0
- package/test/partials/plugin/verdaccio-success/package.json +5 -0
- package/test/partials/plugin/{authenticate.success.js → verdaccio-success/success.js} +0 -0
- package/tsconfig.build.json +3 -3
- package/tsconfig.json +6 -6
- package/test/partials/plugin/authenticate.fail.js +0 -11
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,92 @@
|
|
|
1
1
|
# @verdaccio/auth
|
|
2
2
|
|
|
3
|
+
## 6.0.0-6-next.28
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @verdaccio/core@6.0.0-6-next.49
|
|
8
|
+
- @verdaccio/config@6.0.0-6-next.49
|
|
9
|
+
- @verdaccio/loaders@6.0.0-6-next.18
|
|
10
|
+
- @verdaccio/logger@6.0.0-6-next.17
|
|
11
|
+
- verdaccio-htpasswd@11.0.0-6-next.19
|
|
12
|
+
- @verdaccio/utils@6.0.0-6-next.17
|
|
13
|
+
|
|
14
|
+
## 6.0.0-6-next.27
|
|
15
|
+
|
|
16
|
+
### Major Changes
|
|
17
|
+
|
|
18
|
+
- 9fc2e796: feat(plugins): improve plugin loader
|
|
19
|
+
|
|
20
|
+
### Changes
|
|
21
|
+
|
|
22
|
+
- Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
|
|
23
|
+
- Avoid config collisions https://github.com/verdaccio/verdaccio/issues/928
|
|
24
|
+
- https://github.com/verdaccio/verdaccio/issues/1394
|
|
25
|
+
- `config.plugins` plugin path validations
|
|
26
|
+
- Updated algorithm for plugin loader.
|
|
27
|
+
- improved documentation (included dev)
|
|
28
|
+
|
|
29
|
+
## Features
|
|
30
|
+
|
|
31
|
+
- Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
|
|
32
|
+
- Custom prefix:
|
|
33
|
+
|
|
34
|
+
```
|
|
35
|
+
// config.yaml
|
|
36
|
+
server:
|
|
37
|
+
pluginPrefix: mycompany
|
|
38
|
+
middleware:
|
|
39
|
+
audit:
|
|
40
|
+
foo: 1
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
This configuration will look up for `mycompany-audit` instead `Verdaccio-audit`.
|
|
44
|
+
|
|
45
|
+
## Breaking Changes
|
|
46
|
+
|
|
47
|
+
### sinopia plugins
|
|
48
|
+
|
|
49
|
+
- `sinopia` fallback support is removed, but can be restored using `pluginPrefix`
|
|
50
|
+
|
|
51
|
+
### plugin filter
|
|
52
|
+
|
|
53
|
+
- method rename `filter_metadata`->`filterMetadata`
|
|
54
|
+
|
|
55
|
+
### Plugin constructor does not merge configs anymore https://github.com/verdaccio/verdaccio/issues/928
|
|
56
|
+
|
|
57
|
+
The plugin receives as first argument `config`, which represents the config of the plugin. Example:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
// config.yaml
|
|
61
|
+
auth:
|
|
62
|
+
plugin:
|
|
63
|
+
foo: 1
|
|
64
|
+
bar: 2
|
|
65
|
+
|
|
66
|
+
export class Plugin<T> {
|
|
67
|
+
public constructor(config: T, options: PluginOptions) {
|
|
68
|
+
console.log(config);
|
|
69
|
+
// {foo:1, bar: 2}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
```
|
|
73
|
+
|
|
74
|
+
### Minor Changes
|
|
75
|
+
|
|
76
|
+
- 62c24b63: feat: add passwordValidationRegex property
|
|
77
|
+
|
|
78
|
+
### Patch Changes
|
|
79
|
+
|
|
80
|
+
- Updated dependencies [43f32687]
|
|
81
|
+
- Updated dependencies [9fc2e796]
|
|
82
|
+
- Updated dependencies [62c24b63]
|
|
83
|
+
- @verdaccio/core@6.0.0-6-next.48
|
|
84
|
+
- @verdaccio/config@6.0.0-6-next.48
|
|
85
|
+
- @verdaccio/loaders@6.0.0-6-next.17
|
|
86
|
+
- verdaccio-htpasswd@11.0.0-6-next.18
|
|
87
|
+
- @verdaccio/utils@6.0.0-6-next.16
|
|
88
|
+
- @verdaccio/logger@6.0.0-6-next.16
|
|
89
|
+
|
|
3
90
|
## 6.0.0-6-next.26
|
|
4
91
|
|
|
5
92
|
### Patch Changes
|
package/build/auth.d.ts
CHANGED
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import { NextFunction, Request, Response } from 'express';
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
config: T & Config;
|
|
5
|
-
authenticate(user: string, password: string, cb: Callback): void;
|
|
6
|
-
invalidateToken?(token: string): Promise<void>;
|
|
7
|
-
changePassword(user: string, password: string, newPassword: string, cb: Callback): void;
|
|
8
|
-
allow_access(pkg: AuthPluginPackage, user: RemoteUser, callback: Callback): void;
|
|
9
|
-
add_user(user: string, password: string, cb: Callback): any;
|
|
10
|
-
}
|
|
1
|
+
import { NextFunction, Request, RequestHandler, Response } from 'express';
|
|
2
|
+
import { VerdaccioError, pluginUtils } from '@verdaccio/core';
|
|
3
|
+
import { Callback, Config, JWTSignOptions, Logger, RemoteUser } from '@verdaccio/types';
|
|
11
4
|
export interface TokenEncryption {
|
|
12
5
|
jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string>;
|
|
13
6
|
aesEncrypt(buf: string): string | void;
|
|
@@ -16,6 +9,10 @@ export interface AESPayload {
|
|
|
16
9
|
user: string;
|
|
17
10
|
password: string;
|
|
18
11
|
}
|
|
12
|
+
export interface IAuthMiddleware {
|
|
13
|
+
apiJWTmiddleware(): $NextFunctionVer;
|
|
14
|
+
webUIJWTmiddleware(): $NextFunctionVer;
|
|
15
|
+
}
|
|
19
16
|
export declare type $RequestExtend = Request & {
|
|
20
17
|
remote_user?: any;
|
|
21
18
|
log: Logger;
|
|
@@ -24,48 +21,36 @@ export declare type $ResponseExtend = Response & {
|
|
|
24
21
|
cookies?: any;
|
|
25
22
|
};
|
|
26
23
|
export declare type $NextFunctionVer = NextFunction & any;
|
|
27
|
-
|
|
28
|
-
apiJWTmiddleware(): $NextFunctionVer;
|
|
29
|
-
webUIJWTmiddleware(): $NextFunctionVer;
|
|
30
|
-
}
|
|
31
|
-
export interface IAuth extends IBasicAuth<Config>, IAuthMiddleware, TokenEncryption {
|
|
32
|
-
config: Config;
|
|
33
|
-
logger: Logger;
|
|
34
|
-
secret: string;
|
|
35
|
-
plugins: any[];
|
|
36
|
-
allow_unpublish(pkg: AuthPluginPackage, user: RemoteUser, callback: Callback): void;
|
|
37
|
-
invalidateToken(token: string): Promise<void>;
|
|
38
|
-
}
|
|
39
|
-
declare class Auth implements IAuth {
|
|
24
|
+
declare class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
|
|
40
25
|
config: Config;
|
|
41
|
-
logger: Logger;
|
|
42
26
|
secret: string;
|
|
43
|
-
plugins:
|
|
27
|
+
plugins: pluginUtils.Auth<Config>[];
|
|
44
28
|
constructor(config: Config);
|
|
29
|
+
init(): Promise<void>;
|
|
45
30
|
private loadDefaultPlugin;
|
|
46
|
-
private
|
|
31
|
+
private loadPlugin;
|
|
47
32
|
private _applyDefaultPlugins;
|
|
48
33
|
changePassword(username: string, password: string, newPassword: string, cb: Callback): void;
|
|
49
34
|
invalidateToken(token: string): Promise<void>;
|
|
50
|
-
authenticate(username: string, password: string, cb:
|
|
51
|
-
add_user(user: string, password: string, cb:
|
|
35
|
+
authenticate(username: string, password: string, cb: (error: VerdaccioError | null, user?: RemoteUser) => void): void;
|
|
36
|
+
add_user(user: string, password: string, cb: (error: VerdaccioError | null, user?: RemoteUser) => void): void;
|
|
52
37
|
/**
|
|
53
38
|
* Allow user to access a package.
|
|
54
39
|
*/
|
|
55
|
-
allow_access({ packageName, packageVersion }: AuthPluginPackage, user: RemoteUser, callback:
|
|
56
|
-
allow_unpublish({ packageName, packageVersion }: AuthPluginPackage, user: RemoteUser, callback: Callback): void;
|
|
40
|
+
allow_access({ packageName, packageVersion }: pluginUtils.AuthPluginPackage, user: RemoteUser, callback: pluginUtils.AccessCallback): void;
|
|
41
|
+
allow_unpublish({ packageName, packageVersion }: pluginUtils.AuthPluginPackage, user: RemoteUser, callback: Callback): void;
|
|
57
42
|
/**
|
|
58
43
|
* Allow user to publish a package.
|
|
59
44
|
*/
|
|
60
|
-
allow_publish({ packageName, packageVersion }: AuthPluginPackage, user: RemoteUser, callback: Callback): void;
|
|
61
|
-
apiJWTmiddleware():
|
|
45
|
+
allow_publish({ packageName, packageVersion }: pluginUtils.AuthPluginPackage, user: RemoteUser, callback: Callback): void;
|
|
46
|
+
apiJWTmiddleware(): RequestHandler;
|
|
62
47
|
private _handleJWTAPIMiddleware;
|
|
63
48
|
private _handleAESMiddleware;
|
|
64
49
|
private _isRemoteUserValid;
|
|
65
50
|
/**
|
|
66
51
|
* JWT middleware for WebUI
|
|
67
52
|
*/
|
|
68
|
-
webUIJWTmiddleware():
|
|
53
|
+
webUIJWTmiddleware(): RequestHandler;
|
|
69
54
|
jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string>;
|
|
70
55
|
/**
|
|
71
56
|
* Encrypt a string.
|
package/build/auth.js
CHANGED
|
@@ -17,6 +17,8 @@ var _core = require("@verdaccio/core");
|
|
|
17
17
|
|
|
18
18
|
var _loaders = require("@verdaccio/loaders");
|
|
19
19
|
|
|
20
|
+
var _logger = require("@verdaccio/logger");
|
|
21
|
+
|
|
20
22
|
var _utils = require("@verdaccio/utils");
|
|
21
23
|
|
|
22
24
|
var _jwtToken = require("./jwt-token");
|
|
@@ -29,67 +31,74 @@ var _utils2 = require("./utils");
|
|
|
29
31
|
|
|
30
32
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
31
33
|
|
|
32
|
-
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
33
|
-
const LoggerApi = require('@verdaccio/logger');
|
|
34
|
-
|
|
35
34
|
const debug = (0, _debug.default)('verdaccio:auth');
|
|
36
35
|
|
|
37
36
|
class Auth {
|
|
38
37
|
constructor(config) {
|
|
39
38
|
this.config = config;
|
|
40
|
-
this.logger = LoggerApi.logger.child({
|
|
41
|
-
sub: 'auth'
|
|
42
|
-
});
|
|
43
39
|
this.secret = config.secret;
|
|
40
|
+
this.plugins = [];
|
|
44
41
|
|
|
45
42
|
if (!this.secret) {
|
|
46
43
|
throw new TypeError('secret it is required value on initialize the auth class');
|
|
47
44
|
}
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
async init() {
|
|
48
|
+
let plugins = await this.loadPlugin();
|
|
49
|
+
debug('auth plugins found %s', plugins.length);
|
|
50
|
+
|
|
51
|
+
if (!plugins || plugins.length === 0) {
|
|
52
|
+
plugins = this.loadDefaultPlugin();
|
|
53
|
+
}
|
|
48
54
|
|
|
49
|
-
this.plugins =
|
|
55
|
+
this.plugins = plugins;
|
|
50
56
|
|
|
51
57
|
this._applyDefaultPlugins();
|
|
52
58
|
}
|
|
53
59
|
|
|
54
|
-
loadDefaultPlugin(
|
|
55
|
-
|
|
56
|
-
file: './htpasswd'
|
|
57
|
-
};
|
|
60
|
+
loadDefaultPlugin() {
|
|
61
|
+
debug('load default auth plugin');
|
|
58
62
|
const pluginOptions = {
|
|
59
|
-
config,
|
|
60
|
-
logger:
|
|
63
|
+
config: this.config,
|
|
64
|
+
logger: _logger.logger
|
|
61
65
|
};
|
|
62
66
|
let authPlugin;
|
|
63
67
|
|
|
64
68
|
try {
|
|
65
|
-
authPlugin = new _verdaccioHtpasswd.HTPasswd(
|
|
69
|
+
authPlugin = new _verdaccioHtpasswd.HTPasswd({
|
|
70
|
+
file: './htpasswd'
|
|
71
|
+
}, pluginOptions);
|
|
66
72
|
} catch (error) {
|
|
67
73
|
debug('error on loading auth htpasswd plugin stack: %o', error);
|
|
74
|
+
|
|
75
|
+
_logger.logger.info({}, 'no auth plugin has been found');
|
|
76
|
+
|
|
68
77
|
return [];
|
|
69
78
|
}
|
|
70
79
|
|
|
71
80
|
return [authPlugin];
|
|
72
81
|
}
|
|
73
82
|
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
83
|
+
async loadPlugin() {
|
|
84
|
+
var _this$config, _this$config$serverSe;
|
|
85
|
+
|
|
86
|
+
return (0, _loaders.asyncLoadPlugin)(this.config.auth, {
|
|
87
|
+
config: this.config,
|
|
88
|
+
logger: _logger.logger
|
|
89
|
+
}, plugin => {
|
|
80
90
|
const {
|
|
81
91
|
authenticate,
|
|
82
92
|
allow_access,
|
|
83
93
|
allow_publish
|
|
84
|
-
} = plugin;
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
});
|
|
94
|
+
} = plugin;
|
|
95
|
+
return typeof authenticate !== 'undefined' || typeof allow_access !== 'undefined' || typeof allow_publish !== 'undefined';
|
|
96
|
+
}, (_this$config = this.config) === null || _this$config === void 0 ? void 0 : (_this$config$serverSe = _this$config.serverSettings) === null || _this$config$serverSe === void 0 ? void 0 : _this$config$serverSe.pluginPrefix);
|
|
88
97
|
}
|
|
89
98
|
|
|
90
99
|
_applyDefaultPlugins() {
|
|
91
100
|
// TODO: rename to applyFallbackPluginMethods
|
|
92
|
-
this.plugins.push((0, _utils2.getDefaultPlugins)(
|
|
101
|
+
this.plugins.push((0, _utils2.getDefaultPlugins)(_logger.logger));
|
|
93
102
|
}
|
|
94
103
|
|
|
95
104
|
changePassword(username, password, newPassword, cb) {
|
|
@@ -107,11 +116,12 @@ class Auth {
|
|
|
107
116
|
debug('updating password for %o', username);
|
|
108
117
|
plugin.changePassword(username, password, newPassword, (err, profile) => {
|
|
109
118
|
if (err) {
|
|
110
|
-
|
|
119
|
+
_logger.logger.error({
|
|
111
120
|
username,
|
|
112
121
|
err
|
|
113
122
|
}, `An error has been produced
|
|
114
123
|
updating the password for @{username}. Error: @{err.message}`);
|
|
124
|
+
|
|
115
125
|
return cb(err);
|
|
116
126
|
}
|
|
117
127
|
|
|
@@ -180,18 +190,16 @@ class Auth {
|
|
|
180
190
|
|
|
181
191
|
(function next() {
|
|
182
192
|
const plugin = plugins.shift();
|
|
183
|
-
let method = 'adduser';
|
|
184
|
-
|
|
185
|
-
if ((0, _utils.isFunction)(plugin[method]) === false) {
|
|
186
|
-
method = 'add_user';
|
|
187
|
-
self.logger.warn('the plugin method add_user in the auth plugin is deprecated and will' + ' be removed in next major release, notify to the plugin author');
|
|
188
|
-
}
|
|
189
193
|
|
|
190
|
-
if (
|
|
194
|
+
if (typeof plugin.adduser !== 'function') {
|
|
191
195
|
next();
|
|
192
196
|
} else {
|
|
193
|
-
//
|
|
194
|
-
|
|
197
|
+
// @ts-expect-error future major (7.x) should remove this section
|
|
198
|
+
if (typeof plugin.adduser === 'undefined' && typeof plugin.add_user === 'function') {
|
|
199
|
+
throw _core.errorUtils.getInternalError('add_user method not longer supported, rename to adduser');
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
plugin.adduser(user, password, function (err, ok) {
|
|
195
203
|
if (err) {
|
|
196
204
|
debug('the user %o could not being added. Error: %o', user, err === null || err === void 0 ? void 0 : err.message);
|
|
197
205
|
return cb(err);
|
|
@@ -217,11 +225,11 @@ class Auth {
|
|
|
217
225
|
packageVersion
|
|
218
226
|
}, user, callback) {
|
|
219
227
|
const plugins = this.plugins.slice(0);
|
|
220
|
-
const
|
|
228
|
+
const pkgAllowAccess = {
|
|
221
229
|
name: packageName,
|
|
222
230
|
version: packageVersion
|
|
223
231
|
};
|
|
224
|
-
const pkg = Object.assign({},
|
|
232
|
+
const pkg = Object.assign({}, pkgAllowAccess, (0, _utils.getMatchedPackagesSpec)(packageName, this.config.packages));
|
|
225
233
|
debug('allow access for %o', packageName);
|
|
226
234
|
|
|
227
235
|
(function next() {
|
|
@@ -303,15 +311,12 @@ class Auth {
|
|
|
303
311
|
(function next() {
|
|
304
312
|
const plugin = plugins.shift();
|
|
305
313
|
|
|
306
|
-
if (
|
|
314
|
+
if (typeof (plugin === null || plugin === void 0 ? void 0 : plugin.allow_publish) !== 'function') {
|
|
307
315
|
debug('allow publish for %o plugin does not implement allow_publish', packageName);
|
|
308
316
|
return next();
|
|
309
|
-
}
|
|
310
|
-
|
|
317
|
+
}
|
|
311
318
|
|
|
312
|
-
plugin.allow_publish(user,
|
|
313
|
-
pkg, // @ts-ignore
|
|
314
|
-
(err, ok) => {
|
|
319
|
+
plugin.allow_publish(user, pkg, (err, ok) => {
|
|
315
320
|
if (_lodash.default.isNil(err) === false && _lodash.default.isError(err)) {
|
|
316
321
|
debug('forbidden publish for %o', packageName);
|
|
317
322
|
return callback(err);
|
|
@@ -340,7 +345,8 @@ class Auth {
|
|
|
340
345
|
if (plugin.apiJWTmiddleware) {
|
|
341
346
|
return plugin.apiJWTmiddleware(helpers);
|
|
342
347
|
}
|
|
343
|
-
}
|
|
348
|
+
} // @ts-ignore
|
|
349
|
+
|
|
344
350
|
|
|
345
351
|
return (req, res, _next) => {
|
|
346
352
|
req.pause();
|
|
@@ -474,7 +480,7 @@ class Auth {
|
|
|
474
480
|
}
|
|
475
481
|
|
|
476
482
|
_isRemoteUserValid(remote_user) {
|
|
477
|
-
return _lodash.default.isUndefined(remote_user) === false && _lodash.default.isUndefined(remote_user.name) === false;
|
|
483
|
+
return _lodash.default.isUndefined(remote_user) === false && _lodash.default.isUndefined(remote_user === null || remote_user === void 0 ? void 0 : remote_user.name) === false;
|
|
478
484
|
}
|
|
479
485
|
/**
|
|
480
486
|
* JWT middleware for WebUI
|
|
@@ -482,6 +488,7 @@ class Auth {
|
|
|
482
488
|
|
|
483
489
|
|
|
484
490
|
webUIJWTmiddleware() {
|
|
491
|
+
// @ts-ignore
|
|
485
492
|
return (req, res, _next) => {
|
|
486
493
|
if (this._isRemoteUserValid(req.remote_user)) {
|
|
487
494
|
return _next();
|
|
@@ -529,8 +536,7 @@ class Auth {
|
|
|
529
536
|
const {
|
|
530
537
|
name,
|
|
531
538
|
groups
|
|
532
|
-
} = credentials;
|
|
533
|
-
|
|
539
|
+
} = credentials;
|
|
534
540
|
req.remote_user = (0, _config.createRemoteUser)(name, groups);
|
|
535
541
|
} else {
|
|
536
542
|
req.remote_user = (0, _config.createAnonymousRemoteUser)();
|
package/build/auth.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"auth.js","names":["LoggerApi","require","debug","buildDebug","Auth","constructor","config","logger","child","sub","secret","TypeError","plugins","_","isNil","auth","_loadPlugin","loadDefaultPlugin","_applyDefaultPlugins","plugingConf","file","pluginOptions","authPlugin","HTPasswd","error","loadPlugin","plugin","authenticate","allow_access","allow_publish","push","getDefaultPlugins","changePassword","username","password","newPassword","cb","validPlugins","filter","isFunction","isEmpty","errorUtils","getInternalError","SUPPORT_ERRORS","PLUGIN_MISSING_INTERFACE","err","profile","invalidateToken","token","console","log","Promise","resolve","slice","next","shift","groups","message","length","isString","isGroupValid","isArray","API_ERROR","BAD_FORMAT_USER_GROUP","createRemoteUser","add_user","user","self","method","warn","ok","packageName","packageVersion","callback","pkgAllowAcces","name","version","pkg","Object","assign","getMatchedPackagesSpec","packages","allow_unpublish","arguments","isError","apiJWTmiddleware","helpers","createAnonymousRemoteUser","req","res","_next","pause","resume","remote_user","_isRemoteUserValid","remoteUser","locals","authorization","headers","isAuthHeaderValid","getBadRequest","BAD_AUTH_HEADER","security","isAESLegacy","_handleAESMiddleware","_handleJWTAPIMiddleware","scheme","parseAuthTokenHeader","toUpperCase","TOKEN_BASIC","credentials","convertPayloadToBase64","toString","parseBasicPayload","getMiddlewareCredentials","getForbidden","BAD_USERNAME_PASSWORD","isUndefined","webUIJWTmiddleware","status","statusCode","send","replace","TOKEN_BEARER","verifyJWTPayload","jwtEncrypt","signOptions","real_groups","realGroupsValidated","groupedGroups","concat","payload","signPayload","aesEncrypt","value"],"sources":["../src/auth.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { NextFunction, Request, Response } from 'express';\nimport _ from 'lodash';\nimport { HTPasswd, HTPasswdConfig } from 'verdaccio-htpasswd';\n\nimport { createAnonymousRemoteUser, createRemoteUser } from '@verdaccio/config';\nimport {\n API_ERROR,\n SUPPORT_ERRORS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n VerdaccioError,\n errorUtils,\n} from '@verdaccio/core';\nimport { loadPlugin } from '@verdaccio/loaders';\nimport {\n AllowAccess,\n AuthPluginPackage,\n Callback,\n Config,\n IPluginAuth,\n JWTSignOptions,\n Logger,\n PackageAccess,\n PluginOptions,\n RemoteUser,\n Security,\n} from '@verdaccio/types';\nimport { getMatchedPackagesSpec, isFunction, isNil } from '@verdaccio/utils';\n\nimport { signPayload } from './jwt-token';\nimport { aesEncrypt } from './legacy-token';\nimport { parseBasicPayload } from './token';\nimport {\n convertPayloadToBase64,\n getDefaultPlugins,\n getMiddlewareCredentials,\n isAESLegacy,\n isAuthHeaderValid,\n parseAuthTokenHeader,\n verifyJWTPayload,\n} from './utils';\n\n/* eslint-disable @typescript-eslint/no-var-requires */\nconst LoggerApi = require('@verdaccio/logger');\n\nconst debug = buildDebug('verdaccio:auth');\n\nexport interface IBasicAuth<T> {\n config: T & Config;\n authenticate(user: string, password: string, cb: Callback): void;\n invalidateToken?(token: string): Promise<void>;\n changePassword(user: string, password: string, newPassword: string, cb: Callback): void;\n allow_access(pkg: AuthPluginPackage, user: RemoteUser, callback: Callback): void;\n add_user(user: string, password: string, cb: Callback): any;\n}\n\nexport interface TokenEncryption {\n jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string>;\n aesEncrypt(buf: string): string | void;\n}\n\nexport interface AESPayload {\n user: string;\n password: string;\n}\n\nexport type $RequestExtend = Request & { remote_user?: any; log: Logger };\nexport type $ResponseExtend = Response & { cookies?: any };\nexport type $NextFunctionVer = NextFunction & any;\n\nexport interface IAuthMiddleware {\n apiJWTmiddleware(): $NextFunctionVer;\n webUIJWTmiddleware(): $NextFunctionVer;\n}\n\nexport interface IAuth extends IBasicAuth<Config>, IAuthMiddleware, TokenEncryption {\n config: Config;\n logger: Logger;\n secret: string;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n plugins: any[];\n allow_unpublish(pkg: AuthPluginPackage, user: RemoteUser, callback: Callback): void;\n invalidateToken(token: string): Promise<void>;\n}\n\nclass Auth implements IAuth {\n public config: Config;\n public logger: Logger;\n public secret: string;\n public plugins: IPluginAuth<Config>[];\n\n public constructor(config: Config) {\n this.config = config;\n this.logger = LoggerApi.logger.child({ sub: 'auth' });\n this.secret = config.secret;\n if (!this.secret) {\n throw new TypeError('secret it is required value on initialize the auth class');\n }\n\n this.plugins =\n _.isNil(config?.auth) === false ? this._loadPlugin(config) : this.loadDefaultPlugin(config);\n this._applyDefaultPlugins();\n }\n\n private loadDefaultPlugin(config: Config) {\n const plugingConf: HTPasswdConfig = { ...config, file: './htpasswd' };\n const pluginOptions: PluginOptions<{}> = {\n config,\n logger: this.logger,\n };\n let authPlugin;\n try {\n authPlugin = new HTPasswd(plugingConf, pluginOptions as any as PluginOptions<HTPasswdConfig>);\n } catch (error: any) {\n debug('error on loading auth htpasswd plugin stack: %o', error);\n return [];\n }\n\n return [authPlugin];\n }\n\n private _loadPlugin(config: Config): IPluginAuth<Config>[] {\n const pluginOptions = {\n config,\n logger: this.logger,\n };\n\n return loadPlugin<IPluginAuth<Config>>(\n config,\n config.auth,\n pluginOptions,\n (plugin: IPluginAuth<Config>): boolean => {\n const { authenticate, allow_access, allow_publish } = plugin;\n\n // @ts-ignore\n return authenticate || allow_access || allow_publish;\n }\n );\n }\n\n private _applyDefaultPlugins(): void {\n // TODO: rename to applyFallbackPluginMethods\n this.plugins.push(getDefaultPlugins(this.logger));\n }\n\n public changePassword(\n username: string,\n password: string,\n newPassword: string,\n cb: Callback\n ): void {\n const validPlugins = _.filter(this.plugins, (plugin) => isFunction(plugin.changePassword));\n\n if (_.isEmpty(validPlugins)) {\n return cb(errorUtils.getInternalError(SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE));\n }\n\n for (const plugin of validPlugins) {\n if (isNil(plugin) || isFunction(plugin.changePassword) === false) {\n debug('auth plugin does not implement changePassword, trying next one');\n continue;\n } else {\n debug('updating password for %o', username);\n plugin.changePassword!(username, password, newPassword, (err, profile): void => {\n if (err) {\n this.logger.error(\n { username, err },\n `An error has been produced\n updating the password for @{username}. Error: @{err.message}`\n );\n return cb(err);\n }\n\n debug('updated password for %o was successful', username);\n return cb(null, profile);\n });\n }\n }\n }\n\n public async invalidateToken(token: string) {\n // eslint-disable-next-line no-console\n console.log('invalidate token pending to implement', token);\n return Promise.resolve();\n }\n\n public authenticate(username: string, password: string, cb: Callback): void {\n const plugins = this.plugins.slice(0);\n (function next(): void {\n const plugin = plugins.shift() as IPluginAuth<Config>;\n\n if (isFunction(plugin.authenticate) === false) {\n return next();\n }\n\n debug('authenticating %o', username);\n plugin.authenticate(username, password, function (err, groups): void {\n if (err) {\n debug('authenticating for user %o failed. Error: %o', username, err?.message);\n return cb(err);\n }\n\n // Expect: SKIP if groups is falsey and not an array\n // with at least one item (truthy length)\n // Expect: CONTINUE otherwise (will error if groups is not\n // an array, but this is current behavior)\n // Caveat: STRING (if valid) will pass successfully\n // bug give unexpected results\n // Info: Cannot use `== false to check falsey values`\n if (!!groups && groups.length !== 0) {\n // TODO: create a better understanding of expectations\n if (_.isString(groups)) {\n throw new TypeError('plugin group error: invalid type for function');\n }\n const isGroupValid: boolean = _.isArray(groups);\n if (!isGroupValid) {\n throw new TypeError(API_ERROR.BAD_FORMAT_USER_GROUP);\n }\n\n debug('authentication for user %o was successfully. Groups: %o', username, groups);\n return cb(err, createRemoteUser(username, groups));\n }\n next();\n });\n })();\n }\n\n public add_user(user: string, password: string, cb: Callback): void {\n const self = this;\n const plugins = this.plugins.slice(0);\n debug('add user %o', user);\n\n (function next(): void {\n const plugin = plugins.shift() as IPluginAuth<Config>;\n let method = 'adduser';\n if (isFunction(plugin[method]) === false) {\n method = 'add_user';\n self.logger.warn(\n 'the plugin method add_user in the auth plugin is deprecated and will' +\n ' be removed in next major release, notify to the plugin author'\n );\n }\n\n if (isFunction(plugin[method]) === false) {\n next();\n } else {\n // p.add_user() execution\n plugin[method](user, password, function (err, ok): void {\n if (err) {\n debug('the user %o could not being added. Error: %o', user, err?.message);\n return cb(err);\n }\n if (ok) {\n debug('the user %o has been added', user);\n return self.authenticate(user, password, cb);\n }\n next();\n });\n }\n })();\n }\n\n /**\n * Allow user to access a package.\n */\n public allow_access(\n { packageName, packageVersion }: AuthPluginPackage,\n user: RemoteUser,\n callback: Callback\n ): void {\n const plugins = this.plugins.slice(0);\n const pkgAllowAcces: AllowAccess = { name: packageName, version: packageVersion };\n const pkg = Object.assign(\n {},\n pkgAllowAcces,\n getMatchedPackagesSpec(packageName, this.config.packages)\n ) as AllowAccess & PackageAccess;\n debug('allow access for %o', packageName);\n\n (function next(): void {\n const plugin: IPluginAuth<Config> = plugins.shift() as IPluginAuth<Config>;\n\n if (_.isNil(plugin) || isFunction(plugin.allow_access) === false) {\n return next();\n }\n\n plugin.allow_access!(user, pkg, function (err, ok: boolean): void {\n if (err) {\n debug('forbidden access for %o. Error: %o', packageName, err?.message);\n return callback(err);\n }\n\n if (ok) {\n debug('allowed access for %o', packageName);\n return callback(null, ok);\n }\n\n next(); // cb(null, false) causes next plugin to roll\n });\n })();\n }\n\n public allow_unpublish(\n { packageName, packageVersion }: AuthPluginPackage,\n user: RemoteUser,\n callback: Callback\n ): void {\n const pkg = Object.assign(\n { name: packageName, version: packageVersion },\n getMatchedPackagesSpec(packageName, this.config.packages)\n );\n debug('allow unpublish for %o', packageName);\n\n for (const plugin of this.plugins) {\n if (_.isNil(plugin) || isFunction(plugin.allow_unpublish) === false) {\n debug('allow unpublish for %o plugin does not implement allow_unpublish', packageName);\n continue;\n } else {\n // @ts-ignore\n plugin.allow_unpublish!(user, pkg, (err, ok: boolean): void => {\n if (err) {\n debug(\n 'forbidden publish for %o, it will fallback on unpublish permissions',\n packageName\n );\n return callback(err);\n }\n\n if (_.isNil(ok) === true) {\n debug('bypass unpublish for %o, publish will handle the access', packageName);\n // @ts-ignore\n // eslint-disable-next-line\n return this.allow_publish(...arguments);\n }\n\n if (ok) {\n debug('allowed unpublish for %o', packageName);\n return callback(null, ok);\n }\n });\n }\n }\n }\n\n /**\n * Allow user to publish a package.\n */\n public allow_publish(\n { packageName, packageVersion }: AuthPluginPackage,\n user: RemoteUser,\n callback: Callback\n ): void {\n const plugins = this.plugins.slice(0);\n const pkg = Object.assign(\n { name: packageName, version: packageVersion },\n getMatchedPackagesSpec(packageName, this.config.packages)\n );\n debug('allow publish for %o init | plugins: %o', packageName, plugins.length);\n\n (function next(): void {\n const plugin = plugins.shift();\n\n if (isFunction(plugin?.allow_publish) === false) {\n debug('allow publish for %o plugin does not implement allow_publish', packageName);\n return next();\n }\n\n // @ts-ignore\n plugin.allow_publish(\n user,\n // @ts-ignore\n pkg,\n // @ts-ignore\n (err: VerdaccioError, ok: boolean): void => {\n if (_.isNil(err) === false && _.isError(err)) {\n debug('forbidden publish for %o', packageName);\n return callback(err);\n }\n\n if (ok) {\n debug('allowed publish for %o', packageName);\n return callback(null, ok);\n }\n\n debug('allow publish skip validation for %o', packageName);\n next(); // cb(null, false) causes next plugin to roll\n }\n );\n })();\n }\n\n public apiJWTmiddleware(): Function {\n debug('jwt middleware');\n const plugins = this.plugins.slice(0);\n const helpers = { createAnonymousRemoteUser, createRemoteUser };\n for (const plugin of plugins) {\n if (plugin.apiJWTmiddleware) {\n return plugin.apiJWTmiddleware(helpers);\n }\n }\n\n return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction): void => {\n req.pause();\n\n const next = function (err: VerdaccioError | void): void {\n req.resume();\n // uncomment this to reject users with bad auth headers\n // return _next.apply(null, arguments)\n // swallow error, user remains unauthorized\n // set remoteUserError to indicate that user was attempting authentication\n if (err) {\n req.remote_user.error = err.message;\n }\n return _next();\n };\n\n if (this._isRemoteUserValid(req.remote_user)) {\n debug('jwt has a valid authentication header');\n return next();\n }\n\n // in case auth header does not exist we return anonymous function\n const remoteUser = createAnonymousRemoteUser();\n req.remote_user = remoteUser;\n res.locals.remote_user = remoteUser;\n\n const { authorization } = req.headers;\n if (_.isNil(authorization)) {\n debug('jwt, authentication header is missing');\n return next();\n }\n\n if (!isAuthHeaderValid(authorization)) {\n debug('api middleware authentication heather is invalid');\n return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER));\n }\n const { secret, security } = this.config;\n\n if (isAESLegacy(security)) {\n debug('api middleware using legacy auth token');\n this._handleAESMiddleware(req, security, secret, authorization, next);\n } else {\n debug('api middleware using JWT auth token');\n this._handleJWTAPIMiddleware(req, security, secret, authorization, next);\n }\n };\n }\n\n private _handleJWTAPIMiddleware(\n req: $RequestExtend,\n security: Security,\n secret: string,\n authorization: string,\n next: Function\n ): void {\n debug('handle JWT api middleware');\n const { scheme, token } = parseAuthTokenHeader(authorization);\n if (scheme.toUpperCase() === TOKEN_BASIC.toUpperCase()) {\n debug('handle basic token');\n // this should happen when client tries to login with an existing user\n const credentials = convertPayloadToBase64(token).toString();\n const { user, password } = parseBasicPayload(credentials) as AESPayload;\n debug('authenticating %o', user);\n this.authenticate(user, password, (err, user): void => {\n if (!err) {\n debug('generating a remote user');\n req.remote_user = user;\n next();\n } else {\n debug('generating anonymous user');\n req.remote_user = createAnonymousRemoteUser();\n next(err);\n }\n });\n } else {\n debug('handle jwt token');\n const credentials: any = getMiddlewareCredentials(security, secret, authorization);\n if (credentials) {\n // if the signature is valid we rely on it\n req.remote_user = credentials;\n debug('generating a remote user');\n next();\n } else {\n // with JWT throw 401\n debug('jwt invalid token');\n next(errorUtils.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));\n }\n }\n }\n\n private _handleAESMiddleware(\n req: $RequestExtend,\n security: Security,\n secret: string,\n authorization: string,\n next: Function\n ): void {\n debug('handle legacy api middleware');\n debug('api middleware secret %o', typeof secret === 'string');\n debug('api middleware authorization %o', typeof authorization === 'string');\n const credentials: any = getMiddlewareCredentials(security, secret, authorization);\n debug('api middleware credentials %o', credentials?.name);\n if (credentials) {\n const { user, password } = credentials;\n debug('authenticating %o', user);\n this.authenticate(user, password, (err, user): void => {\n if (!err) {\n req.remote_user = user;\n debug('generating a remote user');\n next();\n } else {\n req.remote_user = createAnonymousRemoteUser();\n debug('generating anonymous user');\n next(err);\n }\n });\n } else {\n // we force npm client to ask again with basic authentication\n debug('legacy invalid header');\n return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER));\n }\n }\n\n private _isRemoteUserValid(remote_user: RemoteUser): boolean {\n return _.isUndefined(remote_user) === false && _.isUndefined(remote_user.name) === false;\n }\n\n /**\n * JWT middleware for WebUI\n */\n public webUIJWTmiddleware(): Function {\n return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction): void => {\n if (this._isRemoteUserValid(req.remote_user)) {\n return _next();\n }\n\n req.pause();\n const next = (err: VerdaccioError | void): void => {\n req.resume();\n if (err) {\n // req.remote_user.error = err.message;\n res.status(err.statusCode).send(err.message);\n }\n\n return _next();\n };\n\n const { authorization } = req.headers;\n if (_.isNil(authorization)) {\n return next();\n }\n\n if (!isAuthHeaderValid(authorization)) {\n return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER));\n }\n\n const token = (authorization || '').replace(`${TOKEN_BEARER} `, '');\n if (!token) {\n return next();\n }\n\n let credentials;\n try {\n credentials = verifyJWTPayload(token, this.config.secret);\n } catch (err: any) {\n // FIXME: intended behaviour, do we want it?\n }\n\n if (this._isRemoteUserValid(credentials)) {\n const { name, groups } = credentials;\n // $FlowFixMe\n req.remote_user = createRemoteUser(name, groups);\n } else {\n req.remote_user = createAnonymousRemoteUser();\n }\n\n next();\n };\n }\n\n public async jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string> {\n const { real_groups, name, groups } = user;\n debug('jwt encrypt %o', name);\n const realGroupsValidated = _.isNil(real_groups) ? [] : real_groups;\n const groupedGroups = _.isNil(groups) ? real_groups : groups.concat(realGroupsValidated);\n const payload: RemoteUser = {\n real_groups: realGroupsValidated,\n name,\n groups: groupedGroups,\n };\n\n const token: string = await signPayload(payload, this.secret, signOptions);\n\n return token;\n }\n\n /**\n * Encrypt a string.\n */\n public aesEncrypt(value: string): string | void {\n return aesEncrypt(value, this.secret);\n }\n}\n\nexport { Auth };\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAEA;;AACA;;AAQA;;AAcA;;AAEA;;AACA;;AACA;;AACA;;;;AAUA;AACA,MAAMA,SAAS,GAAGC,OAAO,CAAC,mBAAD,CAAzB;;AAEA,MAAMC,KAAK,GAAG,IAAAC,cAAA,EAAW,gBAAX,CAAd;;AAwCA,MAAMC,IAAN,CAA4B;EAMnBC,WAAW,CAACC,MAAD,EAAiB;IACjC,KAAKA,MAAL,GAAcA,MAAd;IACA,KAAKC,MAAL,GAAcP,SAAS,CAACO,MAAV,CAAiBC,KAAjB,CAAuB;MAAEC,GAAG,EAAE;IAAP,CAAvB,CAAd;IACA,KAAKC,MAAL,GAAcJ,MAAM,CAACI,MAArB;;IACA,IAAI,CAAC,KAAKA,MAAV,EAAkB;MAChB,MAAM,IAAIC,SAAJ,CAAc,0DAAd,CAAN;IACD;;IAED,KAAKC,O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IACA,MAAMG,OAAmB,GAAG;MAC1BJ,WAAW,EAAEC,mBADa;MAE1BrD,IAF0B;MAG1BnB,MAAM,EAAEyE;IAHkB,CAA5B;IAMA,MAAMjF,KAAa,GAAG,MAAM,IAAAoF,qBAAA,EAAYD,OAAZ,EAAqB,KAAKzH,MAA1B,EAAkCoH,WAAlC,CAA5B;IAEA,OAAO9E,KAAP;EACD;EAED;AACF;AACA;;;EACSqF,UAAU,CAACC,KAAD,EAA+B;IAC9C,OAAO,IAAAD,uBAAA,EAAWC,KAAX,EAAkB,KAAK5H,MAAvB,CAAP;EACD;;AApgByB"}
|
|
1
|
+
{"version":3,"file":"auth.js","names":["debug","buildDebug","Auth","constructor","config","secret","plugins","TypeError","init","loadPlugin","length","loadDefaultPlugin","_applyDefaultPlugins","pluginOptions","logger","authPlugin","HTPasswd","file","error","info","asyncLoadPlugin","auth","plugin","authenticate","allow_access","allow_publish","serverSettings","pluginPrefix","push","getDefaultPlugins","changePassword","username","password","newPassword","cb","validPlugins","_","filter","isFunction","isEmpty","errorUtils","getInternalError","SUPPORT_ERRORS","PLUGIN_MISSING_INTERFACE","isNil","err","profile","invalidateToken","token","console","log","Promise","resolve","slice","next","shift","groups","message","isString","isGroupValid","isArray","API_ERROR","BAD_FORMAT_USER_GROUP","createRemoteUser","add_user","user","self","adduser","ok","packageName","packageVersion","callback","pkgAllowAccess","name","version","pkg","Object","assign","getMatchedPackagesSpec","packages","allow_unpublish","arguments","isError","apiJWTmiddleware","helpers","createAnonymousRemoteUser","req","res","_next","pause","resume","remote_user","_isRemoteUserValid","remoteUser","locals","authorization","headers","isAuthHeaderValid","getBadRequest","BAD_AUTH_HEADER","security","isAESLegacy","_handleAESMiddleware","_handleJWTAPIMiddleware","scheme","parseAuthTokenHeader","toUpperCase","TOKEN_BASIC","credentials","convertPayloadToBase64","toString","parseBasicPayload","getMiddlewareCredentials","getForbidden","BAD_USERNAME_PASSWORD","isUndefined","webUIJWTmiddleware","status","statusCode","send","replace","TOKEN_BEARER","verifyJWTPayload","jwtEncrypt","signOptions","real_groups","realGroupsValidated","groupedGroups","concat","payload","signPayload","aesEncrypt","value"],"sources":["../src/auth.ts"],"sourcesContent":["import buildDebug from 'debug';\nimport { NextFunction, Request, RequestHandler, Response } from 'express';\nimport _ from 'lodash';\nimport { HTPasswd } from 'verdaccio-htpasswd';\n\nimport { createAnonymousRemoteUser, createRemoteUser } from '@verdaccio/config';\nimport {\n API_ERROR,\n SUPPORT_ERRORS,\n TOKEN_BASIC,\n TOKEN_BEARER,\n VerdaccioError,\n errorUtils,\n pluginUtils,\n} from '@verdaccio/core';\nimport { asyncLoadPlugin } from '@verdaccio/loaders';\nimport { logger } from '@verdaccio/logger';\nimport {\n AllowAccess,\n Callback,\n Config,\n JWTSignOptions,\n Logger,\n PackageAccess,\n RemoteUser,\n Security,\n} from '@verdaccio/types';\nimport { getMatchedPackagesSpec, isFunction, isNil } from '@verdaccio/utils';\n\nimport { signPayload } from './jwt-token';\nimport { aesEncrypt } from './legacy-token';\nimport { parseBasicPayload } from './token';\nimport {\n convertPayloadToBase64,\n getDefaultPlugins,\n getMiddlewareCredentials,\n isAESLegacy,\n isAuthHeaderValid,\n parseAuthTokenHeader,\n verifyJWTPayload,\n} from './utils';\n\nconst debug = buildDebug('verdaccio:auth');\n\nexport interface TokenEncryption {\n jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string>;\n aesEncrypt(buf: string): string | void;\n}\n\nexport interface AESPayload {\n user: string;\n password: string;\n}\nexport interface IAuthMiddleware {\n apiJWTmiddleware(): $NextFunctionVer;\n webUIJWTmiddleware(): $NextFunctionVer;\n}\n\nexport type $RequestExtend = Request & { remote_user?: any; log: Logger };\nexport type $ResponseExtend = Response & { cookies?: any };\nexport type $NextFunctionVer = NextFunction & any;\n\nclass Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {\n public config: Config;\n public secret: string;\n public plugins: pluginUtils.Auth<Config>[];\n\n public constructor(config: Config) {\n this.config = config;\n this.secret = config.secret;\n this.plugins = [];\n if (!this.secret) {\n throw new TypeError('secret it is required value on initialize the auth class');\n }\n }\n\n public async init() {\n let plugins = (await this.loadPlugin()) as pluginUtils.Auth<unknown>[];\n debug('auth plugins found %s', plugins.length);\n if (!plugins || plugins.length === 0) {\n plugins = this.loadDefaultPlugin();\n }\n this.plugins = plugins;\n\n this._applyDefaultPlugins();\n }\n\n private loadDefaultPlugin() {\n debug('load default auth plugin');\n const pluginOptions: pluginUtils.PluginOptions = {\n config: this.config,\n logger,\n };\n let authPlugin;\n try {\n authPlugin = new HTPasswd(\n { file: './htpasswd' },\n pluginOptions as any as pluginUtils.PluginOptions\n );\n } catch (error: any) {\n debug('error on loading auth htpasswd plugin stack: %o', error);\n logger.info({}, 'no auth plugin has been found');\n return [];\n }\n\n return [authPlugin];\n }\n\n private async loadPlugin() {\n return asyncLoadPlugin<pluginUtils.Auth<unknown>>(\n this.config.auth,\n {\n config: this.config,\n logger,\n },\n (plugin): boolean => {\n const { authenticate, allow_access, allow_publish } = plugin;\n\n return (\n typeof authenticate !== 'undefined' ||\n typeof allow_access !== 'undefined' ||\n typeof allow_publish !== 'undefined'\n );\n },\n this.config?.serverSettings?.pluginPrefix\n );\n }\n\n private _applyDefaultPlugins(): void {\n // TODO: rename to applyFallbackPluginMethods\n this.plugins.push(getDefaultPlugins(logger));\n }\n\n public changePassword(\n username: string,\n password: string,\n newPassword: string,\n cb: Callback\n ): void {\n const validPlugins = _.filter(this.plugins, (plugin) => isFunction(plugin.changePassword));\n\n if (_.isEmpty(validPlugins)) {\n return cb(errorUtils.getInternalError(SUPPORT_ERRORS.PLUGIN_MISSING_INTERFACE));\n }\n\n for (const plugin of validPlugins) {\n if (isNil(plugin) || isFunction(plugin.changePassword) === false) {\n debug('auth plugin does not implement changePassword, trying next one');\n continue;\n } else {\n debug('updating password for %o', username);\n plugin.changePassword!(username, password, newPassword, (err, profile): void => {\n if (err) {\n logger.error(\n { username, err },\n `An error has been produced\n updating the password for @{username}. Error: @{err.message}`\n );\n return cb(err);\n }\n\n debug('updated password for %o was successful', username);\n return cb(null, profile);\n });\n }\n }\n }\n\n public async invalidateToken(token: string) {\n // eslint-disable-next-line no-console\n console.log('invalidate token pending to implement', token);\n return Promise.resolve();\n }\n\n public authenticate(\n username: string,\n password: string,\n cb: (error: VerdaccioError | null, user?: RemoteUser) => void\n ): void {\n const plugins = this.plugins.slice(0);\n (function next(): void {\n const plugin = plugins.shift() as pluginUtils.Auth<Config>;\n\n if (isFunction(plugin.authenticate) === false) {\n return next();\n }\n\n debug('authenticating %o', username);\n plugin.authenticate(username, password, function (err: VerdaccioError | null, groups): void {\n if (err) {\n debug('authenticating for user %o failed. Error: %o', username, err?.message);\n return cb(err);\n }\n\n // Expect: SKIP if groups is falsey and not an array\n // with at least one item (truthy length)\n // Expect: CONTINUE otherwise (will error if groups is not\n // an array, but this is current behavior)\n // Caveat: STRING (if valid) will pass successfully\n // bug give unexpected results\n // Info: Cannot use `== false to check falsey values`\n if (!!groups && groups.length !== 0) {\n // TODO: create a better understanding of expectations\n if (_.isString(groups)) {\n throw new TypeError('plugin group error: invalid type for function');\n }\n const isGroupValid: boolean = _.isArray(groups);\n if (!isGroupValid) {\n throw new TypeError(API_ERROR.BAD_FORMAT_USER_GROUP);\n }\n\n debug('authentication for user %o was successfully. Groups: %o', username, groups);\n return cb(err, createRemoteUser(username, groups));\n }\n next();\n });\n })();\n }\n\n public add_user(\n user: string,\n password: string,\n cb: (error: VerdaccioError | null, user?: RemoteUser) => void\n ): void {\n const self = this;\n const plugins = this.plugins.slice(0);\n debug('add user %o', user);\n\n (function next(): void {\n const plugin = plugins.shift() as pluginUtils.Auth<Config>;\n if (typeof plugin.adduser !== 'function') {\n next();\n } else {\n // @ts-expect-error future major (7.x) should remove this section\n if (typeof plugin.adduser === 'undefined' && typeof plugin.add_user === 'function') {\n throw errorUtils.getInternalError(\n 'add_user method not longer supported, rename to adduser'\n );\n }\n\n plugin.adduser(\n user,\n password,\n function (err: VerdaccioError | null, ok?: boolean | string): void {\n if (err) {\n debug('the user %o could not being added. Error: %o', user, err?.message);\n return cb(err);\n }\n if (ok) {\n debug('the user %o has been added', user);\n return self.authenticate(user, password, cb);\n }\n next();\n }\n );\n }\n })();\n }\n\n /**\n * Allow user to access a package.\n */\n public allow_access(\n { packageName, packageVersion }: pluginUtils.AuthPluginPackage,\n user: RemoteUser,\n callback: pluginUtils.AccessCallback\n ): void {\n const plugins = this.plugins.slice(0);\n const pkgAllowAccess: AllowAccess = { name: packageName, version: packageVersion };\n const pkg = Object.assign(\n {},\n pkgAllowAccess,\n getMatchedPackagesSpec(packageName, this.config.packages)\n ) as AllowAccess & PackageAccess;\n debug('allow access for %o', packageName);\n\n (function next(): void {\n const plugin: pluginUtils.Auth<unknown> = plugins.shift() as pluginUtils.Auth<unknown>;\n\n if (_.isNil(plugin) || isFunction(plugin.allow_access) === false) {\n return next();\n }\n\n plugin.allow_access!(user, pkg, function (err: VerdaccioError | null, ok?: boolean): void {\n if (err) {\n debug('forbidden access for %o. Error: %o', packageName, err?.message);\n return callback(err);\n }\n\n if (ok) {\n debug('allowed access for %o', packageName);\n return callback(null, ok);\n }\n\n next(); // cb(null, false) causes next plugin to roll\n });\n })();\n }\n\n public allow_unpublish(\n { packageName, packageVersion }: pluginUtils.AuthPluginPackage,\n user: RemoteUser,\n callback: Callback\n ): void {\n const pkg = Object.assign(\n { name: packageName, version: packageVersion },\n getMatchedPackagesSpec(packageName, this.config.packages)\n );\n debug('allow unpublish for %o', packageName);\n\n for (const plugin of this.plugins) {\n if (_.isNil(plugin) || isFunction(plugin.allow_unpublish) === false) {\n debug('allow unpublish for %o plugin does not implement allow_unpublish', packageName);\n continue;\n } else {\n // @ts-ignore\n plugin.allow_unpublish!(user, pkg, (err, ok: boolean): void => {\n if (err) {\n debug(\n 'forbidden publish for %o, it will fallback on unpublish permissions',\n packageName\n );\n return callback(err);\n }\n\n if (_.isNil(ok) === true) {\n debug('bypass unpublish for %o, publish will handle the access', packageName);\n // @ts-ignore\n // eslint-disable-next-line\n return this.allow_publish(...arguments);\n }\n\n if (ok) {\n debug('allowed unpublish for %o', packageName);\n return callback(null, ok);\n }\n });\n }\n }\n }\n\n /**\n * Allow user to publish a package.\n */\n public allow_publish(\n { packageName, packageVersion }: pluginUtils.AuthPluginPackage,\n user: RemoteUser,\n callback: Callback\n ): void {\n const plugins = this.plugins.slice(0);\n const pkg = Object.assign(\n { name: packageName, version: packageVersion },\n getMatchedPackagesSpec(packageName, this.config.packages)\n ) as any;\n debug('allow publish for %o init | plugins: %o', packageName, plugins.length);\n\n (function next(): void {\n const plugin = plugins.shift();\n\n if (typeof plugin?.allow_publish !== 'function') {\n debug('allow publish for %o plugin does not implement allow_publish', packageName);\n return next();\n }\n\n plugin.allow_publish(user, pkg, (err: VerdaccioError | null, ok?: boolean): void => {\n if (_.isNil(err) === false && _.isError(err)) {\n debug('forbidden publish for %o', packageName);\n return callback(err);\n }\n\n if (ok) {\n debug('allowed publish for %o', packageName);\n return callback(null, ok);\n }\n\n debug('allow publish skip validation for %o', packageName);\n next(); // cb(null, false) causes next plugin to roll\n });\n })();\n }\n\n public apiJWTmiddleware(): RequestHandler {\n debug('jwt middleware');\n const plugins = this.plugins.slice(0);\n const helpers = { createAnonymousRemoteUser, createRemoteUser };\n for (const plugin of plugins) {\n if (plugin.apiJWTmiddleware) {\n return plugin.apiJWTmiddleware(helpers);\n }\n }\n\n // @ts-ignore\n return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction) => {\n req.pause();\n\n const next = function (err?: VerdaccioError): any {\n req.resume();\n // uncomment this to reject users with bad auth headers\n // return _next.apply(null, arguments)\n // swallow error, user remains unauthorized\n // set remoteUserError to indicate that user was attempting authentication\n if (err) {\n req.remote_user.error = err.message;\n }\n\n return _next();\n };\n\n if (this._isRemoteUserValid(req.remote_user)) {\n debug('jwt has a valid authentication header');\n return next();\n }\n\n // in case auth header does not exist we return anonymous function\n const remoteUser = createAnonymousRemoteUser();\n req.remote_user = remoteUser;\n res.locals.remote_user = remoteUser;\n\n const { authorization } = req.headers;\n if (_.isNil(authorization)) {\n debug('jwt, authentication header is missing');\n return next();\n }\n\n if (!isAuthHeaderValid(authorization)) {\n debug('api middleware authentication heather is invalid');\n return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER));\n }\n const { secret, security } = this.config;\n\n if (isAESLegacy(security)) {\n debug('api middleware using legacy auth token');\n this._handleAESMiddleware(req, security, secret, authorization, next);\n } else {\n debug('api middleware using JWT auth token');\n this._handleJWTAPIMiddleware(req, security, secret, authorization, next);\n }\n };\n }\n\n private _handleJWTAPIMiddleware(\n req: $RequestExtend,\n security: Security,\n secret: string,\n authorization: string,\n next: Function\n ): void {\n debug('handle JWT api middleware');\n const { scheme, token } = parseAuthTokenHeader(authorization);\n if (scheme.toUpperCase() === TOKEN_BASIC.toUpperCase()) {\n debug('handle basic token');\n // this should happen when client tries to login with an existing user\n const credentials = convertPayloadToBase64(token).toString();\n const { user, password } = parseBasicPayload(credentials) as AESPayload;\n debug('authenticating %o', user);\n this.authenticate(user, password, (err: VerdaccioError | null, user): void => {\n if (!err) {\n debug('generating a remote user');\n req.remote_user = user;\n next();\n } else {\n debug('generating anonymous user');\n req.remote_user = createAnonymousRemoteUser();\n next(err);\n }\n });\n } else {\n debug('handle jwt token');\n const credentials: any = getMiddlewareCredentials(security, secret, authorization);\n if (credentials) {\n // if the signature is valid we rely on it\n req.remote_user = credentials;\n debug('generating a remote user');\n next();\n } else {\n // with JWT throw 401\n debug('jwt invalid token');\n next(errorUtils.getForbidden(API_ERROR.BAD_USERNAME_PASSWORD));\n }\n }\n }\n\n private _handleAESMiddleware(\n req: $RequestExtend,\n security: Security,\n secret: string,\n authorization: string,\n next: Function\n ): void {\n debug('handle legacy api middleware');\n debug('api middleware secret %o', typeof secret === 'string');\n debug('api middleware authorization %o', typeof authorization === 'string');\n const credentials: any = getMiddlewareCredentials(security, secret, authorization);\n debug('api middleware credentials %o', credentials?.name);\n if (credentials) {\n const { user, password } = credentials;\n debug('authenticating %o', user);\n this.authenticate(user, password, (err, user): void => {\n if (!err) {\n req.remote_user = user;\n debug('generating a remote user');\n next();\n } else {\n req.remote_user = createAnonymousRemoteUser();\n debug('generating anonymous user');\n next(err);\n }\n });\n } else {\n // we force npm client to ask again with basic authentication\n debug('legacy invalid header');\n return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER));\n }\n }\n\n private _isRemoteUserValid(remote_user?: RemoteUser): boolean {\n return _.isUndefined(remote_user) === false && _.isUndefined(remote_user?.name) === false;\n }\n\n /**\n * JWT middleware for WebUI\n */\n public webUIJWTmiddleware(): RequestHandler {\n // @ts-ignore\n return (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction): void => {\n if (this._isRemoteUserValid(req.remote_user)) {\n return _next();\n }\n\n req.pause();\n const next = (err: VerdaccioError | void): void => {\n req.resume();\n if (err) {\n // req.remote_user.error = err.message;\n res.status(err.statusCode).send(err.message);\n }\n\n return _next();\n };\n\n const { authorization } = req.headers;\n if (_.isNil(authorization)) {\n return next();\n }\n\n if (!isAuthHeaderValid(authorization)) {\n return next(errorUtils.getBadRequest(API_ERROR.BAD_AUTH_HEADER));\n }\n\n const token = (authorization || '').replace(`${TOKEN_BEARER} `, '');\n if (!token) {\n return next();\n }\n\n let credentials: RemoteUser | undefined;\n try {\n credentials = verifyJWTPayload(token, this.config.secret);\n } catch (err: any) {\n // FIXME: intended behaviour, do we want it?\n }\n\n if (this._isRemoteUserValid(credentials)) {\n const { name, groups } = credentials as RemoteUser;\n req.remote_user = createRemoteUser(name as string, groups);\n } else {\n req.remote_user = createAnonymousRemoteUser();\n }\n\n next();\n };\n }\n\n public async jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string> {\n const { real_groups, name, groups } = user;\n debug('jwt encrypt %o', name);\n const realGroupsValidated = _.isNil(real_groups) ? [] : real_groups;\n const groupedGroups = _.isNil(groups) ? real_groups : groups.concat(realGroupsValidated);\n const payload: RemoteUser = {\n real_groups: realGroupsValidated,\n name,\n groups: groupedGroups,\n };\n\n const token: string = await signPayload(payload, this.secret, signOptions);\n\n return token;\n }\n\n /**\n * Encrypt a string.\n */\n public aesEncrypt(value: string): string | void {\n return aesEncrypt(value, this.secret);\n }\n}\n\nexport { Auth };\n"],"mappings":";;;;;;;AAAA;;AAEA;;AACA;;AAEA;;AACA;;AASA;;AACA;;AAWA;;AAEA;;AACA;;AACA;;AACA;;;;AAUA,MAAMA,KAAK,GAAG,IAAAC,cAAA,EAAW,gBAAX,CAAd;;AAoBA,MAAMC,IAAN,CAA+E;EAKtEC,WAAW,CAACC,MAAD,EAAiB;IACjC,KAAKA,MAAL,GAAcA,MAAd;IACA,KAAKC,MAAL,GAAcD,MAAM,CAACC,MAArB;IACA,KAAKC,OAAL,GAAe,EAAf;;IACA,IAAI,CAAC,KAAKD,MAAV,EAAkB;MAChB,MAAM,IAAIE,SAAJ,CAAc,0DAAd,CAAN;IACD;EACF;;EAEgB,MAAJC,IAAI,GAAG;IAClB,IAAIF,OAAO,GAAI,MAAM,KAAKG,UAAL,EAArB;IACAT,KAAK,CAAC,uBAAD,EAA0BM,OAAO,CAACI,MAAlC,CAAL;;IACA,IAAI,CAACJ,OAAD,IAAYA,OAAO,CAACI,MAAR,KAAmB,CAAnC,EAAsC;MACpCJ,OAAO,GAAG,KAAKK,iBAAL,EAAV;IACD;;IACD,KAAKL,OAAL,GAAeA,OAAf;;IAEA,KAAKM,oBAAL;EACD;;EAEOD,iBAAiB,GAAG;IAC1BX,KAAK,CAAC,0BAAD,CAAL;IACA,MAAMa,aAAwC,GAAG;MAC/CT,MAAM,EAAE,KAAKA,MADkC;MAE/CU,MAAM,EAANA;IAF+C,CAAjD;IAIA,IAAIC,UAAJ;;IACA,IAAI;MACFA,UAAU,GAAG,IAAIC,2BAAJ,CACX;QAAEC,IAAI,EAAE;MAAR,CADW,EAEXJ,aAFW,CAAb;IAID,CALD,CAKE,OAAOK,KAAP,EA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@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
var _exportNames = {
|
|
7
7
|
Auth: true,
|
|
8
|
-
|
|
9
|
-
TokenEncryption: true,
|
|
10
|
-
IBasicAuth: true
|
|
8
|
+
TokenEncryption: true
|
|
11
9
|
};
|
|
12
10
|
Object.defineProperty(exports, "Auth", {
|
|
13
11
|
enumerable: true,
|
|
@@ -15,18 +13,6 @@ Object.defineProperty(exports, "Auth", {
|
|
|
15
13
|
return _auth.Auth;
|
|
16
14
|
}
|
|
17
15
|
});
|
|
18
|
-
Object.defineProperty(exports, "IAuth", {
|
|
19
|
-
enumerable: true,
|
|
20
|
-
get: function () {
|
|
21
|
-
return _auth.IAuth;
|
|
22
|
-
}
|
|
23
|
-
});
|
|
24
|
-
Object.defineProperty(exports, "IBasicAuth", {
|
|
25
|
-
enumerable: true,
|
|
26
|
-
get: function () {
|
|
27
|
-
return _auth.IBasicAuth;
|
|
28
|
-
}
|
|
29
|
-
});
|
|
30
16
|
Object.defineProperty(exports, "TokenEncryption", {
|
|
31
17
|
enumerable: true,
|
|
32
18
|
get: function () {
|
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { Auth,
|
|
1
|
+
{"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["export { Auth, TokenEncryption } from './auth';\nexport * from './utils';\nexport * from './legacy-token';\nexport * from './jwt-token';\nexport * from './token';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA;;AACA;;AAAA;EAAA;EAAA;EAAA;EAAA;IAAA;IAAA;MAAA;IAAA;EAAA;AAAA"}
|
package/build/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import { VerdaccioError } from '@verdaccio/core';
|
|
3
|
-
import { AuthPackageAllow, Config,
|
|
2
|
+
import { VerdaccioError, pluginUtils } from '@verdaccio/core';
|
|
3
|
+
import { AuthPackageAllow, Config, Logger, RemoteUser, Security } from '@verdaccio/types';
|
|
4
4
|
import { AESPayload, TokenEncryption } from './auth';
|
|
5
5
|
export declare type BasicPayload = AESPayload | void;
|
|
6
6
|
export declare type AuthMiddlewarePayload = RemoteUser | BasicPayload;
|
|
@@ -23,12 +23,17 @@ export declare function getApiToken(auth: TokenEncryption, config: Config, remot
|
|
|
23
23
|
export declare const expireReasons: string[];
|
|
24
24
|
export declare function verifyJWTPayload(token: string, secret: string): RemoteUser;
|
|
25
25
|
export declare function isAuthHeaderValid(authorization: string): boolean;
|
|
26
|
-
|
|
26
|
+
/**
|
|
27
|
+
* Return a default configuration for authentication if none is provided.
|
|
28
|
+
* @param logger {Logger}
|
|
29
|
+
* @returns object of default implementations.
|
|
30
|
+
*/
|
|
31
|
+
export declare function getDefaultPlugins(logger: Logger): pluginUtils.Auth<Config>;
|
|
27
32
|
export declare type ActionsAllowed = 'publish' | 'unpublish' | 'access';
|
|
28
|
-
export declare function allow_action(action: ActionsAllowed, logger:
|
|
33
|
+
export declare function allow_action(action: ActionsAllowed, logger: Logger): AllowAction;
|
|
29
34
|
/**
|
|
30
35
|
*
|
|
31
36
|
*/
|
|
32
|
-
export declare function handleSpecialUnpublish(logger:
|
|
37
|
+
export declare function handleSpecialUnpublish(logger: Logger): any;
|
|
33
38
|
export declare function buildUser(name: string, password: string): string;
|
|
34
39
|
export declare function convertPayloadToBase64(payload: string): Buffer;
|