@antelopejs/interface-dms 0.17.6 → 0.17.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/auth/password.d.ts +42 -5
- package/dist/auth/password.js +57 -11
- package/dist/auth/password.js.map +1 -1
- package/docs/2.auth/1.introduction.md +2 -2
- package/docs/2.auth/4.users.md +5 -2
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## v0.17.7
|
|
4
|
+
|
|
5
|
+
[compare changes](https://github.com/AntelopeJS/dms/compare/interface-v0.17.6...interface-v0.17.7)
|
|
6
|
+
|
|
7
|
+
### 🩹 Fixes
|
|
8
|
+
|
|
9
|
+
- **auth:** Accept any non-control character in passwords ([#1455](https://github.com/AntelopeJS/dms/pull/1455))
|
|
10
|
+
|
|
11
|
+
### ❤️ Contributors
|
|
12
|
+
|
|
13
|
+
- Antony Rizzitelli
|
|
14
|
+
|
|
3
15
|
## v0.17.6
|
|
4
16
|
|
|
5
17
|
[compare changes](https://github.com/AntelopeJS/dms/compare/interface-v0.17.5...interface-v0.17.6)
|
package/dist/auth/password.d.ts
CHANGED
|
@@ -1,14 +1,51 @@
|
|
|
1
|
-
/** Minimum number of characters a password must have. */
|
|
1
|
+
/** Minimum number of characters a password must have, once normalized. */
|
|
2
2
|
export declare const PASSWORD_MIN_LENGTH = 8;
|
|
3
|
+
/**
|
|
4
|
+
* Maximum number of characters a password may have, once normalized. Counted
|
|
5
|
+
* in UTF-16 code units, the way `string.length` and zod's `.max` count.
|
|
6
|
+
*/
|
|
7
|
+
export declare const PASSWORD_MAX_LENGTH = 128;
|
|
8
|
+
/** Identifies one rule of the password policy. */
|
|
9
|
+
export type PasswordRuleId = "length" | "uppercase" | "digit" | "special" | "characters";
|
|
10
|
+
/** One rule of the password policy. */
|
|
11
|
+
export interface PasswordRule {
|
|
12
|
+
/** Stable identifier of the rule, to label it or key a message. */
|
|
13
|
+
readonly id: PasswordRuleId;
|
|
14
|
+
/**
|
|
15
|
+
* Whether a password satisfies this rule.
|
|
16
|
+
*
|
|
17
|
+
* @param password Candidate password, already normalized with
|
|
18
|
+
* `normalizePassword`
|
|
19
|
+
*/
|
|
20
|
+
test(password: string): boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* The rules of the DMS password policy, in display order: between
|
|
24
|
+
* `PASSWORD_MIN_LENGTH` and `PASSWORD_MAX_LENGTH` characters, one uppercase
|
|
25
|
+
* letter, one digit, one special character (neither a letter nor a digit,
|
|
26
|
+
* a space included) and no control character. Each `test` takes a password
|
|
27
|
+
* already normalized with `normalizePassword`.
|
|
28
|
+
*/
|
|
29
|
+
export declare const PASSWORD_RULES: readonly PasswordRule[];
|
|
3
30
|
/**
|
|
4
31
|
* The character rules of the policy, without the length: at least one
|
|
5
|
-
* uppercase letter, one digit and one
|
|
6
|
-
*
|
|
32
|
+
* uppercase letter, one digit and one special character (neither a letter nor
|
|
33
|
+
* a digit), and no control character. The `s` flag lets `.` cross U+2028 and
|
|
34
|
+
* U+2029, which are not control characters.
|
|
7
35
|
*/
|
|
8
36
|
export declare const PASSWORD_PATTERN: RegExp;
|
|
9
37
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
38
|
+
* The form every DMS flow hashes and compares a password in: Unicode
|
|
39
|
+
* normalization form C, so the same text typed on two keyboards is one
|
|
40
|
+
* password. An ASCII password is unchanged, so stored passwords keep matching.
|
|
41
|
+
*
|
|
42
|
+
* @param password Password as typed
|
|
43
|
+
* @returns The NFC form of the password
|
|
44
|
+
*/
|
|
45
|
+
export declare function normalizePassword(password: string): string;
|
|
46
|
+
/**
|
|
47
|
+
* Whether a password satisfies the DMS password policy: every rule of
|
|
48
|
+
* `PASSWORD_RULES`, checked on its `normalizePassword` form.
|
|
12
49
|
*
|
|
13
50
|
* @param password Candidate password, in clear
|
|
14
51
|
* @returns True when the DMS would accept the password
|
package/dist/auth/password.js
CHANGED
|
@@ -1,28 +1,74 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.PASSWORD_PATTERN = exports.PASSWORD_MIN_LENGTH = void 0;
|
|
3
|
+
exports.PASSWORD_PATTERN = exports.PASSWORD_RULES = exports.PASSWORD_MAX_LENGTH = exports.PASSWORD_MIN_LENGTH = void 0;
|
|
4
|
+
exports.normalizePassword = normalizePassword;
|
|
4
5
|
exports.isPasswordCompliant = isPasswordCompliant;
|
|
5
|
-
/** Minimum number of characters a password must have. */
|
|
6
|
+
/** Minimum number of characters a password must have, once normalized. */
|
|
6
7
|
exports.PASSWORD_MIN_LENGTH = 8;
|
|
7
8
|
/**
|
|
8
|
-
*
|
|
9
|
-
*
|
|
9
|
+
* Maximum number of characters a password may have, once normalized. Counted
|
|
10
|
+
* in UTF-16 code units, the way `string.length` and zod's `.max` count.
|
|
10
11
|
*/
|
|
11
|
-
|
|
12
|
+
exports.PASSWORD_MAX_LENGTH = 128;
|
|
13
|
+
/** An uppercase letter of any script, an accented capital included. */
|
|
14
|
+
const UPPERCASE = /\p{Lu}/u;
|
|
15
|
+
/** A decimal digit of any script. */
|
|
16
|
+
const DIGIT = /\p{Nd}/u;
|
|
17
|
+
/**
|
|
18
|
+
* A special character: anything that is neither a letter nor a digit, so a
|
|
19
|
+
* symbol, a punctuation mark or a space.
|
|
20
|
+
*/
|
|
21
|
+
const SPECIAL = /[^\p{L}\p{Nd}]/u;
|
|
22
|
+
/** A non-empty password with no control character in any position. */
|
|
23
|
+
const NO_CONTROL_CHARACTER = /^[^\p{Cc}]+$/u;
|
|
24
|
+
/**
|
|
25
|
+
* The rules of the DMS password policy, in display order: between
|
|
26
|
+
* `PASSWORD_MIN_LENGTH` and `PASSWORD_MAX_LENGTH` characters, one uppercase
|
|
27
|
+
* letter, one digit, one special character (neither a letter nor a digit,
|
|
28
|
+
* a space included) and no control character. Each `test` takes a password
|
|
29
|
+
* already normalized with `normalizePassword`.
|
|
30
|
+
*/
|
|
31
|
+
exports.PASSWORD_RULES = [
|
|
32
|
+
{
|
|
33
|
+
id: "length",
|
|
34
|
+
test: (password) => password.length >= exports.PASSWORD_MIN_LENGTH &&
|
|
35
|
+
password.length <= exports.PASSWORD_MAX_LENGTH,
|
|
36
|
+
},
|
|
37
|
+
{ id: "uppercase", test: (password) => UPPERCASE.test(password) },
|
|
38
|
+
{ id: "digit", test: (password) => DIGIT.test(password) },
|
|
39
|
+
{ id: "special", test: (password) => SPECIAL.test(password) },
|
|
40
|
+
{
|
|
41
|
+
id: "characters",
|
|
42
|
+
test: (password) => NO_CONTROL_CHARACTER.test(password),
|
|
43
|
+
},
|
|
44
|
+
];
|
|
12
45
|
/**
|
|
13
46
|
* The character rules of the policy, without the length: at least one
|
|
14
|
-
* uppercase letter, one digit and one
|
|
15
|
-
*
|
|
47
|
+
* uppercase letter, one digit and one special character (neither a letter nor
|
|
48
|
+
* a digit), and no control character. The `s` flag lets `.` cross U+2028 and
|
|
49
|
+
* U+2029, which are not control characters.
|
|
16
50
|
*/
|
|
17
|
-
exports.PASSWORD_PATTERN = new RegExp(
|
|
51
|
+
exports.PASSWORD_PATTERN = new RegExp(`(?=.*${UPPERCASE.source})(?=.*${DIGIT.source})(?=.*${SPECIAL.source})${NO_CONTROL_CHARACTER.source}`, "su");
|
|
52
|
+
/**
|
|
53
|
+
* The form every DMS flow hashes and compares a password in: Unicode
|
|
54
|
+
* normalization form C, so the same text typed on two keyboards is one
|
|
55
|
+
* password. An ASCII password is unchanged, so stored passwords keep matching.
|
|
56
|
+
*
|
|
57
|
+
* @param password Password as typed
|
|
58
|
+
* @returns The NFC form of the password
|
|
59
|
+
*/
|
|
60
|
+
function normalizePassword(password) {
|
|
61
|
+
return password.normalize("NFC");
|
|
62
|
+
}
|
|
18
63
|
/**
|
|
19
|
-
* Whether a password satisfies the DMS password policy:
|
|
20
|
-
* `
|
|
64
|
+
* Whether a password satisfies the DMS password policy: every rule of
|
|
65
|
+
* `PASSWORD_RULES`, checked on its `normalizePassword` form.
|
|
21
66
|
*
|
|
22
67
|
* @param password Candidate password, in clear
|
|
23
68
|
* @returns True when the DMS would accept the password
|
|
24
69
|
*/
|
|
25
70
|
function isPasswordCompliant(password) {
|
|
26
|
-
|
|
71
|
+
const normalized = normalizePassword(password);
|
|
72
|
+
return exports.PASSWORD_RULES.every((rule) => rule.test(normalized));
|
|
27
73
|
}
|
|
28
74
|
//# sourceMappingURL=password.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"password.js","sourceRoot":"","sources":["../../src/auth/password.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"password.js","sourceRoot":"","sources":["../../src/auth/password.ts"],"names":[],"mappings":";;;;;AAAA,0EAA0E;AAC7D,QAAA,mBAAmB,GAAG,CAAC,CAAC;AAErC;;;GAGG;AACU,QAAA,mBAAmB,GAAG,GAAG,CAAC;AAEvC,uEAAuE;AACvE,MAAM,SAAS,GAAG,SAAS,CAAC;AAE5B,qCAAqC;AACrC,MAAM,KAAK,GAAG,SAAS,CAAC;AAExB;;;GAGG;AACH,MAAM,OAAO,GAAG,iBAAiB,CAAC;AAElC,sEAAsE;AACtE,MAAM,oBAAoB,GAAG,eAAe,CAAC;AAuB7C;;;;;;GAMG;AACU,QAAA,cAAc,GAA4B;IACrD;QACE,EAAE,EAAE,QAAQ;QACZ,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CACjB,QAAQ,CAAC,MAAM,IAAI,QAAA,mBAAmB;YACtC,QAAQ,CAAC,MAAM,IAAI,QAAA,mBAAmB;KACzC;IACD,EAAE,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,SAAS,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;IACjE,EAAE,EAAE,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,KAAK,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;IACzD,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,OAAO,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAE;IAC7D;QACE,EAAE,EAAE,YAAY;QAChB,IAAI,EAAE,CAAC,QAAQ,EAAE,EAAE,CAAC,oBAAoB,CAAC,IAAI,CAAC,QAAQ,CAAC;KACxD;CACF,CAAC;AAEF;;;;;GAKG;AACU,QAAA,gBAAgB,GAAG,IAAI,MAAM,CACxC,QAAQ,SAAS,CAAC,MAAM,SAAS,KAAK,CAAC,MAAM,SAAS,OAAO,CAAC,MAAM,IAAI,oBAAoB,CAAC,MAAM,EAAE,EACrG,IAAI,CACL,CAAC;AAEF;;;;;;;GAOG;AACH,2BAAkC,QAAgB;IAChD,OAAO,QAAQ,CAAC,SAAS,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC;AAED;;;;;;GAMG;AACH,6BAAoC,QAAgB;IAClD,MAAM,UAAU,GAAG,iBAAiB,CAAC,QAAQ,CAAC,CAAC;IAC/C,OAAO,QAAA,cAAc,CAAC,KAAK,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC,IAAI,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC;AAC/D,CAAC"}
|
|
@@ -16,7 +16,7 @@ The domain is published under three subpaths:
|
|
|
16
16
|
| ------- | -------- |
|
|
17
17
|
| `@antelopejs/interface-dms/auth` | The authentication decorators, `authenticateRequestUser`, the token generators and validators, `createSession`, `sanitizeUser`, the external-identity functions, `announceRegistration`, the account mail functions, `bindVerifiedRequestIdentity`, and the `RequestPrincipal`, `RequestAuthenticator` and `VerifiedRequestIdentity` types. |
|
|
18
18
|
| `@antelopejs/interface-dms/auth/db` | The `User`, `Session` and `UserExternalIdentity` tables, their models, the table-name constants, `normalizeEmail`, `isCurrentRefreshToken` and `buildExternalIdentityId`. |
|
|
19
|
-
| `@antelopejs/interface-dms/auth/password` | The password policy: `PASSWORD_MIN_LENGTH`, `PASSWORD_PATTERN` and `isPasswordCompliant`. These are plain values and
|
|
19
|
+
| `@antelopejs/interface-dms/auth/password` | The password policy: `PASSWORD_MIN_LENGTH`, `PASSWORD_MAX_LENGTH`, `PASSWORD_PATTERN`, `PASSWORD_RULES`, `normalizePassword` and `isPasswordCompliant`. These are plain values and pure functions, usable without the DMS loaded. |
|
|
20
20
|
|
|
21
21
|
## What the domain provides
|
|
22
22
|
|
|
@@ -29,7 +29,7 @@ The domain is published under three subpaths:
|
|
|
29
29
|
- **The user table and model.** The `User` table hashes passwords through `HashModifier`. `UserModel` looks users up by email and by owner flag.
|
|
30
30
|
- **External login providers.** `linkExternalIdentity` binds the accounts a user owns on GitHub, Google, or any configured provider. On the next login, the DMS resolves the provider profile back to the user.
|
|
31
31
|
- **Safe responses.** `sanitizeUser` strips authentication secrets from a user before you return it over HTTP.
|
|
32
|
-
- **One password policy.** `isPasswordCompliant` checks a password against the policy the DMS enforces, so the signup of a module accepts exactly what the DMS accepts.
|
|
32
|
+
- **One password policy.** `isPasswordCompliant` checks a password against the policy the DMS enforces, and `normalizePassword` gives the form to hash and compare, so the signup of a module accepts exactly what the DMS accepts.
|
|
33
33
|
- **Account emails.** The domain sends the second-factor, email-validation, password-reset and invite messages that the authentication flows depend on.
|
|
34
34
|
- **One registration path.** `announceRegistration` runs the notifications and the `USER_REGISTERED` hook, whichever flow created the account.
|
|
35
35
|
|
package/docs/2.auth/4.users.md
CHANGED
|
@@ -257,13 +257,16 @@ export async function requestPasswordReset(
|
|
|
257
257
|
|
|
258
258
|
## Password policy
|
|
259
259
|
|
|
260
|
-
`@antelopejs/interface-dms/auth/password` exports the policy every DMS flow applies when a password is set. A password
|
|
260
|
+
`@antelopejs/interface-dms/auth/password` exports the policy every DMS flow applies when a password is set. A password has between `PASSWORD_MIN_LENGTH` (8) and `PASSWORD_MAX_LENGTH` (128) characters, with at least one uppercase letter, one digit and one special character. A special character is any character that is neither a letter nor a digit, so a symbol, a punctuation mark or a space counts. Any character is allowed except control characters (tab, line break, `U+007F`), so a password that holds spaces or non-ASCII letters is valid. `PASSWORD_PATTERN` holds the character rules without the length, and `PASSWORD_RULES` lists each rule with its `id` (`length`, `uppercase`, `digit`, `special` or `characters`) and a `test` function, to show which rule a password misses.
|
|
261
261
|
|
|
262
262
|
```typescript fragment
|
|
263
263
|
isPasswordCompliant(password: string): boolean
|
|
264
|
+
normalizePassword(password: string): string
|
|
264
265
|
```
|
|
265
266
|
|
|
266
|
-
`
|
|
267
|
+
`normalizePassword` returns the Unicode NFC form of a password. Every DMS flow hashes and compares that form, so the same text typed on two keyboards is one password. An ASCII password is unchanged, so stored passwords keep matching. The length is counted after the normalization.
|
|
268
|
+
|
|
269
|
+
`isPasswordCompliant` is a pure function, not an interface call, so it works without the DMS loaded. It normalizes the password before it checks the rules. Call it from any flow you own that stores a password, such as a public signup, and hash the `normalizePassword` form of the password. Your module then accepts exactly the passwords the DMS accepts, and a user signs in with either form of the same text.
|
|
267
270
|
|
|
268
271
|
## Announce a registration
|
|
269
272
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@antelopejs/interface-dms",
|
|
3
|
-
"version": "0.17.
|
|
3
|
+
"version": "0.17.7",
|
|
4
4
|
"description": "Public AntelopeJS interfaces of the DMS: pages, components, permissions, tenancy, auth, notifications and HTML rendering.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"antelopejs",
|
|
@@ -131,7 +131,7 @@
|
|
|
131
131
|
"provenance": true,
|
|
132
132
|
"registry": "https://registry.npmjs.org/"
|
|
133
133
|
},
|
|
134
|
-
"gitHead": "
|
|
134
|
+
"gitHead": "ccaa3e4caabcb9511038495a02dd0f7f2ccbf85b",
|
|
135
135
|
"scripts": {
|
|
136
136
|
"build": "rimraf dist && antelopejs-tsc",
|
|
137
137
|
"typecheck": "antelopejs-tsc --noEmit",
|