@sixb/server 0.1.18 → 0.1.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 +15 -24
- package/dist/actions/serialize.d.ts +7 -0
- package/dist/actions/serialize.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +4 -26
- package/dist/auth/browser-origin.d.ts.map +1 -1
- package/dist/auth/experience.d.ts +0 -3
- package/dist/auth/experience.d.ts.map +1 -1
- package/dist/auth/guard.d.ts +1 -1
- package/dist/auth/guard.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts +0 -5
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/responses.d.ts +0 -2
- package/dist/auth/responses.d.ts.map +1 -1
- package/dist/auth/session-cookies.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +681 -935
- package/dist/index.js.map +24 -24
- package/dist/routes/action-runs.d.ts +11 -15
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +44 -13
- package/dist/routes/actions.d.ts.map +1 -1
- package/dist/routes/agent-api-gateway.d.ts.map +1 -1
- package/dist/routes/agents.d.ts +20 -22
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +8 -17
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +21 -21
- package/dist/routes/connector-connections.d.ts +8 -8
- package/dist/routes/connectors.d.ts +2 -2
- package/dist/routes/datasets.d.ts +5 -5
- package/dist/routes/events.d.ts +4 -4
- package/dist/routes/files.d.ts +15 -12
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +0 -2
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/ontology.d.ts +6 -6
- package/dist/routes/pipelines.d.ts +16 -16
- package/dist/routes/projections.d.ts +49 -49
- package/dist/routes/syncs.d.ts +10 -10
- package/dist/routes/webhook-runs.d.ts +2 -2
- package/dist/routes/workflows.d.ts +48 -52
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts +6 -9
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/schemas/actions.d.ts +100 -84
- package/dist/schemas/actions.d.ts.map +1 -1
- package/dist/schemas/agents.d.ts +20 -20
- package/dist/schemas/ai-limits.d.ts +10 -10
- package/dist/schemas/auth.d.ts +28 -63
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +8 -8
- package/dist/schemas/datasets.d.ts +40 -40
- package/dist/schemas/events.d.ts +24 -24
- package/dist/schemas/events.d.ts.map +1 -1
- package/dist/schemas/files.d.ts +4 -7
- package/dist/schemas/files.d.ts.map +1 -1
- package/dist/schemas/ontology.d.ts +40 -40
- package/dist/schemas/pipelines.d.ts +92 -92
- package/dist/schemas/projections.d.ts +290 -290
- package/dist/schemas/syncs.d.ts +34 -34
- package/dist/schemas/webhook-runs.d.ts +8 -8
- package/dist/schemas/workflows.d.ts +160 -160
- package/dist/server.d.ts +2 -2
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts.map +1 -1
- package/dist/utils/request-body.d.ts +20 -6
- package/dist/utils/request-body.d.ts.map +1 -1
- package/package.json +7 -7
- package/src/actions/serialize.ts +55 -0
- package/src/auth/browser-origin.ts +30 -240
- package/src/auth/experience.ts +1 -4
- package/src/auth/guard.ts +4 -32
- package/src/auth/public-routes.ts +1 -10
- package/src/auth/responses.ts +0 -5
- package/src/auth/session-cookies.ts +1 -3
- package/src/auth/shared-access.ts +1 -1
- package/src/index.ts +1 -1
- package/src/routes/action-runs.ts +1 -54
- package/src/routes/actions.ts +26 -8
- package/src/routes/agent-api-gateway.ts +18 -42
- package/src/routes/auth.ts +32 -111
- package/src/routes/files.ts +15 -63
- package/src/routes/ws/events.ts +2 -12
- package/src/schemas/actions.ts +21 -18
- package/src/schemas/auth.ts +2 -15
- package/src/schemas/files.ts +0 -6
- package/src/server.ts +23 -18
- package/src/utils/http.ts +2 -0
- package/src/utils/request-body.ts +55 -6
- package/dist/auth/application-access.d.ts +0 -4
- package/dist/auth/application-access.d.ts.map +0 -1
- package/src/auth/application-access.ts +0 -15
package/src/schemas/actions.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { SIXB_ERROR_CODES } from "@sixb/core/internal/errors"
|
|
1
2
|
import {
|
|
2
3
|
ACTION_RUN_FAILURE_CODES,
|
|
3
4
|
ACTION_RUN_PHASES,
|
|
4
5
|
type ActionRunFailure,
|
|
5
6
|
} from "@sixb/core/storage"
|
|
6
7
|
import { z } from "zod"
|
|
7
|
-
import { JsonValueSchema, sixbFailureSchema } from "./common"
|
|
8
|
+
import { codedErrorResponseSchema, JsonValueSchema, sixbFailureSchema } from "./common"
|
|
8
9
|
import { ActionParamSchema } from "./ontology"
|
|
9
10
|
|
|
10
11
|
export const ActionIdParamsSchema = z.object({
|
|
@@ -32,12 +33,19 @@ export const RequestActionBodySchema = z.object({
|
|
|
32
33
|
runId: z.string().min(1).optional(),
|
|
33
34
|
})
|
|
34
35
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
36
|
+
/** A request reused the run id of a run this server is still executing. */
|
|
37
|
+
export const ActionRunInProgressResponseSchema = codedErrorResponseSchema([
|
|
38
|
+
"action.run_in_progress",
|
|
39
|
+
])
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* An unexpected failure. It can follow a run that started: requesting the same `runId` again
|
|
43
|
+
* returns the run's record if it was written, and runs it again otherwise.
|
|
44
|
+
*/
|
|
45
|
+
export const ActionRequestFailedResponseSchema = codedErrorResponseSchema(SIXB_ERROR_CODES)
|
|
46
|
+
|
|
47
|
+
/** The server is stopping and refused the request before starting anything. */
|
|
48
|
+
export const RuntimeStoppingResponseSchema = codedErrorResponseSchema(["runtime.stopping"])
|
|
41
49
|
|
|
42
50
|
export const ActionCatalogItemSchema = z.object({
|
|
43
51
|
id: z.string(),
|
|
@@ -58,13 +66,8 @@ export const ActionDetailSchema = ActionCatalogItemSchema.extend({
|
|
|
58
66
|
inputSchema: z.record(z.unknown()),
|
|
59
67
|
})
|
|
60
68
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
"running",
|
|
64
|
-
"succeeded",
|
|
65
|
-
"failed",
|
|
66
|
-
"cancelled",
|
|
67
|
-
])
|
|
69
|
+
/** How a run ended: a run is recorded once, when it ends. */
|
|
70
|
+
export const ActionRunStatusSchema = z.enum(["succeeded", "failed"])
|
|
68
71
|
|
|
69
72
|
export const ActionRunPhaseSchema = z.enum(ACTION_RUN_PHASES)
|
|
70
73
|
|
|
@@ -116,10 +119,10 @@ export const ActionRunSummarySchema = z.object({
|
|
|
116
119
|
actionId: z.string(),
|
|
117
120
|
subject: ActionSubjectSchema,
|
|
118
121
|
status: ActionRunStatusSchema,
|
|
119
|
-
phase
|
|
120
|
-
|
|
121
|
-
startedAt: z.string()
|
|
122
|
-
finishedAt: z.string()
|
|
122
|
+
/** The last phase the run reached. */
|
|
123
|
+
phase: ActionRunPhaseSchema,
|
|
124
|
+
startedAt: z.string(),
|
|
125
|
+
finishedAt: z.string(),
|
|
123
126
|
error: ActionRunFailureSchema.optional(),
|
|
124
127
|
})
|
|
125
128
|
|
package/src/schemas/auth.ts
CHANGED
|
@@ -179,15 +179,8 @@ export const AuthCreateInvitationCapabilitySchema = z.union([
|
|
|
179
179
|
}),
|
|
180
180
|
])
|
|
181
181
|
|
|
182
|
-
export const AuthInvitationDestinationSchema = z.object({
|
|
183
|
-
id: z.enum(["atlas", "app"]),
|
|
184
|
-
label: z.string(),
|
|
185
|
-
})
|
|
186
|
-
|
|
187
182
|
export const GetAuthInvitationOptionsResponseSchema = z.object({
|
|
188
183
|
groups: z.array(AuthInvitationGroupOptionSchema),
|
|
189
|
-
destinations: z.array(AuthInvitationDestinationSchema),
|
|
190
|
-
defaultDestinationId: z.enum(["atlas", "app"]).optional(),
|
|
191
184
|
canInviteWithoutGroups: z.boolean(),
|
|
192
185
|
capabilities: z.object({
|
|
193
186
|
createInvitation: AuthCreateInvitationCapabilitySchema,
|
|
@@ -196,10 +189,12 @@ export const GetAuthInvitationOptionsResponseSchema = z.object({
|
|
|
196
189
|
|
|
197
190
|
export const GetAuthMembershipOptionsResponseSchema = z.object({
|
|
198
191
|
groups: z.array(AuthGroupOptionSchema),
|
|
192
|
+
serviceAccountGroups: z.array(AuthGroupOptionSchema),
|
|
199
193
|
capabilities: z.object({
|
|
200
194
|
invite: z.boolean(),
|
|
201
195
|
assignGroups: z.boolean(),
|
|
202
196
|
suspend: z.boolean(),
|
|
197
|
+
serviceAccounts: z.boolean(),
|
|
203
198
|
}),
|
|
204
199
|
})
|
|
205
200
|
|
|
@@ -238,7 +233,6 @@ export const ReactivateAuthMemberResponseSchema = z.object({
|
|
|
238
233
|
export const CreateAuthInvitationBodySchema = z.object({
|
|
239
234
|
email: z.string().min(1),
|
|
240
235
|
groupIds: z.array(z.string().min(1)).optional(),
|
|
241
|
-
destinationId: z.enum(["atlas", "app"]).optional(),
|
|
242
236
|
expiresAt: z.string().optional(),
|
|
243
237
|
returnTo: z.string().optional(),
|
|
244
238
|
revealLink: z.boolean().optional(),
|
|
@@ -284,11 +278,6 @@ export const AuthSessionResponseSchema = z.union([
|
|
|
284
278
|
authenticated: z.literal(true),
|
|
285
279
|
/** Browser sessions only: send it back in `x-sixb-csrf` on mutations. */
|
|
286
280
|
csrfToken: z.string().optional(),
|
|
287
|
-
/** Whether the user may open a web app: the browser session's own, or Atlas for a native client. */
|
|
288
|
-
applicationAccess: z.object({
|
|
289
|
-
allowed: z.boolean(),
|
|
290
|
-
audience: z.enum(["atlas", "app"]),
|
|
291
|
-
}),
|
|
292
281
|
user: z.object({
|
|
293
282
|
id: z.string(),
|
|
294
283
|
email: z.string(),
|
|
@@ -352,8 +341,6 @@ export const DeviceAuthorizationDecisionBodySchema = z.object({
|
|
|
352
341
|
|
|
353
342
|
export const AuthSessionSummarySchema = z.object({
|
|
354
343
|
id: z.string(),
|
|
355
|
-
/** The web app a browser session belongs to. Native clients' sessions have none. */
|
|
356
|
-
audience: z.enum(["atlas", "app"]).optional(),
|
|
357
344
|
current: z.boolean(),
|
|
358
345
|
createdAt: z.string(),
|
|
359
346
|
expiresAt: z.string(),
|
package/src/schemas/files.ts
CHANGED
|
@@ -84,12 +84,6 @@ export const CompleteFileUploadBodySchema = z.object({
|
|
|
84
84
|
})
|
|
85
85
|
|
|
86
86
|
export const FileContentQuerySchema = z.object({
|
|
87
|
-
audience: z
|
|
88
|
-
.enum(["atlas", "app"])
|
|
89
|
-
.optional()
|
|
90
|
-
.describe(
|
|
91
|
-
"Session audience for file navigation without Origin; must match Origin when present"
|
|
92
|
-
),
|
|
93
87
|
path: z.string().min(1),
|
|
94
88
|
disposition: z.enum(["inline", "attachment"]).optional(),
|
|
95
89
|
v: z.string().optional().describe("Client cache key; the route still resolves the current file"),
|
package/src/server.ts
CHANGED
|
@@ -5,17 +5,15 @@ import { CSRF_HEADER_NAME, setRequestClientAddress } from "@sixb/core/internal/a
|
|
|
5
5
|
import { bindRequestExecution } from "@sixb/core/internal/request-execution"
|
|
6
6
|
import { setApiPublicOrigin } from "@sixb/core/internal/runtime"
|
|
7
7
|
import type { Server } from "bun"
|
|
8
|
-
import { Elysia } from "elysia"
|
|
8
|
+
import { Elysia, ParseError } from "elysia"
|
|
9
9
|
import { websocket as elysiaWebSocket } from "elysia/ws"
|
|
10
10
|
import { zodToJsonSchema } from "zod-to-json-schema"
|
|
11
11
|
import {
|
|
12
|
-
type AuthInvitationDestinationOptions,
|
|
13
12
|
type AuthInvitationRedirectContext,
|
|
14
13
|
type AuthInvitationRedirectInput,
|
|
15
14
|
BrowserOriginError,
|
|
16
15
|
createApiBrowserAuthContextResolver,
|
|
17
16
|
createApiBrowserAuthRedirectContextResolver,
|
|
18
|
-
getApiBrowserInvitationDestinationOptions,
|
|
19
17
|
isAllowedApiBrowserOrigin,
|
|
20
18
|
type RequestAuthContext,
|
|
21
19
|
type ResolveAuthRedirectContext,
|
|
@@ -56,10 +54,15 @@ import {
|
|
|
56
54
|
import { OPENAPI_TAG_METADATA } from "./openapi/tags"
|
|
57
55
|
import { registerHttpRoutes } from "./registerRoutes"
|
|
58
56
|
import { registerAuthRoutes } from "./routes/auth"
|
|
57
|
+
import { DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES } from "./routes/files"
|
|
59
58
|
import { registerWebhookRoutes } from "./routes/webhooks"
|
|
60
59
|
import { registerWebSocketRoutes } from "./routes/ws"
|
|
61
60
|
import { jsonValueOpenApiOverride } from "./schemas/common"
|
|
62
61
|
import { ObjectQueryOpenApiSchemas } from "./schemas/objects"
|
|
62
|
+
import { limitRequestBody, RequestBodyTooLargeError } from "./utils/request-body"
|
|
63
|
+
|
|
64
|
+
// Clients send only subscription messages; Bun's default would buffer up to 16 MB for one.
|
|
65
|
+
export const MAX_WEBSOCKET_MESSAGE_BYTES = 64 * 1024
|
|
63
66
|
|
|
64
67
|
export interface SixbServerOptions {
|
|
65
68
|
host: SixbHostView
|
|
@@ -141,10 +144,6 @@ export class SixbServer {
|
|
|
141
144
|
return resolveApiBrowserPublicOrigin(this.apiBrowserPolicy, request)
|
|
142
145
|
}
|
|
143
146
|
|
|
144
|
-
getInvitationDestinationOptions(_request: Request): AuthInvitationDestinationOptions {
|
|
145
|
-
return getApiBrowserInvitationDestinationOptions(this.apiBrowserPolicy)
|
|
146
|
-
}
|
|
147
|
-
|
|
148
147
|
resolveInvitationRedirectContext(
|
|
149
148
|
request: Request,
|
|
150
149
|
input: AuthInvitationRedirectInput
|
|
@@ -263,6 +262,13 @@ export function createSixbApi(server: SixbServer) {
|
|
|
263
262
|
}
|
|
264
263
|
return shared.kind === "deny" ? shared.response : undefined
|
|
265
264
|
})
|
|
265
|
+
// A body over its limit fails while Elysia parses it, before the auth guard or handler runs.
|
|
266
|
+
app.onError(({ error, set }) => {
|
|
267
|
+
if (error instanceof ParseError && error.cause instanceof RequestBodyTooLargeError) {
|
|
268
|
+
set.status = 413
|
|
269
|
+
return { error: error.cause.message }
|
|
270
|
+
}
|
|
271
|
+
})
|
|
266
272
|
|
|
267
273
|
// Resolve authentication and bind one execution SDK at the request boundary. Protected routes
|
|
268
274
|
// never choose between a principal SDK and the ambient runtime themselves.
|
|
@@ -427,10 +433,8 @@ export function createSixbApi(server: SixbServer) {
|
|
|
427
433
|
|
|
428
434
|
const authExperience = server.getAuthExperience()
|
|
429
435
|
registerAuthRoutes(app, host, {
|
|
430
|
-
resolveAuthContext: (request) => server.resolveAuthContext(request),
|
|
431
436
|
resolveAuthRedirectContext: (request, input) =>
|
|
432
437
|
server.resolveAuthRedirectContext(request, input),
|
|
433
|
-
getInvitationDestinationOptions: (request) => server.getInvitationDestinationOptions(request),
|
|
434
438
|
resolveAuthRequestOrigin: (request) => server.resolveAuthRequestOrigin(request),
|
|
435
439
|
authExperience: authExperience && { ...authExperience, locale: host.locale },
|
|
436
440
|
resolveInvitationRedirectContext: (request, input) =>
|
|
@@ -439,13 +443,8 @@ export function createSixbApi(server: SixbServer) {
|
|
|
439
443
|
registerHttpRoutes(app, host, {
|
|
440
444
|
sharedAccess,
|
|
441
445
|
connectorConnections: {
|
|
442
|
-
resolveReturnTo: (request, returnTo) =>
|
|
443
|
-
|
|
444
|
-
return server.resolveAuthRedirectContext(request, {
|
|
445
|
-
audience: authContext.audience,
|
|
446
|
-
returnTo,
|
|
447
|
-
}).returnTo
|
|
448
|
-
},
|
|
446
|
+
resolveReturnTo: (request, returnTo) =>
|
|
447
|
+
server.resolveAuthRedirectContext(request, { returnTo }).returnTo,
|
|
449
448
|
resolveCallbackUrl: (request) =>
|
|
450
449
|
new URL("/auth/connectors/callback", server.resolveAuthRequestOrigin(request)).toString(),
|
|
451
450
|
},
|
|
@@ -532,8 +531,13 @@ function startApiServer(
|
|
|
532
531
|
const bunServer = Bun.serve({
|
|
533
532
|
port: options.port,
|
|
534
533
|
hostname: options.host,
|
|
535
|
-
|
|
536
|
-
|
|
534
|
+
// No route reads more than a simple upload form, so Bun rejects anything larger with 413.
|
|
535
|
+
maxRequestBodySize: DEFAULT_SIMPLE_FILE_UPLOAD_BODY_BYTES,
|
|
536
|
+
fetch: (incoming: Request, server: Server<unknown>) => {
|
|
537
|
+
const socketAddress = server.requestIP(incoming)?.address
|
|
538
|
+
// Elysia parses a body before the auth guard runs, so cap it here, as it streams. The capped
|
|
539
|
+
// request replaces this one before any state is keyed to it.
|
|
540
|
+
const request = limitRequestBody(incoming)
|
|
537
541
|
if (socketAddress) {
|
|
538
542
|
const forwardedFor = request.headers.get("x-forwarded-for")
|
|
539
543
|
setRequestClientAddress(request, options.resolveClientAddress(socketAddress, forwardedFor))
|
|
@@ -552,6 +556,7 @@ function getElysiaWsHandler(app: SixbApp) {
|
|
|
552
556
|
return {
|
|
553
557
|
...elysiaWebSocket,
|
|
554
558
|
...(cfg?.websocket ?? {}),
|
|
559
|
+
maxPayloadLength: MAX_WEBSOCKET_MESSAGE_BYTES,
|
|
555
560
|
} as Parameters<typeof Bun.serve>[0]["websocket"]
|
|
556
561
|
}
|
|
557
562
|
|
package/src/utils/http.ts
CHANGED
|
@@ -15,6 +15,7 @@ import { RequestBodyTooLargeError } from "./request-body"
|
|
|
15
15
|
|
|
16
16
|
/** Explicit transport policy for coded failures that are safe to surface as non-500 responses. */
|
|
17
17
|
const HTTP_STATUS_BY_ERROR_CODE: Partial<Record<SixbErrorCode, number>> = {
|
|
18
|
+
"action.run_in_progress": 409,
|
|
18
19
|
"connector.adapter_invalid": 502,
|
|
19
20
|
"connector.authorization_invalid": 400,
|
|
20
21
|
"connector.authorization_required": 409,
|
|
@@ -29,6 +30,7 @@ const HTTP_STATUS_BY_ERROR_CODE: Partial<Record<SixbErrorCode, number>> = {
|
|
|
29
30
|
"connector.revocation_pending": 409,
|
|
30
31
|
"dataset.not_found": 404,
|
|
31
32
|
"dataset.version_not_found": 404,
|
|
33
|
+
"runtime.stopping": 503,
|
|
32
34
|
"ai.usage_limit_exceeded": 429,
|
|
33
35
|
"ai.usage_limit_unavailable": 429,
|
|
34
36
|
}
|
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* Request body limits for the API.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
4
|
+
* Elysia parses a JSON or form body before the auth guard runs, so the server caps every body it
|
|
5
|
+
* receives at `DEFAULT_REQUEST_BODY_LIMIT_BYTES` (`limitRequestBody`). A route that takes more,
|
|
6
|
+
* such as a file upload, reads its own body with `readRequestBodyWithLimit`, whose limit replaces
|
|
7
|
+
* that cap. Both apply the limit DURING streaming (not after buffering), so an oversized or
|
|
8
|
+
* chunked/unknown-length body is rejected before it is fully read.
|
|
8
9
|
*/
|
|
10
|
+
|
|
11
|
+
/** The most a request body may be, unless the route reading it allows more. */
|
|
12
|
+
export const DEFAULT_REQUEST_BODY_LIMIT_BYTES = 1024 * 1024
|
|
13
|
+
|
|
9
14
|
export class RequestBodyTooLargeError extends Error {
|
|
10
15
|
readonly name = "RequestBodyTooLargeError"
|
|
11
16
|
|
|
@@ -17,11 +22,55 @@ export class RequestBodyTooLargeError extends Error {
|
|
|
17
22
|
}
|
|
18
23
|
}
|
|
19
24
|
|
|
25
|
+
const requestBodyCaps = new WeakMap<Request, { lifted: boolean }>()
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Returns `request` with its body capped at `DEFAULT_REQUEST_BODY_LIMIT_BYTES`. Reading past the
|
|
29
|
+
* cap fails with `RequestBodyTooLargeError`, which Elysia surfaces as a parse error.
|
|
30
|
+
*/
|
|
31
|
+
export function limitRequestBody(request: Request): Request {
|
|
32
|
+
if (!request.body) {
|
|
33
|
+
return request
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const cap = { lifted: false }
|
|
37
|
+
let total = 0
|
|
38
|
+
const body = request.body.pipeThrough(
|
|
39
|
+
new TransformStream<Uint8Array, Uint8Array>({
|
|
40
|
+
transform(chunk, controller) {
|
|
41
|
+
total += chunk.byteLength
|
|
42
|
+
if (!cap.lifted && total > DEFAULT_REQUEST_BODY_LIMIT_BYTES) {
|
|
43
|
+
controller.error(new RequestBodyTooLargeError(DEFAULT_REQUEST_BODY_LIMIT_BYTES))
|
|
44
|
+
return
|
|
45
|
+
}
|
|
46
|
+
controller.enqueue(chunk)
|
|
47
|
+
},
|
|
48
|
+
})
|
|
49
|
+
)
|
|
50
|
+
const limited = new Request(request, { body, duplex: "half" } as RequestInit & {
|
|
51
|
+
duplex: "half"
|
|
52
|
+
})
|
|
53
|
+
requestBodyCaps.set(limited, cap)
|
|
54
|
+
return limited
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* Reads a request body fully into memory, failing once it passes `limitBytes`. That limit
|
|
59
|
+
* replaces the server's default cap for this request, so a route reading more than the default
|
|
60
|
+
* must authenticate the caller first. The `content-length` header, when present, only provides an
|
|
61
|
+
* early fast-path.
|
|
62
|
+
*/
|
|
20
63
|
export async function readRequestBodyWithLimit(
|
|
21
64
|
request: Request,
|
|
22
65
|
limitBytes: number,
|
|
23
66
|
tooLargeMessage?: string
|
|
24
|
-
): Promise<Uint8Array
|
|
67
|
+
): Promise<Uint8Array<ArrayBuffer>> {
|
|
68
|
+
// The loop below enforces `limitBytes` in place of the server's cap.
|
|
69
|
+
const cap = requestBodyCaps.get(request)
|
|
70
|
+
if (cap) {
|
|
71
|
+
cap.lifted = true
|
|
72
|
+
}
|
|
73
|
+
|
|
25
74
|
const contentLength = request.headers.get("content-length")
|
|
26
75
|
if (contentLength !== null) {
|
|
27
76
|
const declared = Number(contentLength)
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import { type AuthSessionAudience, type SixbHostView } from "@sixb/core";
|
|
2
|
-
import type { AuthenticatedRequestAuthSession } from "@sixb/core/internal/auth";
|
|
3
|
-
export declare function sessionCanAccessApplication(host: SixbHostView, session: AuthenticatedRequestAuthSession, audience: AuthSessionAudience): boolean;
|
|
4
|
-
//# sourceMappingURL=application-access.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"application-access.d.ts","sourceRoot":"","sources":["../../src/auth/application-access.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,mBAAmB,EAAwB,KAAK,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9F,OAAO,KAAK,EAAE,+BAA+B,EAAE,MAAM,0BAA0B,CAAA;AAE/E,wBAAgB,2BAA2B,CACzC,IAAI,EAAE,YAAY,EAClB,OAAO,EAAE,+BAA+B,EACxC,QAAQ,EAAE,mBAAmB,GAC5B,OAAO,CAOT"}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { type AuthSessionAudience, canAccessApplication, type SixbHostView } from "@sixb/core"
|
|
2
|
-
import type { AuthenticatedRequestAuthSession } from "@sixb/core/internal/auth"
|
|
3
|
-
|
|
4
|
-
export function sessionCanAccessApplication(
|
|
5
|
-
host: SixbHostView,
|
|
6
|
-
session: AuthenticatedRequestAuthSession,
|
|
7
|
-
audience: AuthSessionAudience
|
|
8
|
-
): boolean {
|
|
9
|
-
const authorization = host.auth.contextFromSession(session)
|
|
10
|
-
return canAccessApplication(
|
|
11
|
-
authorization,
|
|
12
|
-
host.definitions.security.listResolvedRoles(),
|
|
13
|
-
audience
|
|
14
|
-
)
|
|
15
|
-
}
|