nucleus-core-ts 0.10.21 → 0.10.23
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/dist/.build-ok +1 -1
- package/dist/index.js +9 -4
- package/dist/server.js +9 -4
- package/dist/src/Nucleus/routes/auth/cohort/types.d.ts +7 -8
- package/dist/src/Nucleus/routes/auth/cohort/utils.d.ts +6 -3
- package/dist/src/Nucleus/routes/auth/passwordPolicy.d.ts +46 -0
- package/dist/src/Nucleus/routes/auth/register/utils.d.ts +11 -1
- package/package.json +1 -1
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { AppliedPasswordPolicy } from '../passwordPolicy';
|
|
1
2
|
import type { NodePgDatabase } from 'drizzle-orm/node-postgres';
|
|
2
3
|
import type { Logger } from 'src/Services';
|
|
3
4
|
type PgTable = ReturnType<typeof import('drizzle-orm/pg-core').pgTable>;
|
|
@@ -21,14 +22,12 @@ export type CohortRouteConfig = {
|
|
|
21
22
|
/** List form of `defaultRole`; merged with it. See NucleusConfigOptions.authentication. */
|
|
22
23
|
defaultRoles?: string[];
|
|
23
24
|
emailExemptDomains?: string[];
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
requireSpecialChar?: boolean;
|
|
31
|
-
};
|
|
25
|
+
/**
|
|
26
|
+
* Mirrors `authentication.passwordPolicy`. It listed only the structural
|
|
27
|
+
* rules, so the two flags the public config declares could not even be named
|
|
28
|
+
* here -- which is one reason they never did anything.
|
|
29
|
+
*/
|
|
30
|
+
passwordPolicy?: AppliedPasswordPolicy;
|
|
32
31
|
};
|
|
33
32
|
/**
|
|
34
33
|
* What a cohort handler actually reads off the request.
|
|
@@ -36,8 +36,11 @@ type PasswordValidation = {
|
|
|
36
36
|
};
|
|
37
37
|
/**
|
|
38
38
|
* Policy-aware password validation.
|
|
39
|
-
*
|
|
40
|
-
*
|
|
39
|
+
*
|
|
40
|
+
* Delegates to the shared policy so `preventCommonPasswords` and
|
|
41
|
+
* `preventUserInfoInPassword` -- declared in the public config for as long as it
|
|
42
|
+
* has existed, and implemented nowhere -- apply here too. `identity` is the
|
|
43
|
+
* account the password is being set for, which is what the second flag needs.
|
|
41
44
|
*/
|
|
42
|
-
export declare function validatePassword(pwd: string, policy?: PasswordPolicy): PasswordValidation;
|
|
45
|
+
export declare function validatePassword(pwd: string, policy?: PasswordPolicy, identity?: string): PasswordValidation;
|
|
43
46
|
export {};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The password policy, actually applied.
|
|
3
|
+
*
|
|
4
|
+
* `preventCommonPasswords` and `preventUserInfoInPassword` have been declared in
|
|
5
|
+
* the public config, carried in the JSON schema, documented as "checks against a
|
|
6
|
+
* list of known common passwords" and "rejects passwords containing the user's
|
|
7
|
+
* email", and defaulted to true in the shipped frontend -- while no list and no
|
|
8
|
+
* comparison existed anywhere in the product. An operator who set them was told
|
|
9
|
+
* their users were protected and they were not. This is where both become real.
|
|
10
|
+
*
|
|
11
|
+
* The two structural validators that existed (`validatePassword` for cohort
|
|
12
|
+
* imports, `validatePasswordStrength` for every other write path) duplicated the
|
|
13
|
+
* same four rules and neither could see the flags. Both now delegate here, so a
|
|
14
|
+
* policy means the same thing wherever a password is set.
|
|
15
|
+
*/
|
|
16
|
+
export interface AppliedPasswordPolicy {
|
|
17
|
+
minLength?: number;
|
|
18
|
+
maxLength?: number;
|
|
19
|
+
requireUppercase?: boolean;
|
|
20
|
+
requireLowercase?: boolean;
|
|
21
|
+
requireNumber?: boolean;
|
|
22
|
+
requireSpecialChar?: boolean;
|
|
23
|
+
/** Reject passwords that appear on the common-password list. */
|
|
24
|
+
preventCommonPasswords?: boolean;
|
|
25
|
+
/** Reject passwords built from the account's own email or username. */
|
|
26
|
+
preventUserInfoInPassword?: boolean;
|
|
27
|
+
}
|
|
28
|
+
export interface PasswordValidation {
|
|
29
|
+
valid: boolean;
|
|
30
|
+
errors: string[];
|
|
31
|
+
}
|
|
32
|
+
/** True when the password is one of the passwords tried first. */
|
|
33
|
+
export declare function isCommonPassword(pwd: string): boolean;
|
|
34
|
+
/**
|
|
35
|
+
* True when the password is built out of the account's own identity.
|
|
36
|
+
*
|
|
37
|
+
* Checks the whole identity, its local part when it is an email, and the
|
|
38
|
+
* domain's first label -- in both directions, because `ayse@firma.com` picking
|
|
39
|
+
* `Ayse2024!` and picking `firma` are the same mistake.
|
|
40
|
+
*/
|
|
41
|
+
export declare function containsUserInfo(pwd: string, identity?: string): boolean;
|
|
42
|
+
/**
|
|
43
|
+
* Applies a policy to a password. With no policy, the rules are the ones this
|
|
44
|
+
* product has always applied to registration: min 8, upper, lower, digit.
|
|
45
|
+
*/
|
|
46
|
+
export declare function validateAgainstPolicy(pwd: string, policy?: AppliedPasswordPolicy, identity?: string): PasswordValidation;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { type AppliedPasswordPolicy } from '../passwordPolicy';
|
|
1
2
|
export declare function hashPassword(plainPassword: string): Promise<string>;
|
|
2
3
|
export declare function generateVerificationToken(): string;
|
|
3
4
|
/**
|
|
@@ -7,7 +8,16 @@ export declare function generateVerificationToken(): string;
|
|
|
7
8
|
*/
|
|
8
9
|
export declare function hashVerificationToken(token: string): string;
|
|
9
10
|
export declare function parseTimeToMs(time: string): number;
|
|
10
|
-
|
|
11
|
+
/**
|
|
12
|
+
* The check every password write path outside the cohort import uses.
|
|
13
|
+
*
|
|
14
|
+
* It was four hardcoded rules that no configuration could reach, which is why
|
|
15
|
+
* `authentication.passwordPolicy` -- including its two security flags -- applied
|
|
16
|
+
* to exactly one endpoint in the product. It now delegates to the shared policy:
|
|
17
|
+
* called with one argument it behaves exactly as it always did, and a caller
|
|
18
|
+
* that has the install's policy and the account can hand them over.
|
|
19
|
+
*/
|
|
20
|
+
export declare function validatePasswordStrength(pwd: string, policy?: AppliedPasswordPolicy, identity?: string): {
|
|
11
21
|
valid: boolean;
|
|
12
22
|
errors: string[];
|
|
13
23
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "nucleus-core-ts",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.23",
|
|
4
4
|
"description": "Production-ready, enterprise-grade TypeScript framework for building multi-tenant APIs",
|
|
5
5
|
"author": "Hidayet Can Özcan <hidayetcan@gmail.com>",
|
|
6
6
|
"license": "SEE LICENSE IN LICENSE",
|