@verdaccio/auth 6.0.0-6-next.55 → 7.0.0-next-7.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (38) hide show
  1. package/CHANGELOG.md +426 -0
  2. package/LICENSE +1 -1
  3. package/build/auth.d.ts +7 -26
  4. package/build/auth.js +43 -31
  5. package/build/auth.js.map +1 -1
  6. package/build/index.d.ts +1 -0
  7. package/build/index.js +12 -0
  8. package/build/index.js.map +1 -1
  9. package/build/signature-legacy.d.ts +5 -0
  10. package/build/signature-legacy.js +60 -0
  11. package/build/signature-legacy.js.map +1 -0
  12. package/build/signature.d.ts +4 -0
  13. package/build/signature.js +60 -0
  14. package/build/signature.js.map +1 -0
  15. package/build/types.d.ts +34 -0
  16. package/build/types.js +13 -0
  17. package/build/types.js.map +1 -0
  18. package/build/utils.d.ts +5 -15
  19. package/build/utils.js +19 -9
  20. package/build/utils.js.map +1 -1
  21. package/package.json +13 -12
  22. package/src/auth.ts +66 -59
  23. package/src/index.ts +1 -0
  24. package/src/signature-legacy.ts +66 -0
  25. package/src/signature.ts +66 -0
  26. package/src/types.ts +46 -0
  27. package/src/utils.ts +37 -31
  28. package/test/auth.spec.ts +561 -40
  29. package/test/helper/plugin.ts +8 -0
  30. package/test/partials/plugin/verdaccio-access-ok/access.js +9 -0
  31. package/test/partials/plugin/verdaccio-access-ok/package.json +5 -0
  32. package/test/partials/plugin/verdaccio-adduser/adduser.js +25 -0
  33. package/test/partials/plugin/verdaccio-adduser/package.json +5 -0
  34. package/test/partials/plugin/verdaccio-adduser-legacy/adduser.js +25 -0
  35. package/test/partials/plugin/verdaccio-adduser-legacy/package.json +5 -0
  36. package/test/partials/plugin/verdaccio-change-password/change.js +32 -0
  37. package/test/partials/plugin/verdaccio-change-password/package.json +5 -0
  38. package/test/partials/plugin/verdaccio-fail/fail.js +3 -0
package/CHANGELOG.md CHANGED
@@ -1,5 +1,431 @@
1
1
  # @verdaccio/auth
2
2
 
