or3-provider-basic-auth 0.0.19 → 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
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
|
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];
|