@celljs/security 4.0.0 → 4.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/README.md +111 -1
  2. package/cell.yml +1 -2
  3. package/esm/node/access/access-protocol.d.ts +0 -4
  4. package/esm/node/access/access-protocol.js +0 -1
  5. package/esm/node/access/access-protocol.js.map +1 -1
  6. package/esm/node/access/index.d.ts +0 -1
  7. package/esm/node/access/index.js +0 -1
  8. package/esm/node/access/index.js.map +1 -1
  9. package/esm/node/access/policy-provider.js +2 -2
  10. package/esm/node/access/policy-resolver.d.ts +2 -1
  11. package/esm/node/access/policy-resolver.js +4 -4
  12. package/esm/node/access/policy-resolver.js.map +1 -1
  13. package/esm/node/access/resource-name-resolver.d.ts +3 -0
  14. package/esm/node/access/resource-name-resolver.js +10 -5
  15. package/esm/node/access/resource-name-resolver.js.map +1 -1
  16. package/esm/node/authentication/authentication-provider.d.ts +8 -0
  17. package/esm/node/authentication/authentication-provider.js +29 -2
  18. package/esm/node/authentication/authentication-provider.js.map +1 -1
  19. package/esm/node/authentication/authentication-success-handler.js +4 -0
  20. package/esm/node/authentication/authentication-success-handler.js.map +1 -1
  21. package/esm/node/crypto/keygen/base64-string-key-generator.d.ts +4 -0
  22. package/esm/node/crypto/keygen/base64-string-key-generator.js +6 -4
  23. package/esm/node/crypto/keygen/base64-string-key-generator.js.map +1 -1
  24. package/esm/node/crypto/password/password-encoder.d.ts +40 -3
  25. package/esm/node/crypto/password/password-encoder.js +80 -24
  26. package/esm/node/crypto/password/password-encoder.js.map +1 -1
  27. package/esm/node/crypto/password/password-protocol.d.ts +6 -0
  28. package/esm/node/module.d.ts +0 -1
  29. package/esm/node/module.js +0 -1
  30. package/esm/node/module.js.map +1 -1
  31. package/esm/node/user/user-protocol.d.ts +5 -0
  32. package/esm/node/user/user-service.d.ts +14 -0
  33. package/esm/node/user/user-service.js +33 -2
  34. package/esm/node/user/user-service.js.map +1 -1
  35. package/lib/node/access/access-protocol.d.ts +0 -4
  36. package/lib/node/access/access-protocol.d.ts.map +1 -1
  37. package/lib/node/access/access-protocol.js +1 -2
  38. package/lib/node/access/access-protocol.js.map +1 -1
  39. package/lib/node/access/expression-resolvers.spec.d.ts +2 -0
  40. package/lib/node/access/expression-resolvers.spec.d.ts.map +1 -0
  41. package/lib/node/access/expression-resolvers.spec.js +57 -0
  42. package/lib/node/access/expression-resolvers.spec.js.map +1 -0
  43. package/lib/node/access/index.d.ts +0 -1
  44. package/lib/node/access/index.d.ts.map +1 -1
  45. package/lib/node/access/index.js +0 -1
  46. package/lib/node/access/index.js.map +1 -1
  47. package/lib/node/access/policy-resolver.d.ts +2 -1
  48. package/lib/node/access/policy-resolver.d.ts.map +1 -1
  49. package/lib/node/access/policy-resolver.js +1 -1
  50. package/lib/node/access/policy-resolver.js.map +1 -1
  51. package/lib/node/access/resource-name-resolver.d.ts +3 -0
  52. package/lib/node/access/resource-name-resolver.d.ts.map +1 -1
  53. package/lib/node/access/resource-name-resolver.js +9 -3
  54. package/lib/node/access/resource-name-resolver.js.map +1 -1
  55. package/lib/node/authentication/authentication-provider.d.ts +8 -0
  56. package/lib/node/authentication/authentication-provider.d.ts.map +1 -1
  57. package/lib/node/authentication/authentication-provider.js +29 -1
  58. package/lib/node/authentication/authentication-provider.js.map +1 -1
  59. package/lib/node/authentication/authentication-success-handler.d.ts.map +1 -1
  60. package/lib/node/authentication/authentication-success-handler.js +4 -0
  61. package/lib/node/authentication/authentication-success-handler.js.map +1 -1
  62. package/lib/node/authentication/basic-authentication.spec.d.ts +2 -0
  63. package/lib/node/authentication/basic-authentication.spec.d.ts.map +1 -0
  64. package/lib/node/authentication/basic-authentication.spec.js +65 -0
  65. package/lib/node/authentication/basic-authentication.spec.js.map +1 -0
  66. package/lib/node/crypto/keygen/base64-string-key-generator.d.ts +4 -0
  67. package/lib/node/crypto/keygen/base64-string-key-generator.d.ts.map +1 -1
  68. package/lib/node/crypto/keygen/base64-string-key-generator.js +6 -3
  69. package/lib/node/crypto/keygen/base64-string-key-generator.js.map +1 -1
  70. package/lib/node/crypto/keygen/base64-string-key-generator.spec.d.ts +2 -0
  71. package/lib/node/crypto/keygen/base64-string-key-generator.spec.d.ts.map +1 -0
  72. package/lib/node/crypto/keygen/base64-string-key-generator.spec.js +15 -0
  73. package/lib/node/crypto/keygen/base64-string-key-generator.spec.js.map +1 -0
  74. package/lib/node/crypto/password/password-encoder.d.ts +40 -3
  75. package/lib/node/crypto/password/password-encoder.d.ts.map +1 -1
  76. package/lib/node/crypto/password/password-encoder.js +80 -23
  77. package/lib/node/crypto/password/password-encoder.js.map +1 -1
  78. package/lib/node/crypto/password/password-encoder.spec.d.ts +2 -0
  79. package/lib/node/crypto/password/password-encoder.spec.d.ts.map +1 -0
  80. package/lib/node/crypto/password/password-encoder.spec.js +147 -0
  81. package/lib/node/crypto/password/password-encoder.spec.js.map +1 -0
  82. package/lib/node/crypto/password/password-protocol.d.ts +6 -0
  83. package/lib/node/crypto/password/password-protocol.d.ts.map +1 -1
  84. package/lib/node/module.d.ts +0 -1
  85. package/lib/node/module.d.ts.map +1 -1
  86. package/lib/node/module.js +0 -1
  87. package/lib/node/module.js.map +1 -1
  88. package/lib/node/user/user-protocol.d.ts +5 -0
  89. package/lib/node/user/user-protocol.d.ts.map +1 -1
  90. package/lib/node/user/user-service.d.ts +14 -0
  91. package/lib/node/user/user-service.d.ts.map +1 -1
  92. package/lib/node/user/user-service.js +33 -2
  93. package/lib/node/user/user-service.js.map +1 -1
  94. package/lib/node/user/user-service.spec.d.ts +2 -0
  95. package/lib/node/user/user-service.spec.d.ts.map +1 -0
  96. package/lib/node/user/user-service.spec.js +44 -0
  97. package/lib/node/user/user-service.spec.js.map +1 -0
  98. package/package.json +7 -13
  99. package/src/node/access/access-protocol.ts +0 -5
  100. package/src/node/access/expression-resolvers.spec.ts +37 -0
  101. package/src/node/access/index.ts +0 -1
  102. package/src/node/access/policy-resolver.ts +2 -2
  103. package/src/node/access/resource-name-resolver.ts +10 -4
  104. package/src/node/authentication/authentication-provider.ts +26 -2
  105. package/src/node/authentication/authentication-success-handler.ts +4 -0
  106. package/src/node/authentication/basic-authentication.spec.ts +68 -0
  107. package/src/node/crypto/keygen/base64-string-key-generator.spec.ts +13 -0
  108. package/src/node/crypto/keygen/base64-string-key-generator.ts +6 -3
  109. package/src/node/crypto/password/password-encoder.spec.ts +162 -0
  110. package/src/node/crypto/password/password-encoder.ts +99 -21
  111. package/src/node/crypto/password/password-protocol.ts +6 -0
  112. package/src/node/module.ts +0 -1
  113. package/src/node/user/user-protocol.ts +5 -0
  114. package/src/node/user/user-service.spec.ts +46 -0
  115. package/src/node/user/user-service.ts +32 -2
  116. package/esm/node/access/jexl-engine-provider.d.ts +0 -5
  117. package/esm/node/access/jexl-engine-provider.js +0 -22
  118. package/esm/node/access/jexl-engine-provider.js.map +0 -1
  119. package/lib/node/access/jexl-engine-provider.d.ts +0 -6
  120. package/lib/node/access/jexl-engine-provider.d.ts.map +0 -1
  121. package/lib/node/access/jexl-engine-provider.js +0 -25
  122. package/lib/node/access/jexl-engine-provider.js.map +0 -1
  123. package/src/node/access/jexl-engine-provider.ts +0 -18
