@furystack/security 2.1.16 → 3.0.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 (79) hide show
  1. package/package.json +27 -12
  2. package/src/helpers.ts +0 -1
  3. package/src/password-authenticator.spec.ts +4 -3
  4. package/src/password-authenticator.ts +1 -3
  5. package/src/password-complexity-rules/contains-lowercase.spec.ts +1 -0
  6. package/src/password-complexity-rules/contains-uppercase.spec.ts +1 -0
  7. package/src/password-complexity-rules/max-length.spec.ts +1 -0
  8. package/src/password-complexity-rules/min-length.spec.ts +1 -0
  9. package/src/security-policy-manager.spec.ts +1 -0
  10. package/types/helpers.d.ts +0 -1
  11. package/types/helpers.d.ts.map +1 -1
  12. package/types/password-authenticator.d.ts +1 -3
  13. package/types/password-authenticator.d.ts.map +1 -1
  14. package/dist/crypto-password-hasher.js +0 -44
  15. package/dist/crypto-password-hasher.js.map +0 -1
  16. package/dist/errors/index.js +0 -20
  17. package/dist/errors/index.js.map +0 -1
  18. package/dist/errors/password-complexity-error.js +0 -15
  19. package/dist/errors/password-complexity-error.js.map +0 -1
  20. package/dist/errors/unauthenticated-error.js +0 -10
  21. package/dist/errors/unauthenticated-error.js.map +0 -1
  22. package/dist/helpers.js +0 -17
  23. package/dist/helpers.js.map +0 -1
  24. package/dist/index.js +0 -25
  25. package/dist/index.js.map +0 -1
  26. package/dist/models/index.js +0 -22
  27. package/dist/models/index.js.map +0 -1
  28. package/dist/models/password-check-result.js +0 -3
  29. package/dist/models/password-check-result.js.map +0 -1
  30. package/dist/models/password-complexity-result.js +0 -3
  31. package/dist/models/password-complexity-result.js.map +0 -1
  32. package/dist/models/password-complexity-rule.js +0 -3
  33. package/dist/models/password-complexity-rule.js.map +0 -1
  34. package/dist/models/password-credential.js +0 -10
  35. package/dist/models/password-credential.js.map +0 -1
  36. package/dist/models/password-reset-token.js +0 -7
  37. package/dist/models/password-reset-token.js.map +0 -1
  38. package/dist/password-authenticator.js +0 -108
  39. package/dist/password-authenticator.js.map +0 -1
  40. package/dist/password-authenticator.spec.js +0 -292
  41. package/dist/password-authenticator.spec.js.map +0 -1
  42. package/dist/password-complexity-rules/contains-lowercase.js +0 -29
  43. package/dist/password-complexity-rules/contains-lowercase.js.map +0 -1
  44. package/dist/password-complexity-rules/contains-lowercase.spec.js +0 -28
  45. package/dist/password-complexity-rules/contains-lowercase.spec.js.map +0 -1
  46. package/dist/password-complexity-rules/contains-uppercase.js +0 -27
  47. package/dist/password-complexity-rules/contains-uppercase.js.map +0 -1
  48. package/dist/password-complexity-rules/contains-uppercase.spec.js +0 -28
  49. package/dist/password-complexity-rules/contains-uppercase.spec.js.map +0 -1
  50. package/dist/password-complexity-rules/index.js +0 -21
  51. package/dist/password-complexity-rules/index.js.map +0 -1
  52. package/dist/password-complexity-rules/max-length.js +0 -19
  53. package/dist/password-complexity-rules/max-length.js.map +0 -1
  54. package/dist/password-complexity-rules/max-length.spec.js +0 -17
  55. package/dist/password-complexity-rules/max-length.spec.js.map +0 -1
  56. package/dist/password-complexity-rules/min-length.js +0 -19
  57. package/dist/password-complexity-rules/min-length.js.map +0 -1
  58. package/dist/password-complexity-rules/min-length.spec.js +0 -17
  59. package/dist/password-complexity-rules/min-length.spec.js.map +0 -1
  60. package/dist/password-hasher.js +0 -23
  61. package/dist/password-hasher.js.map +0 -1
  62. package/dist/security-policy-manager.js +0 -60
  63. package/dist/security-policy-manager.js.map +0 -1
  64. package/dist/security-policy-manager.spec.js +0 -18
  65. package/dist/security-policy-manager.spec.js.map +0 -1
  66. package/dist/security-policy.js +0 -40
  67. package/dist/security-policy.js.map +0 -1
  68. package/types/password-authenticator.spec.d.ts +0 -2
  69. package/types/password-authenticator.spec.d.ts.map +0 -1
  70. package/types/password-complexity-rules/contains-lowercase.spec.d.ts +0 -2
  71. package/types/password-complexity-rules/contains-lowercase.spec.d.ts.map +0 -1
  72. package/types/password-complexity-rules/contains-uppercase.spec.d.ts +0 -2
  73. package/types/password-complexity-rules/contains-uppercase.spec.d.ts.map +0 -1
  74. package/types/password-complexity-rules/max-length.spec.d.ts +0 -2
  75. package/types/password-complexity-rules/max-length.spec.d.ts.map +0 -1
  76. package/types/password-complexity-rules/min-length.spec.d.ts +0 -2
  77. package/types/password-complexity-rules/min-length.spec.d.ts.map +0 -1
  78. package/types/security-policy-manager.spec.d.ts +0 -2
  79. package/types/security-policy-manager.spec.d.ts.map +0 -1
