or3-provider-basic-auth 0.0.18 → 0.0.20
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/README.md +11 -0
- package/dist/module.json +1 -1
- package/dist/runtime/server/api/basic-auth/_helpers.js +33 -2
- package/dist/runtime/server/lib/password.d.ts +1 -0
- package/dist/runtime/server/lib/password.js +8 -1
- package/dist/runtime/server/plugins/register.js +5 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,6 +5,11 @@ Basic-auth provider for OR3 Chat SSR mode.
|
|
|
5
5
|
Rejected registration requests preserve existing login cookies, including when
|
|
6
6
|
the request fails the mutation origin policy. Sign-out still clears the session.
|
|
7
7
|
|
|
8
|
+
Sign-in, registration, and password-change request bodies are limited to **16 KiB**
|
|
9
|
+
before parsing. Both declared and streamed bodies over that limit receive HTTP
|
|
10
|
+
`413`; incomplete oversized uploads are closed after the response. Existing JSON
|
|
11
|
+
and URL-encoded form requests retain their parsing and validation behavior.
|
|
12
|
+
|
|
8
13
|
After credentials are accepted, OR3 Chat loads the canonical workspace session.
|
|
9
14
|
Updated hosts show a persistent **Unable to load your account** notification
|
|
10
15
|
with **Retry** if that step fails. Retry reuses the accepted credentials, so a
|
|
@@ -198,6 +203,12 @@ Optional:
|
|
|
198
203
|
- `OR3_BASIC_AUTH_ALLOW_INSECURE_DEV` (`true` in non-production to start with missing secrets instead of failing)
|
|
199
204
|
- `OR3_PLUGIN_DEV_COOKIE_SCOPE` (set by the isolated plugin development launcher to keep browser sessions separate across local hosts)
|
|
200
205
|
|
|
206
|
+
When both bootstrap values are set, the first account is created before the
|
|
207
|
+
server accepts requests. An existing account is preserved on restart; changing
|
|
208
|
+
the bootstrap password does not reset it. Bootstrap errors stop startup rather
|
|
209
|
+
than leaving the server available with an unusable initial login. Request-time
|
|
210
|
+
password hashing remains asynchronous.
|
|
211
|
+
|
|
201
212
|
Registration mode is a core-auth policy, not a provider setting:
|
|
202
213
|
|
|
203
214
|
- `OR3_AUTH_REGISTRATION_MODE=open|invite_only|disabled`
|
package/dist/module.json
CHANGED
|
@@ -1,7 +1,38 @@
|
|
|
1
1
|
import { useRuntimeConfig } from "#imports";
|
|
2
|
-
import { createError, readBody, setResponseHeader } from "h3";
|
|
2
|
+
import { createError, getHeader, readBody, setResponseHeader } from "h3";
|
|
3
3
|
import { validateBasicAuthConfig } from "../../lib/config.js";
|
|
4
4
|
import { createAuthNotConfiguredError, createInvalidRequestError } from "../../lib/errors.js";
|
|
5
|
+
const AUTH_BODY_LIMIT_BYTES = 16 * 1024;
|
|
6
|
+
function payloadTooLarge(event) {
|
|
7
|
+
event.node.res.shouldKeepAlive = false;
|
|
8
|
+
event.node.req.pause();
|
|
9
|
+
return createError({ statusCode: 413, statusMessage: "The request body is too large." });
|
|
10
|
+
}
|
|
11
|
+
async function readLimitedBody(event) {
|
|
12
|
+
const declared = getHeader(event, "content-length");
|
|
13
|
+
if (declared !== void 0) {
|
|
14
|
+
const length2 = Number(declared);
|
|
15
|
+
if (!Number.isSafeInteger(length2) || length2 < 0 || length2 > AUTH_BODY_LIMIT_BYTES) {
|
|
16
|
+
throw payloadTooLarge(event);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
const chunks = [];
|
|
20
|
+
let length = 0;
|
|
21
|
+
try {
|
|
22
|
+
const stream = event.node.req.iterator({ destroyOnReturn: false });
|
|
23
|
+
for await (const chunk of stream) {
|
|
24
|
+
const bytes = Buffer.isBuffer(chunk) ? chunk : Buffer.from(chunk);
|
|
25
|
+
length += bytes.byteLength;
|
|
26
|
+
if (length > AUTH_BODY_LIMIT_BYTES) throw payloadTooLarge(event);
|
|
27
|
+
chunks.push(bytes);
|
|
28
|
+
}
|
|
29
|
+
} catch (error) {
|
|
30
|
+
if (error && typeof error === "object" && "statusCode" in error && error.statusCode === 413) throw error;
|
|
31
|
+
throw createInvalidRequestError();
|
|
32
|
+
}
|
|
33
|
+
event._requestBody = new Uint8Array(Buffer.concat(chunks, length));
|
|
34
|
+
return readBody(event);
|
|
35
|
+
}
|
|
5
36
|
export function assertBasicAuthReady(event) {
|
|
6
37
|
const diagnostics = validateBasicAuthConfig(useRuntimeConfig(event));
|
|
7
38
|
if (!diagnostics.config.enabled || diagnostics.config.providerId !== "basic-auth") {
|
|
@@ -12,7 +43,7 @@ export function assertBasicAuthReady(event) {
|
|
|
12
43
|
}
|
|
13
44
|
}
|
|
14
45
|
export async function parseBodyWithSchema(event, schema) {
|
|
15
|
-
const body = await
|
|
46
|
+
const body = await readLimitedBody(event);
|
|
16
47
|
const result = schema.safeParse(body);
|
|
17
48
|
if (!result.success) {
|
|
18
49
|
const firstIssue = result.error.issues[0];
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import bcrypt from "bcryptjs";
|
|
2
2
|
import { newPasswordFitsBcrypt } from "../../password-policy.js";
|
|
3
3
|
const PASSWORD_COST = 12;
|
|
4
|
-
|
|
4
|
+
function assertPasswordLength(password) {
|
|
5
5
|
if (!newPasswordFitsBcrypt(password)) {
|
|
6
6
|
throw new RangeError("New passwords must be 72 UTF-8 bytes or fewer.");
|
|
7
7
|
}
|
|
8
|
+
}
|
|
9
|
+
export function hashPasswordSync(password) {
|
|
10
|
+
assertPasswordLength(password);
|
|
11
|
+
return bcrypt.hashSync(password, PASSWORD_COST);
|
|
12
|
+
}
|
|
13
|
+
export async function hashPassword(password) {
|
|
14
|
+
assertPasswordLength(password);
|
|
8
15
|
return await bcrypt.hash(password, PASSWORD_COST);
|
|
9
16
|
}
|
|
10
17
|
export async function verifyPassword(password, hash) {
|
|
@@ -12,10 +12,10 @@ import {
|
|
|
12
12
|
isBasicAuthInsecureDevEscapeHatchEnabled,
|
|
13
13
|
validateBasicAuthConfig
|
|
14
14
|
} from "../lib/config.js";
|
|
15
|
-
import {
|
|
15
|
+
import { hashPasswordSync } from "../lib/password.js";
|
|
16
16
|
import { ensureBootstrapAccount, findAccountByEmail } from "../lib/session-store.js";
|
|
17
17
|
import { basicAuthAdminAdapter } from "../admin/adapters/auth-basic-auth.js";
|
|
18
|
-
|
|
18
|
+
function ensureBootstrapUserIfConfigured() {
|
|
19
19
|
const config = getBasicAuthConfig();
|
|
20
20
|
const email = config.bootstrapEmail?.trim();
|
|
21
21
|
const password = config.bootstrapPassword;
|
|
@@ -25,14 +25,14 @@ async function ensureBootstrapUserIfConfigured() {
|
|
|
25
25
|
if (findAccountByEmail(email)) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
28
|
-
const passwordHash =
|
|
28
|
+
const passwordHash = hashPasswordSync(password);
|
|
29
29
|
ensureBootstrapAccount({
|
|
30
30
|
email,
|
|
31
31
|
passwordHash,
|
|
32
32
|
displayName: email
|
|
33
33
|
});
|
|
34
34
|
}
|
|
35
|
-
export default defineNitroPlugin(
|
|
35
|
+
export default defineNitroPlugin(() => {
|
|
36
36
|
const runtimeConfig = useRuntimeConfig();
|
|
37
37
|
const diagnostics = validateBasicAuthConfig(runtimeConfig);
|
|
38
38
|
for (const warning of diagnostics.warnings) {
|
|
@@ -54,6 +54,7 @@ export default defineNitroPlugin(async () => {
|
|
|
54
54
|
}
|
|
55
55
|
throw new Error(message);
|
|
56
56
|
}
|
|
57
|
+
ensureBootstrapUserIfConfigured();
|
|
57
58
|
registerAuthProvider({
|
|
58
59
|
id: BASIC_AUTH_PROVIDER_ID,
|
|
59
60
|
order: 100,
|
|
@@ -61,5 +62,4 @@ export default defineNitroPlugin(async () => {
|
|
|
61
62
|
});
|
|
62
63
|
registerProviderTokenBroker(BASIC_AUTH_PROVIDER_ID, createBasicAuthTokenBroker);
|
|
63
64
|
registerProviderAdminAdapter(basicAuthAdminAdapter);
|
|
64
|
-
await ensureBootstrapUserIfConfigured();
|
|
65
65
|
});
|