or3-provider-basic-auth 0.0.19 → 0.0.21
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
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
|
|
@@ -353,8 +358,8 @@ The updated host and SQLite or Convex store must provide short-code resolution.
|
|
|
353
358
|
|
|
354
359
|
### Session and account feedback
|
|
355
360
|
|
|
356
|
-
The sidebar reads the host's shared session and emits `or3:auth-session-changed` after sign-in, registration, sign-out, or a password change. The host owns refreshing the session and deciding whether account changes require a reload. Session probes disable automatic request retries.
|
|
361
|
+
The sidebar reads the host's shared session and emits `or3:auth-session-changed` after sign-in, registration, sign-out, or a password change. The host owns refreshing the session and deciding whether account changes require a reload. After sign-in from a signed-out page, the host can defer publishing the session until the reload so the new page starts sync once. It publishes confirmed sign-outs and account or workspace switches before reload so local cleanup can run. Session probes disable automatic request retries and report an indeterminate status when the session endpoint fails. If the auth-change refresh is rate-limited, its notification displays the server’s retry window and permits retry after it ends.
|
|
357
362
|
|
|
358
363
|
Invite-only registration marks the code as required before submission. Invalid or expired invitation messages explain the next step for the current registration mode. Sign-out also clears the pending invitation cookie so it cannot apply to another signup. Password changes explain that all sessions are revoked, report incorrect-password and rate-limit errors, and show a one-time confirmation on the sign-in screen.
|
|
359
364
|
|
|
360
|
-
|
|
365
|
+
Indeterminate session status requires `or3-provider-basic-auth@0.0.21` or later and a host that handles the indeterminate result.
|
package/dist/module.json
CHANGED
|
@@ -21,7 +21,8 @@ export default defineNuxtPlugin(() => {
|
|
|
21
21
|
registerClientSessionRecovery(async () => silentRefreshOnce());
|
|
22
22
|
registerClientAuthStatusResolver(async () => {
|
|
23
23
|
const first = await fetchSession();
|
|
24
|
-
|
|
24
|
+
if (!first) return { ready: true, authenticated: void 0 };
|
|
25
|
+
const firstSession = first.session;
|
|
25
26
|
if (firstSession?.authenticated === true && firstSession.provider === "basic-auth") {
|
|
26
27
|
return { ready: true, authenticated: true };
|
|
27
28
|
}
|
|
@@ -30,7 +31,8 @@ export default defineNuxtPlugin(() => {
|
|
|
30
31
|
return { ready: true, authenticated: false };
|
|
31
32
|
}
|
|
32
33
|
const second = await fetchSession();
|
|
33
|
-
|
|
34
|
+
if (!second) return { ready: true, authenticated: void 0 };
|
|
35
|
+
const secondSession = second.session;
|
|
34
36
|
const authenticated = secondSession?.authenticated === true && secondSession.provider === "basic-auth";
|
|
35
37
|
return { ready: true, authenticated };
|
|
36
38
|
});
|
|
@@ -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];
|