@@ -1,60 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- var __metadata = (this && this.__metadata) || function (k, v) {
9
- if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
10
- };
11
- Object.defineProperty(exports, "__esModule", { value: true });
12
- exports.SecurityPolicyManager = void 0;
13
- const inject_1 = require("@furystack/inject");
14
- const security_policy_1 = require("./security-policy");
15
- let SecurityPolicyManager = class SecurityPolicyManager {
16
- /**
17
- * @param password The Plain password string
18
- * @returns if the password matches the complexity rules
19
- */
20
- async matchPasswordComplexityRules(password) {
21
- const result = await Promise.all(this.policy.passwordComplexityRules.map((rule) => rule.check(password)));
22
- const failed = result.filter((r) => r.success === false);
23
- if (failed.length) {
24
- return {
25
- match: false,
26
- errors: failed.map((f) => f.success === false && { message: f.message, rule: f.rule }),
27
- };
28
- }
29
- return {
30
- match: true,
31
- };
32
- }
33
- hasPasswordExpired(credential) {
34
- if (!this.policy.passwordExpirationDays) {
35
- return false;
36
- }
37
- const credentialExpiration = new Date(credential.creationDate);
38
- credentialExpiration.setDate(credentialExpiration.getDate() + this.policy.passwordExpirationDays);
39
- const now = new Date();
40
- return now > credentialExpiration;
41
- }
42
- hasTokenExpired(token) {
43
- if (!this.policy.resetTokenExpirationSeconds) {
44
- return false;
45
- }
46
- const tokenExpiration = new Date(token.createdAt);
47
- tokenExpiration.setSeconds(tokenExpiration.getSeconds() + this.policy.resetTokenExpirationSeconds);
48
- const now = new Date();
49
- return now > tokenExpiration;
50
- }
51
- };
52
- __decorate([
53
- (0, inject_1.Injected)(security_policy_1.SecurityPolicy),
54
- __metadata("design:type", security_policy_1.SecurityPolicy)
55
- ], SecurityPolicyManager.prototype, "policy", void 0);
56
- SecurityPolicyManager = __decorate([
57
- (0, inject_1.Injectable)({ lifetime: 'singleton' })
58
- ], SecurityPolicyManager);
59
- exports.SecurityPolicyManager = SecurityPolicyManager;
60
- //# sourceMappingURL=security-policy-manager.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"security-policy-manager.js","sourceRoot":"","sources":["../src/security-policy-manager.ts"],"names":[],"mappings":";;;;;;;;;;;;AAAA,8CAAwD;AAExD,uDAAkD;AAGlD,IAAa,qBAAqB,GAAlC,MAAa,qBAAqB;IAChC;;;OAGG;IACI,KAAK,CAAC,4BAA4B,CAAC,QAAgB;QACxD,MAAM,MAAM,GAAG,MAAM,OAAO,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,uBAAuB,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAA;QACzG,MAAM,MAAM,GAAG,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,OAAO,KAAK,KAAK,CAAC,CAAA;QACxD,IAAI,MAAM,CAAC,MAAM,EAAE;YACjB,OAAO;gBACL,KAAK,EAAE,KAAc;gBACrB,MAAM,EAAE,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CA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
3
- const inject_1 = require("@furystack/inject");
4
- const utils_1 = require("@furystack/utils");
5
- const helpers_1 = require("./helpers");
6
- const security_policy_manager_1 = require("./security-policy-manager");
7
- describe('SecurityPolicyManager', () => {
8
- it('Should return false when no token expiration has been set', () => {
9
- (0, utils_1.using)(new inject_1.Injector(), (i) => {
10
- (0, helpers_1.usePasswordPolicy)(i, { resetTokenExpirationSeconds: 0 });
11
- const result = i
12
- .getInstance(security_policy_manager_1.SecurityPolicyManager)
13
- .hasTokenExpired({ createdAt: new Date().toISOString(), token: 'token', userName: 'user' });
14
- expect(result).toBeFalsy();
15
- });
16
- });
17
- });
18
- //# sourceMappingURL=security-policy-manager.spec.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"security-policy-manager.spec.js","sourceRoot":"","sources":["../src/security-policy-manager.spec.ts"],"names":[],"mappings":";;AAAA,8CAA4C;AAC5C,4CAAwC;AACxC,uCAA6C;AAC7C,uEAAiE;AAEjE,QAAQ,CAAC,uBAAuB,EAAE,GAAG,EAAE;IACrC,EAAE,CAAC,2DAA2D,EAAE,GAAG,EAAE;QACnE,IAAA,aAAK,EAAC,IAAI,iBAAQ,EAAE,EAAE,CAAC,CAAC,EAAE,EAAE;YAC1B,IAAA,2BAAiB,EAAC,CAAC,EAAE,EAAE,2BAA2B,EAAE,CAAC,EAAE,CAAC,CAAA;YACxD,MAAM,MAAM,GAAG,CAAC;iBACb,WAAW,CAAC,+CAAqB,CAAC;iBAClC,eAAe,CAAC,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,CAAC,WAAW,EAAE,EAAE,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,EAAE,CAAC,CAAA;YAC7F,MAAM,CAAC,MAAM,CAAC,CAAC,SAAS,EAAE,CAAA;QAC5B,CAAC,CAAC,CAAA;IACJ,CAAC,CAAC,CAAA;AACJ,CAAC,CAAC,CAAA"}
@@ -1,40 +0,0 @@
1
- "use strict";
2
- var __decorate = (this && this.__decorate) || function (decorators, target, key, desc) {
3
- var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
4
- if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
5
- else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
6
- return c > 3 && r && Object.defineProperty(target, key, r), r;
7
- };
8
- Object.defineProperty(exports, "__esModule", { value: true });
9
- exports.SecurityPolicy = void 0;
10
- const inject_1 = require("@furystack/inject");
11
- const crypto_password_hasher_1 = require("./crypto-password-hasher");
12
- let SecurityPolicy = class SecurityPolicy {
13
- constructor() {
14
- /**
15
- * A Hasher instance for password hash generation
16
- */
17
- this.hasher = crypto_password_hasher_1.CryptoPasswordHasher;
18
- /**
19
- * Array of password complexity rules to apply
20
- */
21
- this.passwordComplexityRules = [];
22
- /**
23
- * The password expiration in days
24
- */
25
- this.passwordExpirationDays = 0;
26
- /**
27
- * Defines if the login needs a second factor authentication
28
- */
29
- this.requireSecondFactor = 'never'; // TODO - Challenge based on trusted devices
30
- /**
31
- * The Password Reset Token expiration in seconds
32
- */
33
- this.resetTokenExpirationSeconds = 15;
34
- }
35
- };
36
- SecurityPolicy = __decorate([
37
- (0, inject_1.Injectable)({ lifetime: 'singleton' })
38
- ], SecurityPolicy);
39
- exports.SecurityPolicy = SecurityPolicy;
40
- //# sourceMappingURL=security-policy.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"security-policy.js","sourceRoot":"","sources":["../src/security-policy.ts"],"names":[],"mappings":";;;;;;;;;AACA,8CAA8C;AAC9C,qEAA+D;AAK/D,IAAa,cAAc,GAA3B,MAAa,cAAc;IAA3B;QACE;;WAEG;QACH,WAAM,GAAkC,6CAAoB,CAAA;QAE5D;;WAEG;QACH,4BAAuB,GAA6B,EAAE,CAAA;QAEtD;;WAEG;QACH,2BAAsB,GAAG,CAAC,CAAA;QAE1B;;WAEG;QACH,wBAAmB,GAAuB,OAAO,CAAA,CAAC,4CAA4C;QAE9F;;WAEG;QACH,gCAA2B,GAAG,EAAE,CAAA;IAClC,CAAC;CAAA,CAAA;AAzBY,cAAc;IAD1B,IAAA,mBAAU,EAAC,EAAE,QAAQ,EAAE,WAAW,EAAE,CAAC;GACzB,cAAc,CAyB1B;AAzBY,wCAAc"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=password-authenticator.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"password-authenticator.spec.d.ts","sourceRoot":"","sources":["../src/password-authenticator.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=contains-lowercase.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contains-lowercase.spec.d.ts","sourceRoot":"","sources":["../../src/password-complexity-rules/contains-lowercase.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=contains-uppercase.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"contains-uppercase.spec.d.ts","sourceRoot":"","sources":["../../src/password-complexity-rules/contains-uppercase.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=max-length.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"max-length.spec.d.ts","sourceRoot":"","sources":["../../src/password-complexity-rules/max-length.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=min-length.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"min-length.spec.d.ts","sourceRoot":"","sources":["../../src/password-complexity-rules/min-length.spec.ts"],"names":[],"mappings":""}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=security-policy-manager.spec.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"security-policy-manager.spec.d.ts","sourceRoot":"","sources":["../src/security-policy-manager.spec.ts"],"names":[],"mappings":""}