3
+ ## 7.0.0-next-7.8
4
+
5
+ ### Patch Changes
6
+
7
+ - @verdaccio/core@7.0.0-next-7.8
8
+ - @verdaccio/config@7.0.0-next-7.8
9
+ - @verdaccio/loaders@7.0.0-next-7.8
10
+ - verdaccio-htpasswd@12.0.0-next-7.8
11
+ - @verdaccio/utils@7.0.0-next-7.8
12
+ - @verdaccio/signature@7.0.0-next.3
13
+ - @verdaccio/logger@7.0.0-next-7.8
14
+
15
+ ## 7.0.0-next-7.7
16
+
17
+ ### Patch Changes
18
+
19
+ - @verdaccio/core@7.0.0-next-7.7
20
+ - @verdaccio/config@7.0.0-next-7.7
21
+ - @verdaccio/loaders@7.0.0-next-7.7
22
+ - verdaccio-htpasswd@12.0.0-next-7.7
23
+ - @verdaccio/utils@7.0.0-next-7.7
24
+ - @verdaccio/signature@7.0.0-next.3
25
+ - @verdaccio/logger@7.0.0-next-7.7
26
+
27
+ ## 7.0.0-next.6
28
+
29
+ ### Patch Changes
30
+
31
+ - Updated dependencies [4d96324]
32
+ - @verdaccio/config@7.0.0-next.6
33
+ - @verdaccio/loaders@7.0.0-next.6
34
+ - verdaccio-htpasswd@12.0.0-next.6
35
+ - @verdaccio/signature@7.0.0-next.3
36
+ - @verdaccio/core@7.0.0-next.6
37
+ - @verdaccio/utils@7.0.0-next.6
38
+ - @verdaccio/logger@7.0.0-next.6
39
+
40
+ ## 7.0.0-next.5
41
+
42
+ ### Minor Changes
43
+
44
+ - f047cc8: refactor: auth with legacy sign support
45
+
46
+ ### Patch Changes
47
+
48
+ - Updated dependencies [f047cc8]
49
+ - @verdaccio/core@7.0.0-next.5
50
+ - @verdaccio/signature@7.0.0-next.3
51
+ - @verdaccio/config@7.0.0-next.5
52
+ - @verdaccio/loaders@7.0.0-next.5
53
+ - @verdaccio/logger@7.0.0-next.5
54
+ - verdaccio-htpasswd@12.0.0-next.5
55
+ - @verdaccio/utils@7.0.0-next.5
56
+
57
+ ## 7.0.0-next.4
58
+
59
+ ### Patch Changes
60
+
61
+ - Updated dependencies [312bc100f]
62
+ - @verdaccio/signature@7.0.0-next.2
63
+ - @verdaccio/core@7.0.0-next.4
64
+ - @verdaccio/config@7.0.0-next.4
65
+ - @verdaccio/loaders@7.0.0-next.4
66
+ - verdaccio-htpasswd@12.0.0-next.4
67
+ - @verdaccio/utils@7.0.0-next.4
68
+ - @verdaccio/logger@7.0.0-next.4
69
+
70
+ ## 7.0.0-next.3
71
+
72
+ ### Major Changes
73
+
74
+ - e7ebccb61: update major dependencies, remove old nodejs support
75
+
76
+ ### Patch Changes
77
+
78
+ - Updated dependencies [daceb6d87]
79
+ - Updated dependencies [e7ebccb61]
80
+ - @verdaccio/config@7.0.0-next.3
81
+ - @verdaccio/core@7.0.0-next.3
82
+ - verdaccio-htpasswd@12.0.0-next.3
83
+ - @verdaccio/signature@7.0.0-next.1
84
+ - @verdaccio/utils@7.0.0-next.3
85
+ - @verdaccio/loaders@7.0.0-next.3
86
+ - @verdaccio/logger@7.0.0-next.3
87
+
88
+ ## 7.0.0-next.2
89
+
90
+ ### Patch Changes
91
+
92
+ - @verdaccio/core@7.0.0-next.2
93
+ - @verdaccio/config@7.0.0-next.2
94
+ - @verdaccio/loaders@7.0.0-next.2
95
+ - verdaccio-htpasswd@12.0.0-next.2
96
+ - @verdaccio/utils@7.0.0-next.2
97
+ - @verdaccio/signature@7.0.0-next.0
98
+ - @verdaccio/logger@7.0.0-next.2
99
+
100
+ ## 7.0.0-next.1
101
+
102
+ ### Patch Changes
103
+
104
+ - @verdaccio/core@7.0.0-next.1
105
+ - @verdaccio/config@7.0.0-next.1
106
+ - @verdaccio/loaders@7.0.0-next.1
107
+ - verdaccio-htpasswd@12.0.0-next.1
108
+ - @verdaccio/utils@7.0.0-next.1
109
+ - @verdaccio/signature@7.0.0-next.0
110
+ - @verdaccio/logger@7.0.0-next.1
111
+
112
+ ## 7.0.0-next.0
113
+
114
+ ### Major Changes
115
+
116
+ - feat!: bump to v7
117
+
118
+ ### Patch Changes
119
+
120
+ - Updated dependencies
121
+ - @verdaccio/config@7.0.0-next.0
122
+ - @verdaccio/core@7.0.0-next.0
123
+ - @verdaccio/loaders@7.0.0-next.0
124
+ - @verdaccio/logger@7.0.0-next.0
125
+ - verdaccio-htpasswd@12.0.0-next.0
126
+ - @verdaccio/signature@7.0.0-next.0
127
+ - @verdaccio/utils@7.0.0-next.0
128
+
129
+ ## 6.0.0
130
+
131
+ ### Major Changes
132
+
133
+ - 292c0a37f: feat!: replace deprecated request dependency by got
134
+
135
+ This is a big refactoring of the core, fetching dependencies, improve code, more tests and better stability. This is essential for the next release, will take some time but would allow modularize more the core.
136
+
137
+ ## Notes
138
+
139
+ - Remove deprecated `request` by other `got`, retry improved, custom Agent ( got does not include it built-in)
140
+ - Remove `async` dependency from storage (used by core) it was linked with proxy somehow safe to remove now
141
+ - Refactor with promises instead callback wherever is possible
142
+ - ~Document the API~
143
+ - Improve testing, integration tests
144
+ - Bugfix
145
+ - Clean up old validations
146
+ - Improve performance
147
+
148
+ ## 💥 Breaking changes
149
+
150
+ - Plugin API methods were callbacks based are returning promises, this will break current storage plugins, check documentation for upgrade.
151
+ - Write Tarball, Read Tarball methods parameters change, a new set of options like `AbortController` signals are being provided to the `addAbortSignal` can be internally used with Streams when a request is aborted. eg: `addAbortSignal(signal, fs.createReadStream(pathName));`
152
+ - `@verdaccio/streams` stream abort support is legacy is being deprecated removed
153
+ - Remove AWS and Google Cloud packages for future refactoring [#2574](https://github.com/verdaccio/verdaccio/pull/2574).
154
+
155
+ - 459b6fa72: refactor: search v1 endpoint and local-database
156
+
157
+ - refactor search `api v1` endpoint, improve performance
158
+ - remove usage of `async` dependency https://github.com/verdaccio/verdaccio/issues/1225
159
+ - refactor method storage class
160
+ - create new module `core` to reduce the ammount of modules with utilities
161
+ - use `undici` instead `node-fetch`
162
+ - use `fastify` instead `express` for functional test
163
+
164
+ ### Breaking changes
165
+
166
+ - plugin storage API changes
167
+ - remove old search endpoint (return 404)
168
+ - filter local private packages at plugin level
169
+
170
+ The storage api changes for methods `get`, `add`, `remove` as promise base. The `search` methods also changes and recieves a `query` object that contains all query params from the client.
171
+
172
+ ```ts
173
+ export interface IPluginStorage<T> extends IPlugin {
174
+ add(name: string): Promise<void>;
175
+ remove(name: string): Promise<void>;
176
+ get(): Promise<any>;
177
+ init(): Promise<void>;
178
+ getSecret(): Promise<string>;
179
+ setSecret(secret: string): Promise<any>;
180
+ getPackageStorage(packageInfo: string): IPackageStorage;
181
+ search(query: searchUtils.SearchQuery): Promise<searchUtils.SearchItem[]>;
182
+ saveToken(token: Token): Promise<any>;
183
+ deleteToken(user: string, tokenKey: string): Promise<any>;
184
+ readTokens(filter: TokenFilter): Promise<Token[]>;
185
+ }
186
+ ```
187
+
188
+ - 9fc2e7961: feat(plugins): improve plugin loader
189
+
190
+ ### Changes
191
+
192
+ - Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
193
+ - Avoid config collisions https://github.com/verdaccio/verdaccio/issues/928
194
+ - https://github.com/verdaccio/verdaccio/issues/1394
195
+ - `config.plugins` plugin path validations
196
+ - Updated algorithm for plugin loader.
197
+ - improved documentation (included dev)
198
+
199
+ ## Features
200
+
201
+ - Add scope plugin support to 6.x https://github.com/verdaccio/verdaccio/pull/3227
202
+ - Custom prefix:
203
+
204
+ ```
205
+ // config.yaml
206
+ server:
207
+ pluginPrefix: mycompany
208
+ middleware:
209
+ audit:
210
+ foo: 1
211
+ ```
212
+
213
+ This configuration will look up for `mycompany-audit` instead `Verdaccio-audit`.
214
+
215
+ ## Breaking Changes
216
+
217
+ ### sinopia plugins
218
+
219
+ - `sinopia` fallback support is removed, but can be restored using `pluginPrefix`
220
+
221
+ ### plugin filter
222
+
223
+ - method rename `filter_metadata`->`filterMetadata`
224
+
225
+ ### Plugin constructor does not merge configs anymore https://github.com/verdaccio/verdaccio/issues/928
226
+
227
+ The plugin receives as first argument `config`, which represents the config of the plugin. Example:
228
+
229
+ ```
230
+ // config.yaml
231
+ auth:
232
+ plugin:
233
+ foo: 1
234
+ bar: 2
235
+
236
+ export class Plugin<T> {
237
+ public constructor(config: T, options: PluginOptions) {
238
+ console.log(config);
239
+ // {foo:1, bar: 2}
240
+ }
241
+ }
242
+ ```
243
+
244
+ - 794af76c5: Remove Node 12 support
245
+
246
+ - We need move to the new `undici` and does not support Node.js 12
247
+
248
+ - 10aeb4f13: feat!: experiments config renamed to flags
249
+
250
+ - The `experiments` configuration is renamed to `flags`. The functionality is exactly the same.
251
+
252
+ ```js
253
+ flags: token: false;
254
+ search: false;
255
+ ```
256
+
257
+ - The `self_path` property from the config file is being removed in favor of `config_file` full path.
258
+ - Refactor `config` module, better types and utilities
259
+
260
+ - e367c3f1e: - Replace signature handler for legacy tokens by removing deprecated crypto.createDecipher by createCipheriv
261
+
262
+ - Introduce environment variables for legacy tokens
263
+
264
+ ### Code Improvements
265
+
266
+ - Add debug library for improve developer experience
267
+
268
+ ### Breaking change
269
+
270
+ - The new signature invalidates all previous tokens generated by Verdaccio 4 or previous versions.
271
+ - The secret key must have 32 characters long.
272
+
273
+ ### New environment variables
274
+
275
+ - `VERDACCIO_LEGACY_ALGORITHM`: Allows to define the specific algorithm for the token signature which by default is `aes-256-ctr`
276
+ - `VERDACCIO_LEGACY_ENCRYPTION_KEY`: By default, the token stores in the database, but using this variable allows to get it from memory
277
+
278
+ - 061bfcc8d: feat: standalone registry with no dependencies
279
+
280
+ ## Usage
281
+
282
+ To install a server with no dependencies
283
+
284
+ ```bash
285
+ npm install -g @verdaccio/standalone
286
+ ```
287
+
288
+ with no internet required
289
+
290
+ ```bash
291
+ npm install -g ./tarball.tar.gz
292
+ ```
293
+
294
+ Bundles htpasswd and audit plugins.
295
+
296
+ ### Breaking Change
297
+
298
+ It does not allow anymore the `auth` and `middleware` property at config file empty,
299
+ it will fallback to those plugins by default.
300
+
301
+ ### Minor Changes
302
+
303
+ - 631abe1ac: feat: refactor logger
304
+ - ddb6a2239: feat: signature package
305
+ - b61f762d6: feat: add server rate limit protection to all request
306
+
307
+ To modify custom values, use the server settings property.
308
+
309
+ ```markdown
310
+ server:
311
+
312
+ ## https://www.npmjs.com/package/express-rate-limit#configuration-options
313
+
314
+ rateLimit:
315
+ windowMs: 1000
316
+ max: 10000
317
+ ```
318
+
319
+ The values are intended to be high, if you want to improve security of your server consider
320
+ using different values.
321
+
322
+ - 154b2ecd3: refactor: remove @verdaccio/commons-api in favor @verdaccio/core and remove duplications
323
+ - aa763baec: feat: add typescript project references settings
324
+
325
+ Reading https://ebaytech.berlin/optimizing-multi-package-apps-with-typescript-project-references-d5c57a3b4440 I realized I can use project references to solve the issue to pre-compile modules on develop mode.
326
+
327
+ It allows to navigate (IDE) trough the packages without need compile the packages.
328
+
329
+ Add two `tsconfig`, one using the previous existing configuration that is able to produce declaration files (`tsconfig.build`) and a new one `tsconfig` which is enables [_projects references_](https://www.typescriptlang.org/docs/handbook/project-references.html).
330
+
331
+ - 62c24b632: feat: add passwordValidationRegex property
332
+ - 20c9e43ed: dist tags Implementation on Fastify
333
+ - c9d1af0e5: feat: async bcrypt hash
334
+ - 4b29d715b: chore: move improvements from v5 to v6
335
+
336
+ Migrate improvements form v5 to v6:
337
+
338
+ - https://github.com/verdaccio/verdaccio/pull/3158
339
+ - https://github.com/verdaccio/verdaccio/pull/3151
340
+ - https://github.com/verdaccio/verdaccio/pull/2271
341
+ - https://github.com/verdaccio/verdaccio/pull/2787
342
+ - https://github.com/verdaccio/verdaccio/pull/2791
343
+ - https://github.com/verdaccio/verdaccio/pull/2205
344
+
345
+ ### Patch Changes
346
+
347
+ - 351aeeaa8: fix(deps): @verdaccio/utils should be a prod dep of local-storage
348
+ - a610ef26b: chore: add release step to private regisry on merge changeset pr
349
+ - 34f0f1101: Enable prerelease mode with **changesets**
350
+ - aeff267d9: Refactor htpasswd plugin to use the bcryptjs 'compare' api call instead of 'comparSync'. Add a new configuration value named 'slow_verify_ms' to the htpasswd plugin that when exceeded during password verification will log a warning message.
351
+ - 68ea21214: ESLint Warnings Fixed
352
+
353
+ Related to issue #1461
354
+
355
+ - max-len: most of the sensible max-len errors are fixed
356
+ - no-unused-vars: most of these types of errors are fixed by deleting not needed declarations
357
+ - @typescript-eslint/no-unused-vars: same as above
358
+
359
+ - Updated dependencies [292c0a37f]
360
+ - Updated dependencies [a1986e098]
361
+ - Updated dependencies [974cd8c19]
362
+ - Updated dependencies [a828271d6]
363
+ - Updated dependencies [ef88da3b4]
364
+ - Updated dependencies [43f32687c]
365
+ - Updated dependencies [679c19c1b]
366
+ - Updated dependencies [a3a209b5e]
367
+ - Updated dependencies [459b6fa72]
368
+ - Updated dependencies [9fc2e7961]
369
+ - Updated dependencies [24b9be020]
370
+ - Updated dependencies [794af76c5]
371
+ - Updated dependencies [e75c0a3b9]
372
+ - Updated dependencies [351aeeaa8]
373
+ - Updated dependencies [10aeb4f13]
374
+ - Updated dependencies [631abe1ac]
375
+ - Updated dependencies [9718e0330]
376
+ - Updated dependencies [1b217fd34]
377
+ - Updated dependencies [e367c3f1e]
378
+ - Updated dependencies [a1da11308]
379
+ - Updated dependencies [d167f92e1]
380
+ - Updated dependencies [d2c65da9c]
381
+ - Updated dependencies [00d1d2a17]
382
+ - Updated dependencies [1810ed0d8]
383
+ - Updated dependencies [a610ef26b]
384
+ - Updated dependencies [ddb6a2239]
385
+ - Updated dependencies [e54ec4b5d]
386
+ - Updated dependencies [31d661c7b]
387
+ - Updated dependencies [648575aa4]
388
+ - Updated dependencies [b61f762d6]
389
+ - Updated dependencies [d43894e8f]
390
+ - Updated dependencies [154b2ecd3]
391
+ - Updated dependencies [061bfcc8d]
392
+ - Updated dependencies [aa763baec]
393
+ - Updated dependencies [378e907d5]
394
+ - Updated dependencies [16e38df8a]
395
+ - Updated dependencies [34f0f1101]
396
+ - Updated dependencies [df0da3d69]
397
+ - Updated dependencies [82cb0f2bf]
398
+ - Updated dependencies [dc571aabd]
399
+ - Updated dependencies [b78f35257]
400
+ - Updated dependencies [f859d2b1a]
401
+ - Updated dependencies [2c594910d]
402
+ - Updated dependencies [6c1eb021b]
403
+ - Updated dependencies [62c24b632]
404
+ - Updated dependencies [09753cc1f]
405
+ - Updated dependencies [0a6412ca9]
406
+ - Updated dependencies [d08fe29d9]
407
+ - Updated dependencies [5167bb528]
408
+ - Updated dependencies [f86c31ed0]
409
+ - Updated dependencies [c8a040e69]
410
+ - Updated dependencies [65f88b826]
411
+ - Updated dependencies [aeff267d9]
412
+ - Updated dependencies [b3e8438f6]
413
+ - Updated dependencies [c9d1af0e5]
414
+ - Updated dependencies [730b5d8cc]
415
+ - Updated dependencies [4b29d715b]
416
+ - Updated dependencies [b13a3fefd]
417
+ - Updated dependencies [68ea21214]
418
+ - Updated dependencies [8f43bf17d]
419
+ - Updated dependencies [45c03819e]
420
+ - Updated dependencies [b849128de]
421
+ - @verdaccio/config@6.0.0
422
+ - @verdaccio/core@6.0.0
423
+ - @verdaccio/loaders@6.0.0
424
+ - @verdaccio/logger@6.0.0
425
+ - verdaccio-htpasswd@11.0.0
426
+ - @verdaccio/utils@6.0.0
427
+ - @verdaccio/signature@6.0.0
428
+
3
429
  ## 6.0.0-6-next.55
4
430
 
5
431
  ### Patch Changes
package/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  MIT License
2
2
 
3
- Copyright (c) 2021 Verdaccio contributors
3
+ Copyright (c) 2024 Verdaccio contributors
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/build/auth.d.ts CHANGED
@@ -1,26 +1,7 @@
1
- import { NextFunction, Request, RequestHandler, Response } from 'express';
2
1
  import { VerdaccioError, pluginUtils } from '@verdaccio/core';
3
- import { Callback, Config, JWTSignOptions, Logger, RemoteUser } from '@verdaccio/types';
4
- export interface TokenEncryption {
5
- jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string>;
6
- aesEncrypt(buf: string): string | void;
7
- }
8
- export interface AESPayload {
9
- user: string;
10
- password: string;
11
- }
12
- export interface IAuthMiddleware {
13
- apiJWTmiddleware(): $NextFunctionVer;
14
- webUIJWTmiddleware(): $NextFunctionVer;
15
- }
16
- export type $RequestExtend = Request & {
17
- remote_user?: any;
18
- log: Logger;
19
- };
20
- export type $ResponseExtend = Response & {
21
- cookies?: any;
22
- };
23
- export type $NextFunctionVer = NextFunction & any;
2
+ import '@verdaccio/core';
3
+ import { Callback, Config, JWTSignOptions, RemoteUser } from '@verdaccio/types';
4
+ import { $RequestExtend, $ResponseExtend, IAuthMiddleware, NextFunction, TokenEncryption } from './types';
24
5
  declare class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBasicAuth {
25
6
  config: Config;
26
7
  secret: string;
@@ -43,14 +24,14 @@ declare class Auth implements IAuthMiddleware, TokenEncryption, pluginUtils.IBas
43
24
  * Allow user to publish a package.
44
25
  */
45
26
  allow_publish({ packageName, packageVersion }: pluginUtils.AuthPluginPackage, user: RemoteUser, callback: Callback): void;
46
- apiJWTmiddleware(): RequestHandler;
47
- private _handleJWTAPIMiddleware;
48
- private _handleAESMiddleware;
27
+ apiJWTmiddleware(): any;
28
+ private handleJWTAPIMiddleware;
29
+ private handleAESMiddleware;
49
30
  private _isRemoteUserValid;
50
31
  /**
51
32
  * JWT middleware for WebUI
52
33
  */
53
- webUIJWTmiddleware(): RequestHandler;
34
+ webUIJWTmiddleware(): (req: $RequestExtend, res: $ResponseExtend, _next: NextFunction) => void;
54
35
  jwtEncrypt(user: RemoteUser, signOptions: JWTSignOptions): Promise<string>;
55
36
  /**
56
37
  * Encrypt a string.
package/build/auth.js CHANGED
@@ -16,9 +16,6 @@ var _utils = require("@verdaccio/utils");
16
16
  var _utils2 = require("./utils");
17
17
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
18
18
  const debug = (0, _debug.default)('verdaccio:auth');
19
-
20
- // remove
21
-
22
19
  class Auth {
23
20
  constructor(config) {
24
21
  this.config = config;
@@ -146,23 +143,29 @@ class Auth {
146
143
  const plugins = this.plugins.slice(0);
147
144
  debug('add user %o', user);
148
145
  (function next() {
146
+ let method = 'adduser';
149
147
  const plugin = plugins.shift();
150
- if (typeof plugin.adduser !== 'function') {
148
+ // @ts-expect-error future major (7.x) should remove this section
149
+ if (typeof plugin.adduser === 'undefined' && typeof plugin.add_user === 'function') {
150
+ method = 'add_user';
151
+ _core.warningUtils.emit(_core.warningUtils.Codes.VERWAR006);
152
+ }
153
+ // @ts-ignore
154
+ if (typeof plugin[method] !== 'function') {
151
155
  next();
152
156
  } else {
153
- // @ts-expect-error future major (7.x) should remove this section
154
- if (typeof plugin.adduser === 'undefined' && typeof plugin.add_user === 'function') {
155
- throw _core.errorUtils.getInternalError('add_user method not longer supported, rename to adduser');
156
- }
157
- plugin.adduser(user, password, function (err, ok) {
157
+ // TODO: replace by adduser whenever add_user deprecation method has been removed
158
+ // @ts-ignore
159
+ plugin[method](user, password, function (err, ok) {
158
160
  if (err) {
159
- debug('the user %o could not being added. Error: %o', user, err === null || err === void 0 ? void 0 : err.message);
161
+ debug('the user %o could not being added. Error: %o', user, err === null || err === void 0 ? void 0 : err.message);
160
162
  return cb(err);
161
163
  }
162
164
  if (ok) {
163
165
  debug('the user %o has been added', user);
164
166
  return self.authenticate(user, password, cb);
165
167
  }
168
+ debug('user could not be added, skip to next auth plugin');
166
169
  next();
167
170
  });
168
171
  }
@@ -201,7 +204,6 @@ class Auth {
201
204
  });
202
205
  })();
203
206
  }
204
-
205
207
  allow_unpublish({
206
208
  packageName,
207
209
  packageVersion
@@ -212,11 +214,10 @@ class Auth {
212
214
  }, (0, _utils.getMatchedPackagesSpec)(packageName, this.config.packages));
213
215
  debug('allow unpublish for %o', packageName);
214
216
  for (const plugin of this.plugins) {
215
- if (_lodash.default.isNil(plugin) || (0, _utils.isFunction)(plugin.allow_unpublish) === false) {
217
+ if (typeof (plugin === null || plugin === void 0 ? void 0 : plugin.allow_unpublish) !== 'function') {
216
218
  debug('allow unpublish for %o plugin does not implement allow_unpublish', packageName);
217
219
  continue;
218
220
  } else {
219
- // @ts-ignore
220
221
  plugin.allow_unpublish(user, pkg, (err, ok) => {
221
222
  if (err) {
222
223
  debug('forbidden publish for %o, it will fallback on unpublish permissions', packageName);
@@ -224,9 +225,10 @@ class Auth {
224
225
  }
225
226
  if (_lodash.default.isNil(ok) === true) {
226
227
  debug('bypass unpublish for %o, publish will handle the access', packageName);
227
- // @ts-ignore
228
- // eslint-disable-next-line
229
- return this.allow_publish(...arguments);
228
+ return this.allow_publish({
229
+ packageName,
230
+ packageVersion
231
+ }, user, callback);
230
232
  }
231
233
  if (ok) {
232
234
  debug('allowed unpublish for %o', packageName);
@@ -270,7 +272,6 @@ class Auth {
270
272
  });
271
273
  })();
272
274
  }
273
-
274
275
  apiJWTmiddleware() {
275
276
  debug('jwt middleware');
276
277
  const plugins = this.plugins.slice(0);
@@ -283,8 +284,6 @@ class Auth {
283
284
  return plugin.apiJWTmiddleware(helpers);
284
285
  }
285
286
  }
286
-
287
- // @ts-ignore
288
287
  return (req, res, _next) => {
289
288
  req.pause();
290
289
  const next = function (err) {
@@ -298,10 +297,12 @@ class Auth {
298
297
  }
299
298
  return _next();
300
299
  };
301
- if (this._isRemoteUserValid(req.remote_user)) {
302
- debug('jwt has a valid authentication header');
303
- return next();
304
- }
300
+
301
+ // FUTURE: disabled, not removed yet but seems unreacable code
302
+ // if (this._isRemoteUserValid(req.remote_user)) {
303
+ // debug('jwt has a valid authentication header');
304
+ // return next();
305
+ // }
305
306
 
306
307
  // in case auth header does not exist we return anonymous function
307
308
  const remoteUser = (0, _config.createAnonymousRemoteUser)();
@@ -324,14 +325,14 @@ class Auth {
324
325
  } = this.config;
325
326
  if ((0, _utils2.isAESLegacy)(security)) {
326
327
  debug('api middleware using legacy auth token');
327
- this._handleAESMiddleware(req, security, secret, authorization, next);
328
+ this.handleAESMiddleware(req, security, secret, authorization, next);
328
329
  } else {
329
330
  debug('api middleware using JWT auth token');
330
- this._handleJWTAPIMiddleware(req, security, secret, authorization, next);
331
+ this.handleJWTAPIMiddleware(req, security, secret, authorization, next);
331
332
  }
332
333
  };
333
334
  }
334
- _handleJWTAPIMiddleware(req, security, secret, authorization, next) {
335
+ handleJWTAPIMiddleware(req, security, secret, authorization, next) {
335
336
  debug('handle JWT api middleware');
336
337
  const {
337
338
  scheme,
@@ -372,11 +373,12 @@ class Auth {
372
373
  }
373
374
  }
374
375
  }
375
- _handleAESMiddleware(req, security, secret, authorization, next) {
376
+ handleAESMiddleware(req, security, secret, authorization, next) {
377
+ var _this$config2;
376
378
  debug('handle legacy api middleware');
377
379
  debug('api middleware secret %o', typeof secret === 'string');
378
380
  debug('api middleware authorization %o', typeof authorization === 'string');
379
- const credentials = (0, _utils2.getMiddlewareCredentials)(security, secret, authorization);
381
+ const credentials = (0, _utils2.getMiddlewareCredentials)(security, secret, authorization, (_this$config2 = this.config) === null || _this$config2 === void 0 ? void 0 : _this$config2.getEnhancedLegacySignature());
380
382
  debug('api middleware credentials %o', credentials === null || credentials === void 0 ? void 0 : credentials.name);
381
383
  if (credentials) {
382
384
  const {
@@ -409,7 +411,6 @@ class Auth {
409
411
  * JWT middleware for WebUI
410
412
  */
411
413
  webUIJWTmiddleware() {
412
- // @ts-ignore
413
414
  return (req, res, _next) => {
414
415
  if (this._isRemoteUserValid(req.remote_user)) {
415
416
  return _next();
@@ -418,7 +419,7 @@ class Auth {
418
419
  const next = err => {
419
420
  req.resume();
420
421
  if (err) {
421
- // req.remote_user.error = err.message;
422
+ req.remote_user.error = err.message;
422
423
  res.status(err.statusCode).send(err.message);
423
424
  }
424
425
  return _next();
@@ -476,7 +477,18 @@ class Auth {
476
477
  * Encrypt a string.
477
478
  */
478
479
  aesEncrypt(value) {
479
- return (0, _signature.aesEncrypt)(value, this.secret);
480
+ var _this$config3;
481
+ // enhancedLegacySignature enables modern aes192 algorithm signature
482
+ if ((_this$config3 = this.config) !== null && _this$config3 !== void 0 && _this$config3.getEnhancedLegacySignature()) {
483
+ debug('signing with enhaced aes legacy');
484
+ const token = (0, _signature.aesEncrypt)(value, this.secret);
485
+ return token;
486
+ } else {
487
+ debug('signing with enhaced aes deprecated legacy');
488
+ // deprecated aes (legacy) signature, only must be used for legacy version
489
+ const token = (0, _signature.aesEncryptDeprecated)(Buffer.from(value), this.secret).toString('base64');
490
+ return token;
491
+ }
480
492
  }
481
493
  }
482
494
  exports.Auth = Auth;