@@ -0,0 +1,147 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const bun_test_1 = require("bun:test");
4
+ const chai_1 = require("chai");
5
+ const password_encoder_1 = require("./password-encoder");
6
+ const authentication_provider_1 = require("../../authentication/authentication-provider");
7
+ /**
8
+ * Golden vectors: legacy hashes made by the crypto-js implementation of this encoder (crypto-js 4.2.0, main 6a87acfc0)
9
+ * for fixed salts, with cell-refactor/stage1/t10-password-vectors/generate.cjs. Stored hashes like these must keep matching.
10
+ */
11
+ const LEGACY = [
12
+ { options: { "encodeHashAsBase64": true }, password: "123456", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZjA1NjVhMGQzZmI4ZDlhY2U3ZmY5YTY4OTE1YTFiOTll" },
13
+ { options: { "encodeHashAsBase64": true }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxODE5NWZjMWI0ODk3YjBlMDBjMjU1YTVjNjcxZTUxOGIx" },
14
+ { options: { "encodeHashAsBase64": true }, password: "中文密码🔐", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMDc2MjIyMDk5NzdkMDRjMzdkY2JlYjBhZjNkNjg2NDQ3" },
15
+ { options: { "encodeHashAsBase64": false }, password: "123456", salt: "a1b2c3d4e5f60718", encoded: "a1b2c3d4e5f60718c1ef95056e13cce639b1b172f002e7ae" },
16
+ { options: { "encodeHashAsBase64": false }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "ffffffff00000000", encoded: "ffffffff0000000018bbdc72579e0a3093f5f6ea06b82033" },
17
+ { options: { "encodeHashAsBase64": false }, password: "中文密码🔐", salt: "0123456789abcdef", encoded: "0123456789abcdef066fc4596441dd6bdb884678496ef9fc" },
18
+ { options: { "encodeHashAsBase64": true, "secret": "s3cr3t" }, password: "123456", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMDg4Zjc0NzAyM2E1NjE1NWVjNzU1NzlkZTUxNmQ1Mjhi" },
19
+ { options: { "encodeHashAsBase64": true, "secret": "s3cr3t" }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZjY4ZGI3ZWU2NGFmMjVhNjdkNWU0MWU0ZTFlZTEyZGY0" },
20
+ { options: { "encodeHashAsBase64": true, "secret": "s3cr3t" }, password: "中文密码🔐", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxODAxYTBjZDMxYTgxZmE0N2UyMDQxNWUzNDJiOTg5ZGMx" },
21
+ { options: { "encodeHashAsBase64": true, "secret": 123456 }, password: "123456", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZjZkNGE0MGRkMDU4MmRmMGI1MjVkM2MxZjE0NjVkNjY5" },
22
+ { options: { "encodeHashAsBase64": true, "secret": 123456 }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxOGM5ZWY5NjgzNzExMDUwNWUwNWVlYzlkYTRhMjkyYmZj" },
23
+ { options: { "encodeHashAsBase64": true, "secret": 123456 }, password: "中文密码🔐", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMDFkZWZlYjdjYjkxNTNlMzk1YWFiZGUzNWM3NDBjNjg0" },
24
+ { options: { "encodeHashAsBase64": false, "secret": "密钥🔑", "iterations": 1000 }, password: "123456", salt: "a1b2c3d4e5f60718", encoded: "a1b2c3d4e5f6071822b7276a5d78c8e4111547a26aada7f1" },
25
+ { options: { "encodeHashAsBase64": false, "secret": "密钥🔑", "iterations": 1000 }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "ffffffff00000000", encoded: "ffffffff0000000068f9b165d52e8bc615b2ebcc6654d149" },
26
+ { options: { "encodeHashAsBase64": false, "secret": "密钥🔑", "iterations": 1000 }, password: "中文密码🔐", salt: "0123456789abcdef", encoded: "0123456789abcdef27ac13cc586b34fbf24700ef8f5cd54b" },
27
+ { options: { "encodeHashAsBase64": true, "iterations": 1, "keySize": 8 }, password: "123456", salt: "ffffffff00000000", encoded: "ZmZmZmZmZmYwMDAwMDAwMGYyMjdkNzNkODMwNWU3OWZjOGM2YTc1ZjdmZjZhMGRhNDgwMWFlYTZlZjcxYWM4Mjc0MmIyYzlhNTQyZjJhM2Q=" },
28
+ { options: { "encodeHashAsBase64": true, "iterations": 1, "keySize": 8 }, password: "P@ss w0rd!#$%^&*()_+-=[]{}|;:'\",.<>/?`~\\", salt: "0123456789abcdef", encoded: "MDEyMzQ1Njc4OWFiY2RlZmFmZGEwNTA0YzA5YjJlYjBjNTExOTA3ZWRlZThiNzRmODVhNGU0NWZjODg0ZmZjOGU5NDA3Y2JiNTljZDA4ZWQ=" },
29
+ { options: { "encodeHashAsBase64": true, "iterations": 1, "keySize": 8 }, password: "中文密码🔐", salt: "a1b2c3d4e5f60718", encoded: "YTFiMmMzZDRlNWY2MDcxOGI2MTgyZGI1YWFkOThjMDNmOGRlZDllYTNkYjUzNTVlM2YwZDhlMmU0NDQ3ZTE5ZjY5NDBjOWUzOTRlOTE1ODM=" },
30
+ ];
31
+ class TestEncoder extends password_encoder_1.Pbkdf2PasswordEncoder {
32
+ constructor(options = {}, newIterations = 1000) {
33
+ super();
34
+ this.newIterations = newIterations;
35
+ Object.defineProperty(this, 'options', { value: options });
36
+ }
37
+ get iterations() {
38
+ return this.newIterations;
39
+ }
40
+ /** What the crypto-js implementation stored for a fixed salt. */
41
+ async legacyHash(rawPassword, salt) {
42
+ var _a;
43
+ const text = await this.legacyEncode(rawPassword, salt);
44
+ return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.encodeHashAsBase64) ? Buffer.from(text, 'utf8').toString('base64') : text;
45
+ }
46
+ }
47
+ const name = (v) => `${JSON.stringify(v.options)} ${JSON.stringify(v.password)}`;
48
+ (0, bun_test_1.describe)('Pbkdf2PasswordEncoder', () => {
49
+ (0, bun_test_1.describe)('legacy hashes of the crypto-js implementation', () => {
50
+ for (const vector of LEGACY) {
51
+ (0, bun_test_1.it)(`match, and a wrong password does not: ${name(vector)}`, async () => {
52
+ const encoder = new TestEncoder(vector.options);
53
+ (0, chai_1.expect)(await encoder.matches(vector.password, vector.encoded)).to.equal(true);
54
+ (0, chai_1.expect)(await encoder.matches(`${vector.password}x`, vector.encoded)).to.equal(false);
55
+ (0, chai_1.expect)(await encoder.matches('', vector.encoded)).to.equal(false);
56
+ });
57
+ (0, bun_test_1.it)(`are reproduced byte for byte: ${name(vector)}`, async () => {
58
+ (0, chai_1.expect)(await new TestEncoder(vector.options).legacyHash(vector.password, vector.salt)).to.equal(vector.encoded);
59
+ });
60
+ }
61
+ (0, bun_test_1.it)('need an upgrade', () => {
62
+ for (const vector of LEGACY) {
63
+ (0, chai_1.expect)(new TestEncoder(vector.options).needsUpgrade(vector.encoded)).to.equal(true);
64
+ }
65
+ });
66
+ (0, bun_test_1.it)('only match with the secret they were made with (none means the text "undefined")', async () => {
67
+ const vector = LEGACY.find(v => v.options.secret === undefined && v.options.encodeHashAsBase64);
68
+ (0, chai_1.expect)(await new TestEncoder({ ...vector.options, secret: 'undefined' }).matches(vector.password, vector.encoded)).to.equal(true);
69
+ (0, chai_1.expect)(await new TestEncoder({ ...vector.options, secret: 'pepper' }).matches(vector.password, vector.encoded)).to.equal(false);
70
+ });
71
+ });
72
+ (0, bun_test_1.describe)('new hashes', () => {
73
+ (0, bun_test_1.it)('record their parameters and use a fresh salt', async () => {
74
+ const encoder = new TestEncoder({ encodeHashAsBase64: true });
75
+ const a = await encoder.encode('secret');
76
+ const b = await encoder.encode('secret');
77
+ (0, chai_1.expect)(a).to.match(/^pbkdf2-sha256\$1000\$[A-Za-z0-9+/]{22}==\$[A-Za-z0-9+/]{43}=$/);
78
+ (0, chai_1.expect)(a).to.not.equal(b);
79
+ });
80
+ (0, bun_test_1.it)('match the right password only', async () => {
81
+ const encoder = new TestEncoder();
82
+ const hash = await encoder.encode('中文密码🔐');
83
+ (0, chai_1.expect)(await encoder.matches('中文密码🔐', hash)).to.equal(true);
84
+ (0, chai_1.expect)(await encoder.matches('中文密码', hash)).to.equal(false);
85
+ });
86
+ (0, bun_test_1.it)('do not depend on encodeHashAsBase64, and a missing secret is not the text "undefined"', async () => {
87
+ const hash = await new TestEncoder({ encodeHashAsBase64: true }).encode('secret');
88
+ (0, chai_1.expect)(await new TestEncoder({ encodeHashAsBase64: false }).matches('secret', hash)).to.equal(true);
89
+ (0, chai_1.expect)(await new TestEncoder({ secret: 'undefined' }).matches('secret', hash)).to.equal(false);
90
+ });
91
+ (0, bun_test_1.it)('mix the secret in', async () => {
92
+ const hash = await new TestEncoder({ secret: 'pepper' }).encode('secret');
93
+ (0, chai_1.expect)(await new TestEncoder({ secret: 'pepper' }).matches('secret', hash)).to.equal(true);
94
+ (0, chai_1.expect)(await new TestEncoder({ secret: 'other' }).matches('secret', hash)).to.equal(false);
95
+ (0, chai_1.expect)(await new TestEncoder().matches('secret', hash)).to.equal(false);
96
+ });
97
+ (0, bun_test_1.it)('check with the iterations they record, and need an upgrade when that is fewer than new hashes get', async () => {
98
+ const old = await new TestEncoder({}, 1000).encode('secret');
99
+ const encoder = new TestEncoder({}, 2000);
100
+ (0, chai_1.expect)(await encoder.matches('secret', old)).to.equal(true);
101
+ (0, chai_1.expect)(encoder.needsUpgrade(old)).to.equal(true);
102
+ (0, chai_1.expect)(encoder.needsUpgrade(await encoder.encode('secret'))).to.equal(false);
103
+ });
104
+ (0, bun_test_1.it)('get 600000 iterations by default', async () => {
105
+ (0, chai_1.expect)(await new password_encoder_1.Pbkdf2PasswordEncoder().encode('secret')).to.match(/^pbkdf2-sha256\$600000\$/);
106
+ });
107
+ });
108
+ (0, bun_test_1.it)('rejects malformed hashes instead of throwing', async () => {
109
+ for (const options of [{ encodeHashAsBase64: true }, { encodeHashAsBase64: false }]) {
110
+ const encoder = new TestEncoder(options);
111
+ for (const hash of ['', 'abc', '!!!!', '0123456789abcdef', 'pbkdf2-sha256$x$a$b', 'pbkdf2-sha256$1000$$', 'pbkdf2-sha256$1000$YQ==$YQ==',
112
+ 'pbkdf2-sha256$1000$YQ==$YQ==$x', undefined, null]) {
113
+ (0, chai_1.expect)(await encoder.matches('secret', hash), String(hash)).to.equal(false);
114
+ }
115
+ }
116
+ });
117
+ (0, bun_test_1.describe)('upgradePasswordHash', () => {
118
+ const legacy = LEGACY.find(v => v.options.encodeHashAsBase64 && v.options.secret === undefined);
119
+ const user = () => ({ username: 'tom', password: legacy.encoded });
120
+ const logger = (warnings) => ({ warn: (m) => warnings.push(m) });
121
+ (0, bun_test_1.it)('stores a new hash of a legacy one through UserService.updatePassword', async () => {
122
+ const encoder = new TestEncoder(legacy.options);
123
+ const stored = [];
124
+ const service = { load: async () => user(), updatePassword: async (_, hash) => { stored.push(hash); } };
125
+ await (0, authentication_provider_1.upgradePasswordHash)(encoder, service, user(), legacy.password, logger([]));
126
+ (0, chai_1.expect)(stored).to.have.length(1);
127
+ (0, chai_1.expect)(encoder.needsUpgrade(stored[0])).to.equal(false);
128
+ (0, chai_1.expect)(await encoder.matches(legacy.password, stored[0])).to.equal(true);
129
+ });
130
+ (0, bun_test_1.it)('does nothing when the hash is current or the UserService cannot store passwords', async () => {
131
+ const encoder = new TestEncoder(legacy.options);
132
+ const stored = [];
133
+ const service = { load: async () => user(), updatePassword: async (_, hash) => { stored.push(hash); } };
134
+ await (0, authentication_provider_1.upgradePasswordHash)(encoder, service, { ...user(), password: await encoder.encode(legacy.password) }, legacy.password, logger([]));
135
+ await (0, authentication_provider_1.upgradePasswordHash)(encoder, { load: async () => user() }, user(), legacy.password, logger([]));
136
+ (0, chai_1.expect)(stored).to.have.length(0);
137
+ });
138
+ (0, bun_test_1.it)('logs a failure to store instead of failing the login', async () => {
139
+ const warnings = [];
140
+ const service = { load: async () => user(), updatePassword: async () => { throw new Error('read-only'); } };
141
+ await (0, authentication_provider_1.upgradePasswordHash)(new TestEncoder(legacy.options), service, user(), legacy.password, logger(warnings));
142
+ (0, chai_1.expect)(warnings).to.have.length(1);
143
+ (0, chai_1.expect)(warnings[0]).to.include('read-only');
144
+ });
145
+ });
146
+ });
147
+ //# sourceMappingURL=password-encoder.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-encoder.spec.js","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-encoder.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,yDAAyF;AACzF,0FAAmF;AAEnF;;;GAGG;AACH,MAAM,MAAM,GAAiG;IACzG,EAAE,OAAO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E;YAClE,MAAM,QAAQ,GAAa,EAAE,CAAC;YAC9B,MAAM,OAAO,GAAG,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,IAAI,EAAE,EAAE,cAAc,EAAE,KAAK,IAAI,EAAE,GAAG,MAAM,IAAI,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;YAC5G,MAAM,IAAA,6CAAmB,EAAC,IAAI,WAAW,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,EAAE,MAAM,CAAC,QAAQ,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;YAC/G,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;YACnC,IAAA,aAAM,EAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,CAAC,WAAW,CAAC,CAAC;QAChD,CAAC,CAAC,CAAC;IACP,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
@@ -2,5 +2,11 @@ export declare const PasswordEncoder: unique symbol;
2
2
  export interface PasswordEncoder {
3
3
  encode(rawPassword: string): Promise<string>;
4
4
  matches(rawPassword: string, encodedPassword: string): Promise<boolean>;
5
+ /**
6
+ * Whether a stored hash should be replaced by `encode()` of the password once it matched (a legacy
7
+ * format, or weaker parameters than new hashes get). Login does so when the UserService can
8
+ * store passwords (`UserService.updatePassword`).
9
+ */
10
+ needsUpgrade?(encodedPassword: string): boolean;
5
11
  }
6
12
  //# sourceMappingURL=password-protocol.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"password-protocol.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,eAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC5B,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3E"}
1
+ {"version":3,"file":"password-protocol.d.ts","sourceRoot":"","sources":["../../../../src/node/crypto/password/password-protocol.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,eAAe,eAA4B,CAAC;AAEzD,MAAM,WAAW,eAAe;IAC5B,MAAM,CAAC,WAAW,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAC7C,OAAO,CAAC,WAAW,EAAE,MAAM,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IACxE;;;;OAIG;IACH,YAAY,CAAC,CAAC,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC;CACnD"}
@@ -1,4 +1,3 @@
1
- import 'reflect-metadata';
2
1
  import './index';
3
2
  declare const _default: import("inversify").interfaces.ContainerModule;
4
3
  export default _default;
@@ -1 +1 @@
1
- {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AAAA,OAAO,kBAAkB,CAAC;AAE1B,OAAO,SAAS,CAAC"}
1
+ {"version":3,"file":"module.d.ts","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,CAAC"}
@@ -1,6 +1,5 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- require("reflect-metadata");
4
3
  const core_1 = require("@celljs/core");
5
4
  require("./index");
6
5
  exports.default = (0, core_1.autoBind)();
@@ -1 +1 @@
1
- {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,4BAA0B;AAC1B,uCAAwC;AACxC,mBAAiB;kBAEF,IAAA,eAAQ,GAAE"}
1
+ {"version":3,"file":"module.js","sourceRoot":"","sources":["../../src/node/module.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,mBAAiB;kBAEF,IAAA,eAAQ,GAAE"}
@@ -5,6 +5,11 @@ export declare const UserMapper: unique symbol;
5
5
  export declare const USER_MIDDLEWARE_PRIORITY: number;
6
6
  export interface UserService<R, U extends User> {
7
7
  load(userRequest: R): Promise<U>;
8
+ /**
9
+ * Stores a new password hash of `user`. Optional: when a service has it, a login whose stored hash
10
+ * `PasswordEncoder.needsUpgrade()` saves the hash in the current format.
11
+ */
12
+ updatePassword?(user: U, encodedPassword: string): Promise<void>;
8
13
  }
9
14
  export interface UserChecker {
10
15
  check(user: User): Promise<void>;
@@ -1 +1 @@
1
- {"version":3,"file":"user-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,UAAU,eAAuB,CAAC;AAE/C,eAAO,MAAM,wBAAwB,QAA6C,CAAC;AAEnF,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,IAAI;IAC1C,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACvB,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC"}
1
+ {"version":3,"file":"user-protocol.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-protocol.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,cAAc,CAAC;AAGpC,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,WAAW,eAAwB,CAAC;AACjD,eAAO,MAAM,UAAU,eAAuB,CAAC;AAE/C,eAAO,MAAM,wBAAwB,QAA6C,CAAC;AAEnF,MAAM,WAAW,WAAW,CAAC,CAAC,EAAE,CAAC,SAAS,IAAI;IAC1C,IAAI,CAAC,WAAW,EAAE,CAAC,GAAG,OAAO,CAAC,CAAC,CAAC,CAAC;IACjC;;;OAGG;IACH,cAAc,CAAC,CAAC,IAAI,EAAE,CAAC,EAAE,eAAe,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpE;AAED,MAAM,WAAW,WAAW;IACxB,KAAK,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC;AAED,MAAM,WAAW,UAAU;IACvB,GAAG,CAAC,IAAI,EAAE,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAClC"}
@@ -1,7 +1,21 @@
1
1
  import { UserService } from './user-protocol';
2
+ import { Logger, ApplicationLifecycle, Application } from '@celljs/core';
2
3
  import { User } from '../../common';
4
+ /** The one user of `cell.security.username` / `password`, when they are configured. */
3
5
  export declare class UserServiceImpl implements UserService<string, User> {
4
6
  protected readonly options: any;
7
+ /** Whether `cell.security` configures a user. */
8
+ get hasConfiguredUser(): boolean;
5
9
  load(username: string): Promise<User>;
6
10
  }
11
+ /**
12
+ * Warns at startup when the login (form or Basic) has no user to check: the default UserService is in
13
+ * use and `cell.security` configures no user. A warning, not an error: an application may log in with
14
+ * OAuth2 only, or use @celljs/security for authorization alone.
15
+ */
16
+ export declare class UserSourceCheck implements ApplicationLifecycle<Application> {
17
+ protected readonly userService: UserService<string, User>;
18
+ protected readonly logger: Logger;
19
+ initialize(): void;
20
+ }
7
21
  //# sourceMappingURL=user-service.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-service.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAG9C,OAAO,EAAE,IAAI,EAAY,MAAM,cAAc,CAAC;AAE9C,qBACa,eAAgB,YAAW,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC;IAG7D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IAE1B,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe1C;CACJ"}
1
+ {"version":3,"file":"user-service.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAC9C,OAAO,EAA+B,MAAM,EAAE,oBAAoB,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAEtG,OAAO,EAAE,IAAI,EAAY,MAAM,cAAc,CAAC;AAE9C,uFAAuF;AACvF,qBACa,eAAgB,YAAW,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC;IAG7D,SAAS,CAAC,QAAQ,CAAC,OAAO,EAAE,GAAG,CAAC;IAEhC,iDAAiD;IACjD,IAAI,iBAAiB,IAAI,OAAO,CAE/B;IAEK,IAAI,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO,CAAC,IAAI,CAAC,CAe1C;CACJ;AAED;;;;GAIG;AACH,qBACa,eAAgB,YAAW,oBAAoB,CAAC,WAAW,CAAC;IAGrE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,WAAW,CAAC,MAAM,EAAE,IAAI,CAAC,CAAC;IAG1D,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IAElC,UAAU,IAAI,IAAI,CAOjB;CACJ"}
@@ -9,14 +9,20 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
10
  };
11
11
  Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.UserServiceImpl = void 0;
12
+ exports.UserSourceCheck = exports.UserServiceImpl = void 0;
13
13
  const user_protocol_1 = require("./user-protocol");
14
14
  const core_1 = require("@celljs/core");
15
15
  const error_1 = require("../error");
16
16
  const common_1 = require("../../common");
17
+ /** The one user of `cell.security.username` / `password`, when they are configured. */
17
18
  let UserServiceImpl = class UserServiceImpl {
19
+ /** Whether `cell.security` configures a user. */
20
+ get hasConfiguredUser() {
21
+ var _a, _b;
22
+ return !!((_a = this.options) === null || _a === void 0 ? void 0 : _a.username) && !!((_b = this.options) === null || _b === void 0 ? void 0 : _b.password);
23
+ }
18
24
  async load(username) {
19
- if (this.options.username === username) {
25
+ if (this.hasConfiguredUser && this.options.username === username) {
20
26
  return {
21
27
  type: common_1.UserType.Memery,
22
28
  username,
@@ -39,4 +45,29 @@ __decorate([
39
45
  exports.UserServiceImpl = UserServiceImpl = __decorate([
40
46
  (0, core_1.Component)(user_protocol_1.UserService)
41
47
  ], UserServiceImpl);
48
+ /**
49
+ * Warns at startup when the login (form or Basic) has no user to check: the default UserService is in
50
+ * use and `cell.security` configures no user. A warning, not an error: an application may log in with
51
+ * OAuth2 only, or use @celljs/security for authorization alone.
52
+ */
53
+ let UserSourceCheck = class UserSourceCheck {
54
+ initialize() {
55
+ if (this.userService instanceof UserServiceImpl && !this.userService.hasConfiguredUser) {
56
+ this.logger.warn('No user can log in: @celljs/security has no built-in user. Set cell.security.username and cell.security.password ' +
57
+ '(a hash made by the PasswordEncoder) in cell.yml, or bind a UserService of your own.');
58
+ }
59
+ }
60
+ };
61
+ exports.UserSourceCheck = UserSourceCheck;
62
+ __decorate([
63
+ (0, core_1.Autowired)(user_protocol_1.UserService),
64
+ __metadata("design:type", Object)
65
+ ], UserSourceCheck.prototype, "userService", void 0);
66
+ __decorate([
67
+ (0, core_1.Autowired)(core_1.Logger),
68
+ __metadata("design:type", Object)
69
+ ], UserSourceCheck.prototype, "logger", void 0);
70
+ exports.UserSourceCheck = UserSourceCheck = __decorate([
71
+ (0, core_1.Component)(core_1.ApplicationLifecycle)
72
+ ], UserSourceCheck);
42
73
  //# sourceMappingURL=user-service.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"user-service.js","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA8C;AAC9C,uCAAgD;AAChD,oCAAiD;AACjD,yCAA8C;AAGvC,IAAM,eAAe,GAArB,MAAM,eAAe;IAKxB,KAAK,CAAC,IAAI,CAAC,QAAgB;QACvB,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YACrC,OAAO;gBACH,IAAI,EAAE,iBAAQ,CAAC,MAAM;gBACrB,QAAQ;gBACR,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,iBAAiB,EAAE,IAAI;gBACvB,gBAAgB,EAAE,IAAI;gBACtB,qBAAqB,EAAE,IAAI;gBAC3B,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,EAAE;aACf,CAAC;QACN,CAAC;QAED,MAAM,IAAI,6BAAqB,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;IACnE,CAAC;CACJ,CAAA;;AAlBsB;IADlB,IAAA,YAAK,EAAC,eAAe,CAAC;;gDACS;0BAHvB,eAAe;IAD3B,IAAA,gBAAS,EAAC,2BAAW,CAAC;GACV,eAAe,CAqB3B"}
1
+ {"version":3,"file":"user-service.js","sourceRoot":"","sources":["../../../src/node/user/user-service.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,mDAA8C;AAC9C,uCAAsG;AACtG,oCAAiD;AACjD,yCAA8C;AAE9C,uFAAuF;AAEhF,IAAM,eAAe,GAArB,MAAM,eAAe;IAKxB,iDAAiD;IACjD,IAAI,iBAAiB;;QACjB,OAAO,CAAC,EAAC,MAAA,IAAI,CAAC,OAAO,0CAAE,QAAQ,CAAA,IAAI,CAAC,EAAC,MAAA,IAAI,CAAC,OAAO,0CAAE,QAAQ,CAAA,CAAC;IAChE,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,QAAgB;QACvB,IAAI,IAAI,CAAC,iBAAiB,IAAI,IAAI,CAAC,OAAO,CAAC,QAAQ,KAAK,QAAQ,EAAE,CAAC;YAC/D,OAAO;gBACH,IAAI,EAAE,iBAAQ,CAAC,MAAM;gBACrB,QAAQ;gBACR,QAAQ,EAAE,IAAI,CAAC,OAAO,CAAC,QAAQ;gBAC/B,iBAAiB,EAAE,IAAI;gBACvB,gBAAgB,EAAE,IAAI;gBACtB,qBAAqB,EAAE,IAAI;gBAC3B,OAAO,EAAE,IAAI;gBACb,QAAQ,EAAE,EAAE;aACf,CAAC;QACN,CAAC;QAED,MAAM,IAAI,6BAAqB,CAAC,mBAAmB,QAAQ,EAAE,CAAC,CAAC;IACnE,CAAC;CACJ,CAAA;;AAvBsB;IADlB,IAAA,YAAK,EAAC,eAAe,CAAC;;gDACS;0BAHvB,eAAe;IAD3B,IAAA,gBAAS,EAAC,2BAAW,CAAC;GACV,eAAe,CA0B3B;AAED;;;;GAIG;AAEI,IAAM,eAAe,GAArB,MAAM,eAAe;IAQxB,UAAU;QACN,IAAI,IAAI,CAAC,WAAW,YAAY,eAAe,IAAI,CAAC,IAAI,CAAC,WAAW,CAAC,iBAAiB,EAAE,CAAC;YACrF,IAAI,CAAC,MAAM,CAAC,IAAI,CACZ,mHAAmH;gBACnH,sFAAsF,CACzF,CAAC;QACN,CAAC;IACL,CAAC;CACJ,CAAA;;AAbsB;IADlB,IAAA,gBAAS,EAAC,2BAAW,CAAC;;oDACmC;AAGvC;IADlB,IAAA,gBAAS,EAAC,aAAM,CAAC;;+CACgB;0BANzB,eAAe;IAD3B,IAAA,gBAAS,EAAC,2BAAoB,CAAC;GACnB,eAAe,CAgB3B"}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=user-service.spec.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-service.spec.d.ts","sourceRoot":"","sources":["../../../src/node/user/user-service.spec.ts"],"names":[],"mappings":""}
@@ -0,0 +1,44 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const bun_test_1 = require("bun:test");
4
+ const chai_1 = require("chai");
5
+ const user_service_1 = require("./user-service");
6
+ const error_1 = require("../error");
7
+ function check(userService) {
8
+ const warnings = [];
9
+ const lifecycle = new user_service_1.UserSourceCheck();
10
+ Object.assign(lifecycle, { userService, logger: { warn: (m) => warnings.push(m) } });
11
+ lifecycle.initialize();
12
+ return warnings;
13
+ }
14
+ function service(options) {
15
+ return Object.assign(new user_service_1.UserServiceImpl(), { options });
16
+ }
17
+ (0, bun_test_1.describe)('UserServiceImpl', () => {
18
+ (0, bun_test_1.it)('has no built-in user', async () => {
19
+ let error;
20
+ try {
21
+ await service({}).load('admin');
22
+ }
23
+ catch (e) {
24
+ error = e;
25
+ }
26
+ (0, chai_1.expect)(error).to.be.instanceOf(error_1.UsernameNotFoundError);
27
+ });
28
+ (0, bun_test_1.it)('loads the user of cell.security', async () => {
29
+ const user = await service({ username: 'tom', password: 'hash' }).load('tom');
30
+ (0, chai_1.expect)(user.username).to.equal('tom');
31
+ (0, chai_1.expect)(user.password).to.equal('hash');
32
+ });
33
+ });
34
+ (0, bun_test_1.describe)('UserSourceCheck', () => {
35
+ (0, bun_test_1.it)('warns when the default UserService has no configured user', () => {
36
+ (0, chai_1.expect)(check(service({}))).to.have.length(1);
37
+ (0, chai_1.expect)(check(service({ username: 'tom' }))).to.have.length(1);
38
+ });
39
+ (0, bun_test_1.it)('is quiet with a configured user or a UserService of the application', () => {
40
+ (0, chai_1.expect)(check(service({ username: 'tom', password: 'hash' }))).to.have.length(0);
41
+ (0, chai_1.expect)(check({ load: async () => ({}) })).to.have.length(0);
42
+ });
43
+ });
44
+ //# sourceMappingURL=user-service.spec.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"user-service.spec.js","sourceRoot":"","sources":["../../../src/node/user/user-service.spec.ts"],"names":[],"mappings":";;AAAA,uCAAwC;AACxC,+BAA8B;AAC9B,iDAAkE;A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,KAAK,CAAC,CAAC;QACtC,IAAA,aAAM,EAAC,IAAI,CAAC,QAAQ,CAAC,CAAC,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;IAC3C,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC;AAEH,IAAA,mBAAQ,EAAC,iBAAiB,EAAE,GAAG,EAAE;IAC7B,IAAA,aAAE,EAAC,2DAA2D,EAAE,GAAG,EAAE;QACjE,IAAA,aAAM,EAAC,KAAK,CAAC,OAAO,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAC7C,IAAA,aAAM,EAAC,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAClE,CAAC,CAAC,CAAC;IAEH,IAAA,aAAE,EAAC,qEAAqE,EAAE,GAAG,EAAE;QAC3E,IAAA,aAAM,EAAC,KAAK,CAAC,OAAO,CAAC,EAAE,QAAQ,EAAE,KAAK,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;QAChF,IAAA,aAAM,EAAC,KAAK,CAAC,EAAE,IAAI,EAAE,KAAK,IAAI,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC;IAChE,CAAC,CAAC,CAAC;AACP,CAAC,CAAC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@celljs/security",
3
- "version": "4.0.0",
3
+ "version": "4.1.0",
4
4
  "description": "",
5
5
  "keywords": [
6
6
  "cell-component"
@@ -29,21 +29,15 @@
29
29
  "watch": "tsc -b -w --preserveWatchOutput"
30
30
  },
31
31
  "dependencies": {
32
- "@celljs/core": "4.0.0",
33
- "@celljs/http": "4.0.0",
34
- "@celljs/web": "4.0.0",
35
- "axios": "^0.26.1",
36
- "crypto-js": "^4.0.0",
37
- "jexl": "^2.2.0",
32
+ "@celljs/core": "4.1.0",
33
+ "@celljs/http": "4.1.0",
34
+ "@celljs/web": "4.1.0",
35
+ "axios": "^0.35.0",
38
36
  "micromatch": "^4.0.2",
39
- "qs": "^6.9.4",
40
- "reflect-metadata": "^0.1.13",
41
- "rxjs": "^6.6.0",
42
- "tslib": "^2.8.0"
37
+ "qs": "^6.17.1",
38
+ "rxjs": "^6.6.0"
43
39
  },
44
40
  "devDependencies": {
45
- "@types/crypto-js": "^3.1.47",
46
- "@types/jexl": "^2.2.0",
47
41
  "@types/micromatch": "^4.0.1"
48
42
  },
49
43
  "publishConfig": {
@@ -5,7 +5,6 @@ export const AccessDecisionVoter = Symbol('AccessDecisionVoter');
5
5
  export const SecurityMetadataSource = Symbol('SecurityMetadataSource');
6
6
  export const PolicyResolver = Symbol('PolicyResolver');
7
7
  export const SecurityExpressionContextHandler = Symbol('SecurityExpressionContextHandler');
8
- export const JexlEngineProvider = Symbol('JexlEngineProvider');
9
8
  export const PolicyProvider = Symbol('PolicyProvider');
10
9
  export const PolicyFactory = Symbol('PolicyFactory');
11
10
  export const ResourceNameResolver = Symbol('ResourceNameResolver');
@@ -40,10 +39,6 @@ export interface PolicyResolver {
40
39
  support(policy: Policy, securityMetadata: SecurityMetadata): Promise<boolean>;
41
40
  }
42
41
 
43
- export interface JexlEngineProvider<T> {
44
- provide(): T
45
- }
46
-
47
42
  export interface SecurityExpressionContextHandler {
48
43
  handle(context: any): Promise<void>
49
44
  }
@@ -0,0 +1,37 @@
1
+ import { describe, it } from 'bun:test';
2
+ import { expect } from 'chai';
3
+ import { JexlEngineProviderImpl } from '@celljs/core';
4
+ import { Resource } from '../annotation/resource';
5
+ import { ACCESS_DENIED, ACCESS_GRANTED } from './access-protocol';
6
+ import { ElPolicyResolver } from './policy-resolver';
7
+ import { DefaultResourceNameResolver } from './resource-name-resolver';
8
+ import { PolicyType } from '../../common';
9
+
10
+ @Resource('order')
11
+ class OrderService {
12
+ @Resource('args[0].id')
13
+ get(_order: { id: string }) {}
14
+ }
15
+
16
+ class ItemService {
17
+ @Resource("'item:' + args[0]")
18
+ get(_id: string) {}
19
+ }
20
+
21
+ describe('security expressions (jexl of @celljs/core)', () => {
22
+ it('ElPolicyResolver grants when the expression is true', async () => {
23
+ const resolver = new ElPolicyResolver();
24
+ Object.defineProperty(resolver, 'jexlEngineProvider', { value: new JexlEngineProviderImpl() });
25
+ const policy = (el: string) => ({ type: PolicyType.el, el, context: { user: { name: 'tom', roles: ['admin'] } } }) as any;
26
+ expect(await resolver.resolve(policy("user.name == 'tom' && 'admin' in user.roles"), {} as any)).to.equal(ACCESS_GRANTED);
27
+ expect(await resolver.resolve(policy("user.name == 'bob'"), {} as any)).to.equal(ACCESS_DENIED);
28
+ });
29
+
30
+ it('DefaultResourceNameResolver evaluates method resources against the call', async () => {
31
+ const resolver = new DefaultResourceNameResolver();
32
+ Object.assign(resolver, { tenantEnabled: false, jexlEngineProvider: new JexlEngineProviderImpl() });
33
+ const target = new OrderService();
34
+ expect(await resolver.resolve({ target, method: 'get', args: [{ id: '42' }] } as any)).to.deep.equal(['order:42']);
35
+ expect(await resolver.resolve({ target: new ItemService(), method: 'get', args: ['7'] } as any)).to.deep.equal(['item:7']);
36
+ });
37
+ });
@@ -8,4 +8,3 @@ export * from './security-metadata-source';
8
8
  export * from './resource-name-resolver';
9
9
  export * from './action-name-resolver';
10
10
  export * from './access-decision-utils';
11
- export * from './jexl-engine-provider';
@@ -1,5 +1,5 @@
1
- import { ACCESS_ABSTAIN, ACCESS_DENIED, ACCESS_GRANTED, JexlEngineProvider, PolicyResolver, SecurityMetadata, SECURITY_EXPRESSION_CONTEXT_KEY } from './access-protocol';
2
- import { Autowired, Component } from '@celljs/core';
1
+ import { ACCESS_ABSTAIN, ACCESS_DENIED, ACCESS_GRANTED, PolicyResolver, SecurityMetadata, SECURITY_EXPRESSION_CONTEXT_KEY } from './access-protocol';
2
+ import { Autowired, Component, JexlEngineProvider } from '@celljs/core';
3
3
  import { Context } from '@celljs/web/lib/node';
4
4
  import { AclPolicy, Effect, ElPolicy, Policy, PolicyType, Statement } from '../../common';
5
5
  import { contains } from 'micromatch';
@@ -1,7 +1,6 @@
1
1
  import { MethodSecurityMetadataContext, ResourceNameResolver } from './access-protocol';
2
- import { Component, Value, TENANT_ENABLED, getOwnMetadata } from '@celljs/core';
2
+ import { Component, Value, Autowired, TENANT_ENABLED, getOwnMetadata, JexlEngineProvider } from '@celljs/core';
3
3
  import { METADATA_KEY } from '../constants';
4
- import { evalSync } from 'jexl';
5
4
  import { Context } from '@celljs/web/lib/node';
6
5
 
7
6
  @Component(ResourceNameResolver)
@@ -10,6 +9,13 @@ export class DefaultResourceNameResolver implements ResourceNameResolver {
10
9
  @Value(TENANT_ENABLED)
11
10
  protected tenantEnabled: boolean;
12
11
 
12
+ @Autowired(JexlEngineProvider)
13
+ protected readonly jexlEngineProvider: JexlEngineProvider<any>;
14
+
15
+ protected evalSync(expression: string, ctx: MethodSecurityMetadataContext): any {
16
+ return this.jexlEngineProvider.provide().evalSync(expression, ctx);
17
+ }
18
+
13
19
  async resolve(ctx: MethodSecurityMetadataContext): Promise<string[]> {
14
20
  const classResources: string[] = getOwnMetadata(METADATA_KEY.resource, ctx.target.constructor);
15
21
  const methodResources: string[] = getOwnMetadata(METADATA_KEY.resource, ctx.target.constructor, ctx.method);
@@ -17,11 +23,11 @@ export class DefaultResourceNameResolver implements ResourceNameResolver {
17
23
  if (classResources.length && methodResources.length) {
18
24
  for (const resource of methodResources) {
19
25
  // eslint-disable-next-line no-eval
20
- resources.push(`${classResources[0]}:${evalSync(resource?.toString(), ctx)}`);
26
+ resources.push(`${classResources[0]}:${this.evalSync(resource?.toString(), ctx)}`);
21
27
  }
22
28
  } else if (methodResources.length) {
23
29
  // eslint-disable-next-line no-eval
24
- resources = methodResources.map(r => evalSync(r?.toString(), ctx)?.toString());
30
+ resources = methodResources.map(r => this.evalSync(r?.toString(), ctx)?.toString());
25
31
  } else if (classResources.length) {
26
32
  resources = classResources;
27
33
  } else {
@@ -1,4 +1,4 @@
1
- import { Component, Autowired, Value } from '@celljs/core';
1
+ import { Component, Autowired, Value, Logger } from '@celljs/core';
2
2
  import { AuthenticationProvider, Authentication, USERNAME_PASSWORD_AUTHENTICATION_PROVIDER_PRIORITY,
3
3
  BASE_AUTHENTICATION_PROVIDER_PRIORITY, AUTHENTICATION_SCHEME_BASIC } from './authentication-protocol';
4
4
  import { Context, RequestMatcher, RedirectStrategy } from '@celljs/web/lib/node';
@@ -10,6 +10,22 @@ import { PathResolver } from '@celljs/web';
10
10
 
11
11
  import { User } from '../../common';
12
12
 
13
+ /**
14
+ * After a password matched: when its stored hash is in a legacy format and the UserService can store
15
+ * passwords, store a new hash of it. A failure is logged and does not fail the login.
16
+ */
17
+ export async function upgradePasswordHash(passwordEncoder: PasswordEncoder, userService: UserService<any, User>, user: User,
18
+ rawPassword: string, logger: Logger): Promise<void> {
19
+ if (!userService.updatePassword || !passwordEncoder.needsUpgrade?.(user.password)) {
20
+ return;
21
+ }
22
+ try {
23
+ await userService.updatePassword(user, await passwordEncoder.encode(rawPassword));
24
+ } catch (error) {
25
+ logger.warn(`Could not upgrade the password hash of ${user.username}: ${(error as Error)?.message ?? error}`);
26
+ }
27
+ }
28
+
13
29
  @Component(AuthenticationProvider)
14
30
  export class UsernamePasswordAuthenticationProvider implements AuthenticationProvider {
15
31
 
@@ -37,6 +53,9 @@ export class UsernamePasswordAuthenticationProvider implements AuthenticationPro
37
53
  @Autowired(RedirectStrategy)
38
54
  protected readonly redirectStrategy: RedirectStrategy;
39
55
 
56
+ @Autowired(Logger)
57
+ protected readonly logger: Logger;
58
+
40
59
  priority = USERNAME_PASSWORD_AUTHENTICATION_PROVIDER_PRIORITY;
41
60
 
42
61
  async authenticate(): Promise<Authentication | undefined> {
@@ -50,6 +69,7 @@ export class UsernamePasswordAuthenticationProvider implements AuthenticationPro
50
69
  if (!await this.passwordEncoder.matches(password, user.password)) {
51
70
  throw new BadCredentialsError('Bad credentials');
52
71
  }
72
+ await upgradePasswordHash(this.passwordEncoder, this.userService, user, password, this.logger);
53
73
  await this.userMapper.map(user);
54
74
  return {
55
75
  name: user.username,
@@ -100,6 +120,9 @@ export class BasicAuthenticationProvider implements AuthenticationProvider {
100
120
  @Autowired(RedirectStrategy)
101
121
  protected readonly redirectStrategy: RedirectStrategy;
102
122
 
123
+ @Autowired(Logger)
124
+ protected readonly logger: Logger;
125
+
103
126
  priority = BASE_AUTHENTICATION_PROVIDER_PRIORITY;
104
127
 
105
128
  async authenticate(): Promise<Authentication | undefined> {
@@ -115,7 +138,7 @@ export class BasicAuthenticationProvider implements AuthenticationProvider {
115
138
  throw new BadCredentialsError('Invalid basic authentication token');
116
139
  }
117
140
  const username = token.substring(0, delim);
118
- const password = token.substring(delim);
141
+ const password = token.substring(delim + 1);
119
142
  if (!password || !username) {
120
143
  throw new BadCredentialsError('Bad credentials');
121
144
  }
@@ -124,6 +147,7 @@ export class BasicAuthenticationProvider implements AuthenticationProvider {
124
147
  if (!await this.passwordEncoder.matches(password, user.password)) {
125
148
  throw new BadCredentialsError('Bad credentials');
126
149
  }
150
+ await upgradePasswordHash(this.passwordEncoder, this.userService, user, password, this.logger);
127
151
 
128
152
  await this.userMapper.map(user);
129
153
 
@@ -29,6 +29,10 @@ export class DefaultAuthenticationSuccessHandler implements AuthenticationSucces
29
29
  protected readonly requestCache: RequestCache;
30
30
 
31
31
  async onAuthenticationSuccess(authentication: Authentication): Promise<void> {
32
+ // Authentication that goes on to the requested resource (Basic): nothing to redirect to.
33
+ if (authentication.next) {
34
+ return;
35
+ }
32
36
  const response = Context.getResponse();
33
37
  if (Context.getRequest().get(HttpHeaders.X_REQUESTED_WITH) === XML_HTTP_REQUEST) {
34
38
  return;