@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/dist/server.d.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
1
|
import type { SixbHostView } from "@sixb/core";
|
|
2
2
|
import { Elysia } from "elysia";
|
|
3
|
-
import { type
|
|
3
|
+
import { type AuthInvitationRedirectContext, type AuthInvitationRedirectInput, type RequestAuthContext, type ResolveAuthRedirectContext, type ResolvedSixbApiBrowserPolicy, type SixbApiBrowserPolicy } from "./auth/browser-origin";
|
|
4
4
|
import type { SixbAuthExperienceOptions } from "./auth/experience";
|
|
5
5
|
import { type SixbSharedAccessOptions } from "./auth/shared-access";
|
|
6
|
+
export declare const MAX_WEBSOCKET_MESSAGE_BYTES: number;
|
|
6
7
|
export interface SixbServerOptions {
|
|
7
8
|
host: SixbHostView;
|
|
8
9
|
port?: number;
|
|
@@ -40,7 +41,6 @@ export declare class SixbServer {
|
|
|
40
41
|
resolveAuthContext(request: Request): RequestAuthContext;
|
|
41
42
|
resolveAuthRedirectContext(request: Parameters<ResolveAuthRedirectContext>[0], input: Parameters<ResolveAuthRedirectContext>[1]): ReturnType<ResolveAuthRedirectContext>;
|
|
42
43
|
resolveAuthRequestOrigin(request: Request): string;
|
|
43
|
-
getInvitationDestinationOptions(_request: Request): AuthInvitationDestinationOptions;
|
|
44
44
|
resolveInvitationRedirectContext(request: Request, input: AuthInvitationRedirectInput): AuthInvitationRedirectContext;
|
|
45
45
|
getApiBrowserPolicy(): ResolvedSixbApiBrowserPolicy;
|
|
46
46
|
getAuthExperience(): SixbAuthExperienceOptions | undefined;
|
package/dist/server.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,YAAY,EAAE,MA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../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,KAAK,iBAAiB,EACtB,KAAK,aAAa,EACnB,MAAM,YAAY,CAAA;AA+BnB,UAAU,gBAAgB;IACxB,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;IACxB,OAAO,CAAC,EAAE,OAAO,CAAA;CAClB;AAED,wBAAgB,WAAW,CAAC,KAAK,EAAE,IAAI,GAAG,MAAM,CAE/C;AAED,wBAAgB,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,IAAI,GAAG,SAAS,CAWrE;AAED,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,SAAS,GAAG,MAAM,GAAG,SAAS,CAW9E;AAED;;;;;;;;GAQG;AACH,wBAAgB,2BAA2B,CACzC,GAAG,EAAE;IAAE,MAAM,CAAC,EAAE,MAAM,GAAG,MAAM,CAAA;CAAE,EACjC,IAAI,EAAE,MAAM,GACX;IAAE,KAAK,EAAE,MAAM,CAAA;CAAE,CAGnB;AAED,wBAAgB,gBAAgB,CAC9B,KAAK,EAAE,OAAO,EACd,GAAG,EAAE,gBAAgB,GACpB;IACD,KAAK,EAAE,MAAM,CAAA;IACb,IAAI,CAAC,EAAE,aAAa,CAAA;IACpB,OAAO,CAAC,EAAE,iBAAiB,CAAA;CAC5B,CA6CA"}
|
|
@@ -1,15 +1,29 @@
|
|
|
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
|
+
/** The most a request body may be, unless the route reading it allows more. */
|
|
11
|
+
export declare const DEFAULT_REQUEST_BODY_LIMIT_BYTES: number;
|
|
9
12
|
export declare class RequestBodyTooLargeError extends Error {
|
|
10
13
|
readonly limitBytes: number;
|
|
11
14
|
readonly name = "RequestBodyTooLargeError";
|
|
12
15
|
constructor(limitBytes: number, message?: string);
|
|
13
16
|
}
|
|
14
|
-
|
|
17
|
+
/**
|
|
18
|
+
* Returns `request` with its body capped at `DEFAULT_REQUEST_BODY_LIMIT_BYTES`. Reading past the
|
|
19
|
+
* cap fails with `RequestBodyTooLargeError`, which Elysia surfaces as a parse error.
|
|
20
|
+
*/
|
|
21
|
+
export declare function limitRequestBody(request: Request): Request;
|
|
22
|
+
/**
|
|
23
|
+
* Reads a request body fully into memory, failing once it passes `limitBytes`. That limit
|
|
24
|
+
* replaces the server's default cap for this request, so a route reading more than the default
|
|
25
|
+
* must authenticate the caller first. The `content-length` header, when present, only provides an
|
|
26
|
+
* early fast-path.
|
|
27
|
+
*/
|
|
28
|
+
export declare function readRequestBodyWithLimit(request: Request, limitBytes: number, tooLargeMessage?: string): Promise<Uint8Array<ArrayBuffer>>;
|
|
15
29
|
//# sourceMappingURL=request-body.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"request-body.d.ts","sourceRoot":"","sources":["../../src/utils/request-body.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"request-body.d.ts","sourceRoot":"","sources":["../../src/utils/request-body.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG;AAEH,+EAA+E;AAC/E,eAAO,MAAM,gCAAgC,QAAc,CAAA;AAE3D,qBAAa,wBAAyB,SAAQ,KAAK;IAI/C,QAAQ,CAAC,UAAU,EAAE,MAAM;IAH7B,QAAQ,CAAC,IAAI,8BAA6B;gBAG/B,UAAU,EAAE,MAAM,EAC3B,OAAO,SAAuD;CAIjE;AAID;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAwB1D;AAED;;;;;GAKG;AACH,wBAAsB,wBAAwB,CAC5C,OAAO,EAAE,OAAO,EAChB,UAAU,EAAE,MAAM,EAClB,eAAe,CAAC,EAAE,MAAM,GACvB,OAAO,CAAC,UAAU,CAAC,WAAW,CAAC,CAAC,CA4ClC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.20",
|
|
4
4
|
"description": "HTTP and WebSocket API server for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -38,14 +38,14 @@
|
|
|
38
38
|
"zod-to-json-schema": "^3.24.0"
|
|
39
39
|
},
|
|
40
40
|
"peerDependencies": {
|
|
41
|
-
"@sixb/core": "0.1.
|
|
41
|
+
"@sixb/core": "0.1.20"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@sixb/auth-magic-link": "0.1.
|
|
45
|
-
"@sixb/auth-oidc": "0.1.
|
|
46
|
-
"@sixb/cli-core": "0.1.
|
|
47
|
-
"@sixb/core": "0.1.
|
|
48
|
-
"@sixb/sqlite": "0.1.
|
|
44
|
+
"@sixb/auth-magic-link": "0.1.6",
|
|
45
|
+
"@sixb/auth-oidc": "0.1.6",
|
|
46
|
+
"@sixb/cli-core": "0.1.8",
|
|
47
|
+
"@sixb/core": "0.1.20",
|
|
48
|
+
"@sixb/sqlite": "0.1.20",
|
|
49
49
|
"@types/bun": "latest",
|
|
50
50
|
"typescript": "^5.7.0"
|
|
51
51
|
},
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import type { ActionRunRecord } from "@sixb/core/storage"
|
|
2
|
+
import { ActionRunDetailSchema, ActionRunSummarySchema } from "../schemas/actions"
|
|
3
|
+
import { toIsoString } from "../utils/http"
|
|
4
|
+
|
|
5
|
+
/** The run summary run listings answer with. */
|
|
6
|
+
export function serializeActionRunSummary(
|
|
7
|
+
run: ActionRunRecord
|
|
8
|
+
): ReturnType<typeof ActionRunSummarySchema.parse> {
|
|
9
|
+
return ActionRunSummarySchema.parse({
|
|
10
|
+
id: run.id,
|
|
11
|
+
projectId: run.projectId,
|
|
12
|
+
actionId: run.actionId,
|
|
13
|
+
subject: run.subject,
|
|
14
|
+
status: run.status,
|
|
15
|
+
phase: run.phase,
|
|
16
|
+
startedAt: toIsoString(run.startedAt),
|
|
17
|
+
finishedAt: toIsoString(run.finishedAt),
|
|
18
|
+
error: run.error,
|
|
19
|
+
})
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** The run detail every route that returns one run answers with. */
|
|
23
|
+
export function serializeActionRunDetail(
|
|
24
|
+
run: ActionRunRecord
|
|
25
|
+
): ReturnType<typeof ActionRunDetailSchema.parse> {
|
|
26
|
+
return ActionRunDetailSchema.parse({
|
|
27
|
+
...serializeActionRunSummary(run),
|
|
28
|
+
params: run.params,
|
|
29
|
+
writeback: run.writeback
|
|
30
|
+
? run.writeback.status === "succeeded"
|
|
31
|
+
? {
|
|
32
|
+
status: "succeeded",
|
|
33
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
34
|
+
result: run.writeback.result,
|
|
35
|
+
}
|
|
36
|
+
: {
|
|
37
|
+
status: "failed",
|
|
38
|
+
completedAt: toIsoString(run.writeback.completedAt),
|
|
39
|
+
error: run.writeback.error,
|
|
40
|
+
}
|
|
41
|
+
: undefined,
|
|
42
|
+
effects: run.effects
|
|
43
|
+
? run.effects.status === "succeeded"
|
|
44
|
+
? {
|
|
45
|
+
status: "succeeded",
|
|
46
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
47
|
+
}
|
|
48
|
+
: {
|
|
49
|
+
status: "failed",
|
|
50
|
+
completedAt: toIsoString(run.effects.completedAt),
|
|
51
|
+
error: run.effects.error,
|
|
52
|
+
}
|
|
53
|
+
: undefined,
|
|
54
|
+
})
|
|
55
|
+
}
|
|
@@ -1,57 +1,20 @@
|
|
|
1
|
-
import {
|
|
2
|
-
type AuthSessionAudience,
|
|
3
|
-
applications,
|
|
4
|
-
DEFAULT_AUTH_SESSION_AUDIENCE,
|
|
5
|
-
isValidAuthSessionAudience,
|
|
6
|
-
resolveAuthSessionAudience,
|
|
7
|
-
} from "@sixb/core"
|
|
8
|
-
import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/core/internal/http"
|
|
9
|
-
|
|
10
|
-
const fileNavigationRoutes = SIXB_API_ROUTES.filter(
|
|
11
|
-
(route) =>
|
|
12
|
-
(route.method === "GET" || route.method === "HEAD") && route.path.endsWith("/files/content")
|
|
13
|
-
)
|
|
14
|
-
|
|
15
|
-
export interface SixbBrowserOrigin {
|
|
16
|
-
readonly origin: string
|
|
17
|
-
readonly audience: AuthSessionAudience
|
|
18
|
-
}
|
|
19
|
-
|
|
20
1
|
export interface SixbApiBrowserPolicy {
|
|
21
2
|
readonly publicOrigin?: string
|
|
22
|
-
|
|
23
|
-
readonly
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
export interface ResolvedSixbBrowserOrigin {
|
|
27
|
-
readonly origin: string
|
|
28
|
-
readonly audience: AuthSessionAudience
|
|
3
|
+
/** The browser origins that may call the API with a session: the project's app. */
|
|
4
|
+
readonly allowedOrigins: readonly string[]
|
|
29
5
|
}
|
|
30
6
|
|
|
31
7
|
export interface ResolvedSixbApiBrowserPolicy {
|
|
32
8
|
readonly publicOrigin?: string
|
|
33
|
-
readonly
|
|
34
|
-
readonly allowedOrigins: readonly ResolvedSixbBrowserOrigin[]
|
|
9
|
+
readonly allowedOrigins: readonly string[]
|
|
35
10
|
}
|
|
36
11
|
|
|
37
12
|
export interface RequestAuthContext {
|
|
38
|
-
readonly audience: AuthSessionAudience
|
|
39
13
|
readonly browserOrigin?: string
|
|
40
14
|
readonly absoluteReturnTo?: boolean
|
|
41
15
|
}
|
|
42
16
|
|
|
43
|
-
export interface AuthInvitationDestination {
|
|
44
|
-
readonly id: AuthSessionAudience
|
|
45
|
-
readonly label: string
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export interface AuthInvitationDestinationOptions {
|
|
49
|
-
readonly destinations: readonly AuthInvitationDestination[]
|
|
50
|
-
readonly defaultDestinationId?: AuthSessionAudience
|
|
51
|
-
}
|
|
52
|
-
|
|
53
17
|
export interface AuthInvitationRedirectInput {
|
|
54
|
-
readonly destinationId?: AuthSessionAudience
|
|
55
18
|
readonly returnTo?: string
|
|
56
19
|
}
|
|
57
20
|
|
|
@@ -60,13 +23,11 @@ export type AuthInvitationRedirectContext = AuthRedirectContext
|
|
|
60
23
|
export type ResolveRequestAuthContext = (request: Request) => RequestAuthContext
|
|
61
24
|
|
|
62
25
|
export interface AuthRedirectInput {
|
|
63
|
-
readonly audience?: string | null
|
|
64
26
|
readonly returnTo?: string | null
|
|
65
27
|
readonly fallbackReturnToOrigin?: string
|
|
66
28
|
}
|
|
67
29
|
|
|
68
30
|
export interface AuthRedirectContext {
|
|
69
|
-
readonly audience: AuthSessionAudience
|
|
70
31
|
readonly returnTo: string
|
|
71
32
|
readonly requestOrigin: string
|
|
72
33
|
}
|
|
@@ -83,46 +44,18 @@ export class BrowserOriginError extends Error {
|
|
|
83
44
|
export function resolveApiBrowserPolicy(
|
|
84
45
|
policy: SixbApiBrowserPolicy
|
|
85
46
|
): ResolvedSixbApiBrowserPolicy {
|
|
86
|
-
const
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
for (const entry of policy.allowedOrigins) {
|
|
93
|
-
const origin = normalizeHttpOrigin(entry.origin, "browser origin")
|
|
94
|
-
const audience = resolveAuthSessionAudience(entry.audience)
|
|
95
|
-
const existingAudienceOrigin = audienceOrigins.get(audience)
|
|
96
|
-
if (existingAudienceOrigin && existingAudienceOrigin !== origin) {
|
|
97
|
-
throw new Error(
|
|
98
|
-
`[SixbServer] Auth audience '${audience}' is mapped to multiple browser origins.`
|
|
99
|
-
)
|
|
100
|
-
}
|
|
101
|
-
audienceOrigins.set(audience, origin)
|
|
102
|
-
|
|
103
|
-
const existing = origins.get(origin)
|
|
104
|
-
if (existing) {
|
|
105
|
-
if (existing.audience !== audience) {
|
|
106
|
-
throw new Error(
|
|
107
|
-
`[SixbServer] Browser origin '${origin}' is mapped to multiple auth audiences.`
|
|
108
|
-
)
|
|
109
|
-
}
|
|
110
|
-
continue
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
origins.set(origin, { origin, audience })
|
|
114
|
-
}
|
|
115
|
-
|
|
116
|
-
if (origins.size === 0) {
|
|
117
|
-
throw new Error("[SixbServer] API browser policy requires at least one allowed origin.")
|
|
118
|
-
}
|
|
47
|
+
const allowedOrigins = [
|
|
48
|
+
...new Set(
|
|
49
|
+
policy.allowedOrigins.map((origin) => normalizeHttpOrigin(origin, "browser origin"))
|
|
50
|
+
),
|
|
51
|
+
]
|
|
119
52
|
|
|
53
|
+
// Empty is an API serving no browser app: only its own origin is admitted.
|
|
120
54
|
return {
|
|
121
55
|
publicOrigin: policy.publicOrigin
|
|
122
56
|
? normalizeHttpOrigin(policy.publicOrigin, "API public origin")
|
|
123
57
|
: undefined,
|
|
124
|
-
|
|
125
|
-
allowedOrigins: [...origins.values()],
|
|
58
|
+
allowedOrigins,
|
|
126
59
|
}
|
|
127
60
|
}
|
|
128
61
|
|
|
@@ -143,82 +76,23 @@ export function resolveApiBrowserAuthContext(
|
|
|
143
76
|
request: Request
|
|
144
77
|
): RequestAuthContext {
|
|
145
78
|
const origin = normalizeRequestOrigin(request)
|
|
146
|
-
const fileAudience = resolveFileNavigationAudience(policy, request)
|
|
147
79
|
if (!origin) {
|
|
148
|
-
return {
|
|
80
|
+
return { absoluteReturnTo: true }
|
|
149
81
|
}
|
|
150
82
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
assertFileAudienceMatchesOrigin(fileAudience, allowed.audience)
|
|
154
|
-
return {
|
|
155
|
-
audience: allowed.audience,
|
|
156
|
-
browserOrigin: allowed.origin,
|
|
157
|
-
absoluteReturnTo: true,
|
|
158
|
-
}
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
if (isSameOriginApiRequest(policy, origin, request)) {
|
|
162
|
-
assertFileAudienceMatchesOrigin(fileAudience, policy.apiOriginAudience)
|
|
163
|
-
return { audience: policy.apiOriginAudience, browserOrigin: origin, absoluteReturnTo: true }
|
|
83
|
+
if (isAllowedOrigin(policy, request, origin)) {
|
|
84
|
+
return { browserOrigin: origin, absoluteReturnTo: true }
|
|
164
85
|
}
|
|
165
86
|
|
|
166
87
|
throw new BrowserOriginError(`[SixbServer] Browser origin '${origin}' is not allowed.`)
|
|
167
88
|
}
|
|
168
89
|
|
|
169
|
-
// A URL audience selects credentials, never grants authority. Only file GET/HEAD
|
|
170
|
-
// routes accept it; Origin remains authoritative whenever the browser sends one.
|
|
171
|
-
function resolveFileNavigationAudience(
|
|
172
|
-
policy: ResolvedSixbApiBrowserPolicy,
|
|
173
|
-
request: Request
|
|
174
|
-
): AuthSessionAudience | undefined {
|
|
175
|
-
const url = new URL(request.url)
|
|
176
|
-
if (
|
|
177
|
-
!fileNavigationRoutes.some(
|
|
178
|
-
(route) =>
|
|
179
|
-
route.method === request.method &&
|
|
180
|
-
matchesPathPattern(normalizeRoutePath(url.pathname), route.path)
|
|
181
|
-
)
|
|
182
|
-
) {
|
|
183
|
-
return undefined
|
|
184
|
-
}
|
|
185
|
-
const values = url.searchParams.getAll("audience")
|
|
186
|
-
if (values.length === 0) return undefined
|
|
187
|
-
const audience = values[0]
|
|
188
|
-
if (
|
|
189
|
-
values.length !== 1 ||
|
|
190
|
-
!audience ||
|
|
191
|
-
!isValidAuthSessionAudience(audience) ||
|
|
192
|
-
(audience !== policy.apiOriginAudience &&
|
|
193
|
-
!policy.allowedOrigins.some((entry) => entry.audience === audience))
|
|
194
|
-
) {
|
|
195
|
-
throw new BrowserOriginError("[SixbServer] File navigation audience is not allowed.")
|
|
196
|
-
}
|
|
197
|
-
return audience
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
function assertFileAudienceMatchesOrigin(
|
|
201
|
-
audience: AuthSessionAudience | undefined,
|
|
202
|
-
originAudience: AuthSessionAudience
|
|
203
|
-
): void {
|
|
204
|
-
if (audience !== undefined && audience !== originAudience) {
|
|
205
|
-
throw new BrowserOriginError("[SixbServer] File navigation audience conflicts with Origin.")
|
|
206
|
-
}
|
|
207
|
-
}
|
|
208
|
-
|
|
209
90
|
export function isAllowedApiBrowserOrigin(
|
|
210
91
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
211
92
|
request: Request
|
|
212
93
|
): boolean {
|
|
213
94
|
const origin = normalizeRequestOrigin(request)
|
|
214
|
-
|
|
215
|
-
return false
|
|
216
|
-
}
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
findAllowedBrowserOrigin(policy, origin) !== null ||
|
|
220
|
-
isSameOriginApiRequest(policy, origin, request)
|
|
221
|
-
)
|
|
95
|
+
return origin !== null && isAllowedOrigin(policy, request, origin)
|
|
222
96
|
}
|
|
223
97
|
|
|
224
98
|
export function resolveApiBrowserAuthRedirectContext(
|
|
@@ -226,58 +100,21 @@ export function resolveApiBrowserAuthRedirectContext(
|
|
|
226
100
|
request: Request,
|
|
227
101
|
input: AuthRedirectInput
|
|
228
102
|
): AuthRedirectContext {
|
|
229
|
-
const audience = resolveRequiredAuthAudience(input.audience)
|
|
230
|
-
const returnTo = resolveApiBrowserReturnTo(policy, request, input, audience)
|
|
231
|
-
|
|
232
103
|
return {
|
|
233
|
-
|
|
234
|
-
returnTo,
|
|
104
|
+
returnTo: resolveApiBrowserReturnTo(policy, request, input),
|
|
235
105
|
requestOrigin: resolveApiBrowserPublicOrigin(policy, request),
|
|
236
106
|
}
|
|
237
107
|
}
|
|
238
108
|
|
|
239
|
-
|
|
240
|
-
policy: ResolvedSixbApiBrowserPolicy
|
|
241
|
-
): AuthInvitationDestinationOptions {
|
|
242
|
-
const destinations = policy.allowedOrigins.map((entry) => ({
|
|
243
|
-
id: entry.audience,
|
|
244
|
-
label: applications[entry.audience].label,
|
|
245
|
-
}))
|
|
246
|
-
const defaultDestinationId = destinations.some((destination) => destination.id === "app")
|
|
247
|
-
? applications.app.id
|
|
248
|
-
: destinations.some((destination) => destination.id === "atlas")
|
|
249
|
-
? applications.atlas.id
|
|
250
|
-
: undefined
|
|
251
|
-
|
|
252
|
-
return {
|
|
253
|
-
destinations,
|
|
254
|
-
...(defaultDestinationId ? { defaultDestinationId } : {}),
|
|
255
|
-
}
|
|
256
|
-
}
|
|
257
|
-
|
|
109
|
+
/** An invitation lands where the inviter works, or on the app when the request has no Origin. */
|
|
258
110
|
export function resolveApiBrowserInvitationRedirectContext(
|
|
259
111
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
260
112
|
request: Request,
|
|
261
113
|
input: AuthInvitationRedirectInput
|
|
262
114
|
): AuthInvitationRedirectContext {
|
|
263
115
|
const authContext = resolveApiBrowserAuthContext(policy, request)
|
|
264
|
-
if (!input.destinationId) {
|
|
265
|
-
return resolveApiBrowserAuthRedirectContext(policy, request, {
|
|
266
|
-
audience: authContext.audience,
|
|
267
|
-
fallbackReturnToOrigin: authContext.browserOrigin,
|
|
268
|
-
returnTo: input.returnTo,
|
|
269
|
-
})
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
const destination = policy.allowedOrigins.find((entry) => entry.audience === input.destinationId)
|
|
273
|
-
if (!destination) {
|
|
274
|
-
throw new BrowserOriginError("[SixbServer] Invitation destination is not allowed.")
|
|
275
|
-
}
|
|
276
|
-
assertInvitationReturnToOrigin(input.returnTo, destination.origin)
|
|
277
|
-
|
|
278
116
|
return resolveApiBrowserAuthRedirectContext(policy, request, {
|
|
279
|
-
|
|
280
|
-
fallbackReturnToOrigin: destination.origin,
|
|
117
|
+
fallbackReturnToOrigin: authContext.browserOrigin ?? policy.allowedOrigins[0],
|
|
281
118
|
returnTo: input.returnTo,
|
|
282
119
|
})
|
|
283
120
|
}
|
|
@@ -289,51 +126,21 @@ export function resolveApiBrowserPublicOrigin(
|
|
|
289
126
|
return policy.publicOrigin ?? new URL(request.url).origin
|
|
290
127
|
}
|
|
291
128
|
|
|
292
|
-
function
|
|
129
|
+
function isAllowedOrigin(
|
|
293
130
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
131
|
+
request: Request,
|
|
294
132
|
origin: string
|
|
295
|
-
): ResolvedSixbBrowserOrigin | null {
|
|
296
|
-
return policy.allowedOrigins.find((entry) => entry.origin === origin) ?? null
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
function isSameOriginApiRequest(
|
|
300
|
-
policy: ResolvedSixbApiBrowserPolicy,
|
|
301
|
-
origin: string,
|
|
302
|
-
request: Request
|
|
303
133
|
): boolean {
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
function assertInvitationReturnToOrigin(
|
|
309
|
-
returnTo: string | undefined,
|
|
310
|
-
destinationOrigin: string
|
|
311
|
-
): void {
|
|
312
|
-
if (!returnTo?.trim()) return
|
|
313
|
-
|
|
314
|
-
try {
|
|
315
|
-
if (new URL(returnTo).origin === destinationOrigin) return
|
|
316
|
-
} catch {
|
|
317
|
-
// Fall through to the same public validation error as an origin mismatch.
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
throw new BrowserOriginError("[SixbServer] Invitation return target is not allowed.")
|
|
321
|
-
}
|
|
322
|
-
|
|
323
|
-
function resolveRequiredAuthAudience(value: string | null | undefined): AuthSessionAudience {
|
|
324
|
-
const audience = value?.trim()
|
|
325
|
-
if (!audience || !isValidAuthSessionAudience(audience)) {
|
|
326
|
-
throw new BrowserOriginError("[SixbServer] Auth audience is invalid or missing.")
|
|
327
|
-
}
|
|
328
|
-
|
|
329
|
-
return audience
|
|
134
|
+
return (
|
|
135
|
+
policy.allowedOrigins.includes(origin) ||
|
|
136
|
+
origin === resolveApiBrowserPublicOrigin(policy, request)
|
|
137
|
+
)
|
|
330
138
|
}
|
|
331
139
|
|
|
332
140
|
function resolveApiBrowserReturnTo(
|
|
333
141
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
334
142
|
request: Request,
|
|
335
|
-
input: AuthRedirectInput
|
|
336
|
-
audience: AuthSessionAudience
|
|
143
|
+
input: AuthRedirectInput
|
|
337
144
|
): string {
|
|
338
145
|
const rawReturnTo = input.returnTo?.trim()
|
|
339
146
|
const value =
|
|
@@ -354,35 +161,18 @@ function resolveApiBrowserReturnTo(
|
|
|
354
161
|
throw new BrowserOriginError("[SixbServer] Auth return target must be an absolute URL.")
|
|
355
162
|
}
|
|
356
163
|
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
164
|
+
if (
|
|
165
|
+
(url.protocol !== "http:" && url.protocol !== "https:") ||
|
|
166
|
+
url.username ||
|
|
167
|
+
url.password ||
|
|
168
|
+
!isAllowedOrigin(policy, request, url.origin)
|
|
169
|
+
) {
|
|
363
170
|
throw new BrowserOriginError("[SixbServer] Auth return target is not allowed.")
|
|
364
171
|
}
|
|
365
172
|
|
|
366
173
|
return url.toString()
|
|
367
174
|
}
|
|
368
175
|
|
|
369
|
-
function resolveReturnToAudience(
|
|
370
|
-
policy: ResolvedSixbApiBrowserPolicy,
|
|
371
|
-
request: Request,
|
|
372
|
-
origin: string
|
|
373
|
-
): AuthSessionAudience | null {
|
|
374
|
-
const allowed = findAllowedBrowserOrigin(policy, origin)
|
|
375
|
-
if (allowed) {
|
|
376
|
-
return allowed.audience
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
if (origin === resolveApiBrowserPublicOrigin(policy, request)) {
|
|
380
|
-
return policy.apiOriginAudience
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
return null
|
|
384
|
-
}
|
|
385
|
-
|
|
386
176
|
function normalizeRequestOrigin(request: Request): string | null {
|
|
387
177
|
const origin = request.headers.get("origin")
|
|
388
178
|
if (!origin) {
|
package/src/auth/experience.ts
CHANGED
|
@@ -1,12 +1,10 @@
|
|
|
1
1
|
import { resolve } from "node:path"
|
|
2
|
-
import type { AuthSessionAudience } from "@sixb/core"
|
|
3
2
|
|
|
4
3
|
const AUTH_BOOTSTRAP_PLACEHOLDER = "__SIXB_AUTH_BOOTSTRAP__"
|
|
5
4
|
const AUTH_ASSET_PREFIX = "/auth/assets/"
|
|
6
5
|
|
|
7
6
|
export interface SixbAuthExperienceOptions {
|
|
8
7
|
readonly outdir: string
|
|
9
|
-
readonly audience?: AuthSessionAudience
|
|
10
8
|
}
|
|
11
9
|
|
|
12
10
|
/** The configured experience with the project's language, which its pages declare. */
|
|
@@ -30,7 +28,6 @@ export interface AuthExperienceSubmission {
|
|
|
30
28
|
export async function customAuthExperienceResponse(
|
|
31
29
|
options: ProjectAuthExperience | undefined,
|
|
32
30
|
input: {
|
|
33
|
-
readonly audience: AuthSessionAudience
|
|
34
31
|
readonly state: AuthExperiencePageState
|
|
35
32
|
readonly signInUrl: string
|
|
36
33
|
readonly submission?: AuthExperienceSubmission
|
|
@@ -39,7 +36,7 @@ export async function customAuthExperienceResponse(
|
|
|
39
36
|
readonly formActionOrigins?: readonly string[]
|
|
40
37
|
}
|
|
41
38
|
): Promise<Response | null> {
|
|
42
|
-
if (!options
|
|
39
|
+
if (!options) {
|
|
43
40
|
return null
|
|
44
41
|
}
|
|
45
42
|
|
package/src/auth/guard.ts
CHANGED
|
@@ -4,7 +4,6 @@ import {
|
|
|
4
4
|
verifyDoubleSubmitCsrf,
|
|
5
5
|
} from "@sixb/core/internal/auth"
|
|
6
6
|
import { credentialTransport, isAccessTokenRoute, shouldVerifyCsrf } from "./access-token-boundary"
|
|
7
|
-
import { sessionCanAccessApplication } from "./application-access"
|
|
8
7
|
import { BrowserOriginError, type ResolveRequestAuthContext } from "./browser-origin"
|
|
9
8
|
import { classifyRoute } from "./public-routes"
|
|
10
9
|
import {
|
|
@@ -64,17 +63,13 @@ export class ServerAuthGuard {
|
|
|
64
63
|
return { kind: "deny", response: authContext }
|
|
65
64
|
}
|
|
66
65
|
|
|
67
|
-
let session = await this.host.auth.getSession(request, {
|
|
68
|
-
audience: authContext.audience,
|
|
69
|
-
credentialSource: "any",
|
|
70
|
-
})
|
|
66
|
+
let session = await this.host.auth.getSession(request, { credentialSource: "any" })
|
|
71
67
|
if (!session.authenticated) {
|
|
72
68
|
if (route.kind === "html") {
|
|
73
69
|
return {
|
|
74
70
|
kind: "deny",
|
|
75
71
|
response: htmlAuthRedirectResponse(request, {
|
|
76
72
|
absoluteReturnTo: authContext.absoluteReturnTo ?? false,
|
|
77
|
-
audience: authContext.audience,
|
|
78
73
|
}),
|
|
79
74
|
}
|
|
80
75
|
}
|
|
@@ -86,20 +81,6 @@ export class ServerAuthGuard {
|
|
|
86
81
|
return { kind: "deny", response: jsonAuthRequiredResponse() }
|
|
87
82
|
}
|
|
88
83
|
|
|
89
|
-
// Application access gates the web app a browser session belongs to. A native client's session
|
|
90
|
-
// and an access token belong to no web app: grants alone decide what they may do. Account pages
|
|
91
|
-
// serve every signed-in user.
|
|
92
|
-
const deniedApplication = (caller: AuthenticatedRequestAuthSession) =>
|
|
93
|
-
!route.account &&
|
|
94
|
-
credentialTransport(caller) === "cookie" &&
|
|
95
|
-
!sessionCanAccessApplication(this.host, caller, authContext.audience)
|
|
96
|
-
if (deniedApplication(session)) {
|
|
97
|
-
return {
|
|
98
|
-
kind: "deny",
|
|
99
|
-
response: jsonForbiddenResponse("Application access is not allowed"),
|
|
100
|
-
}
|
|
101
|
-
}
|
|
102
|
-
|
|
103
84
|
if (session.credentialSource === "accessToken" && !isAccessTokenRoute(request)) {
|
|
104
85
|
return {
|
|
105
86
|
kind: "deny",
|
|
@@ -123,7 +104,6 @@ export class ServerAuthGuard {
|
|
|
123
104
|
hasForegroundSessionActivity(request)
|
|
124
105
|
) {
|
|
125
106
|
const activeSession = await this.host.auth.getSession(request, {
|
|
126
|
-
audience: authContext.audience,
|
|
127
107
|
credentialSource: "session",
|
|
128
108
|
sessionActivity: "foreground",
|
|
129
109
|
})
|
|
@@ -133,32 +113,24 @@ export class ServerAuthGuard {
|
|
|
133
113
|
kind: "deny",
|
|
134
114
|
response: htmlAuthRedirectResponse(request, {
|
|
135
115
|
absoluteReturnTo: authContext.absoluteReturnTo ?? false,
|
|
136
|
-
audience: authContext.audience,
|
|
137
116
|
}),
|
|
138
117
|
}
|
|
139
118
|
}
|
|
140
119
|
return { kind: "deny", response: jsonAuthRequiredResponse() }
|
|
141
120
|
}
|
|
142
|
-
if (deniedApplication(activeSession)) {
|
|
143
|
-
return {
|
|
144
|
-
kind: "deny",
|
|
145
|
-
response: jsonForbiddenResponse("Application access is not allowed"),
|
|
146
|
-
}
|
|
147
|
-
}
|
|
148
121
|
session = activeSession
|
|
149
122
|
}
|
|
150
123
|
|
|
151
124
|
return { kind: "allow", session }
|
|
152
125
|
}
|
|
153
126
|
|
|
154
|
-
getCsrfCookieName(
|
|
155
|
-
|
|
156
|
-
return this.host.auth.getCookieOptions({ audience }).csrfCookieName
|
|
127
|
+
getCsrfCookieName(): string {
|
|
128
|
+
return this.host.auth.getCookieOptions().csrfCookieName
|
|
157
129
|
}
|
|
158
130
|
|
|
159
131
|
verifyCsrf(request: Request, _session: AuthenticatedRequestAuthSession): boolean {
|
|
160
132
|
return verifyDoubleSubmitCsrf(request, {
|
|
161
|
-
cookieName: this.getCsrfCookieName(
|
|
133
|
+
cookieName: this.getCsrfCookieName(),
|
|
162
134
|
})
|
|
163
135
|
}
|
|
164
136
|
|