@sixb/server 0.1.6 → 0.1.8
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/dist/auth/access-token-boundary.d.ts +3 -0
- package/dist/auth/access-token-boundary.d.ts.map +1 -1
- package/dist/auth/public-routes.d.ts.map +1 -1
- package/dist/auth/scope.d.ts +6 -2
- package/dist/auth/scope.d.ts.map +1 -1
- package/dist/auth/shared-access.d.ts +66 -0
- package/dist/auth/shared-access.d.ts.map +1 -0
- package/dist/files/content.d.ts +8 -0
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3402 -1693
- package/dist/index.js.map +35 -28
- package/dist/models/display.d.ts +22 -0
- package/dist/models/display.d.ts.map +1 -0
- package/dist/openapi/security.d.ts +15 -1
- package/dist/openapi/security.d.ts.map +1 -1
- package/dist/openapi/tags.d.ts +6 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +2 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +2 -0
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/actions.d.ts +1 -0
- 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 +100 -90
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/ai-accounting.d.ts.map +1 -1
- package/dist/routes/auth.d.ts +143 -24
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +8 -8
- package/dist/routes/connector-connections.d.ts +4 -4
- package/dist/routes/datasets.d.ts +5 -3
- package/dist/routes/datasets.d.ts.map +1 -1
- package/dist/routes/events.d.ts +3 -3
- package/dist/routes/files.d.ts +1 -0
- package/dist/routes/files.d.ts.map +1 -1
- package/dist/routes/logs.d.ts +1 -1
- package/dist/routes/models.d.ts +18 -1
- package/dist/routes/models.d.ts.map +1 -1
- package/dist/routes/objects.d.ts +3 -1
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +6 -1
- package/dist/routes/pipelines.d.ts.map +1 -1
- package/dist/routes/rules.d.ts +1 -1
- package/dist/routes/share-grants.d.ts +264 -0
- package/dist/routes/share-grants.d.ts.map +1 -0
- package/dist/routes/shared-access.d.ts +155 -0
- package/dist/routes/shared-access.d.ts.map +1 -0
- package/dist/routes/syncs.d.ts +3 -0
- package/dist/routes/syncs.d.ts.map +1 -1
- package/dist/routes/workflows.d.ts +58 -55
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/logs.d.ts +4 -4
- package/dist/schemas/agents.d.ts +385 -230
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +1847 -295
- package/dist/schemas/ai-accounting.d.ts.map +1 -1
- package/dist/schemas/ai-limits.d.ts +2210 -0
- package/dist/schemas/ai-limits.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +195 -112
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/datasets.d.ts +28 -22
- package/dist/schemas/datasets.d.ts.map +1 -1
- package/dist/schemas/events.d.ts +6 -6
- package/dist/schemas/files.d.ts +3 -0
- package/dist/schemas/files.d.ts.map +1 -1
- package/dist/schemas/logs.d.ts +6 -6
- package/dist/schemas/models.d.ts +214 -14
- package/dist/schemas/models.d.ts.map +1 -1
- package/dist/schemas/objects.d.ts +4 -4
- package/dist/schemas/pipelines.d.ts +42 -6
- package/dist/schemas/pipelines.d.ts.map +1 -1
- package/dist/schemas/rules.d.ts +6 -6
- package/dist/schemas/share-grants.d.ts +518 -0
- package/dist/schemas/share-grants.d.ts.map +1 -0
- package/dist/schemas/shared-access.d.ts +42 -0
- package/dist/schemas/shared-access.d.ts.map +1 -0
- package/dist/schemas/syncs.d.ts +7 -0
- package/dist/schemas/syncs.d.ts.map +1 -1
- package/dist/schemas/workflows.d.ts +200 -210
- package/dist/schemas/workflows.d.ts.map +1 -1
- package/dist/server.d.ts +5 -0
- package/dist/server.d.ts.map +1 -1
- package/dist/utils/http.d.ts +8 -4
- package/dist/utils/http.d.ts.map +1 -1
- package/package.json +4 -4
- package/src/auth/access-token-boundary.ts +17 -2
- package/src/auth/public-routes.ts +23 -0
- package/src/auth/scope.ts +3 -2
- package/src/auth/shared-access.ts +376 -0
- package/src/files/content.ts +39 -6
- package/src/index.ts +1 -0
- package/src/models/display.ts +91 -0
- package/src/openapi/security.ts +20 -1
- package/src/openapi/tags.ts +4 -0
- package/src/registerRoutes.ts +6 -0
- package/src/routes/actions.ts +5 -10
- package/src/routes/agent-api-gateway.ts +137 -38
- package/src/routes/agents.ts +58 -83
- package/src/routes/ai-accounting.ts +414 -23
- package/src/routes/auth.ts +280 -1
- package/src/routes/models.ts +12 -4
- package/src/routes/share-grants.ts +238 -0
- package/src/routes/shared-access.ts +165 -0
- package/src/routes/workflows.ts +3 -5
- package/src/routes/ws/agents.ts +17 -6
- package/src/schemas/agents.ts +38 -50
- package/src/schemas/ai-accounting.ts +88 -19
- package/src/schemas/ai-limits.ts +116 -0
- package/src/schemas/auth.ts +32 -0
- package/src/schemas/datasets.ts +2 -1
- package/src/schemas/files.ts +1 -0
- package/src/schemas/models.ts +33 -5
- package/src/schemas/share-grants.ts +109 -0
- package/src/schemas/shared-access.ts +31 -0
- package/src/schemas/workflows.ts +0 -2
- package/src/server.ts +91 -1
- package/src/utils/http.ts +33 -2
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"workflows.d.ts","sourceRoot":"","sources":["../../src/schemas/workflows.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,WAAW,EAGjB,MAAM,oBAAoB,CAAA;AAC3B,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAA;AAMvB,eAAO,MAAM,wBAAwB,+GAA4B,CAAA;AAMjE,eAAO,MAAM,oBAAoB;;;;;;EAE/B,CAAA;AAEF,eA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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAEnD,CAAA;AAEF,eAAO,MAAM,gCAAgC;;;;;;;;;;;;;;;EAK3C,CAAA"}
|
package/dist/server.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { SixbHostView } from "@sixb/core";
|
|
|
2
2
|
import { Elysia } from "elysia";
|
|
3
3
|
import { type AuthInvitationDestinationOptions, 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
|
+
import { type SixbSharedAccessOptions } from "./auth/shared-access";
|
|
5
6
|
export interface SixbServerOptions {
|
|
6
7
|
host: SixbHostView;
|
|
7
8
|
port?: number;
|
|
@@ -10,6 +11,8 @@ export interface SixbServerOptions {
|
|
|
10
11
|
browser: SixbApiBrowserPolicy;
|
|
11
12
|
/** Optional custom-app auth bundle mounted under the API's `/auth` routes. */
|
|
12
13
|
authExperience?: SixbAuthExperienceOptions;
|
|
14
|
+
/** Optional server limits for short-lived shared-access sessions. */
|
|
15
|
+
sharedAccess?: SixbSharedAccessOptions;
|
|
13
16
|
}
|
|
14
17
|
export declare function createSixbServer(options: SixbServerOptions): SixbServer;
|
|
15
18
|
export declare class SixbServer {
|
|
@@ -21,6 +24,7 @@ export declare class SixbServer {
|
|
|
21
24
|
private readonly authContextResolver;
|
|
22
25
|
private readonly authRedirectContextResolver;
|
|
23
26
|
private readonly authExperience?;
|
|
27
|
+
private readonly sharedAccessOptions;
|
|
24
28
|
private app;
|
|
25
29
|
private bunServer;
|
|
26
30
|
private maintenance;
|
|
@@ -34,6 +38,7 @@ export declare class SixbServer {
|
|
|
34
38
|
resolveInvitationRedirectContext(request: Request, input: AuthInvitationRedirectInput): AuthInvitationRedirectContext;
|
|
35
39
|
getApiBrowserPolicy(): ResolvedSixbApiBrowserPolicy;
|
|
36
40
|
getAuthExperience(): SixbAuthExperienceOptions | undefined;
|
|
41
|
+
getSharedAccessOptions(): SixbSharedAccessOptions;
|
|
37
42
|
start(): Promise<void>;
|
|
38
43
|
stop(): Promise<void>;
|
|
39
44
|
}
|
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,MAAM,YAAY,CAAA;AAGzE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAMhC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAKjC,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;
|
|
1
|
+
{"version":3,"file":"server.d.ts","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAA6B,YAAY,EAAE,MAAM,YAAY,CAAA;AAGzE,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAA;AAG/B,OAAO,EACL,KAAK,gCAAgC,EACrC,KAAK,6BAA6B,EAClC,KAAK,2BAA2B,EAMhC,KAAK,kBAAkB,EACvB,KAAK,0BAA0B,EAC/B,KAAK,4BAA4B,EAKjC,KAAK,oBAAoB,EAC1B,MAAM,uBAAuB,CAAA;AAE9B,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,mBAAmB,CAAA;AAKlE,OAAO,EAGL,KAAK,uBAAuB,EAC7B,MAAM,sBAAsB,CAAA;AAiB7B,MAAM,WAAW,iBAAiB;IAChC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AG,MAAM;IAIlD,+BAA+B,CAAC,QAAQ,EAAE,OAAO,GAAG,gCAAgC;IAIpF,gCAAgC,CAC9B,OAAO,EAAE,OAAO,EAChB,KAAK,EAAE,2BAA2B,GACjC,6BAA6B;IAIhC,mBAAmB,IAAI,4BAA4B;IAInD,iBAAiB,IAAI,yBAAyB,GAAG,SAAS;IAI1D,sBAAsB,IAAI,uBAAuB;IAI3C,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IA8BtB,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;CAe5B;AAED,wBAAgB,aAAa,CAAC,MAAM,EAAE,UAAU;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4O/C;AAiED,MAAM,MAAM,OAAO,GAAG,UAAU,CAAC,OAAO,aAAa,CAAC,CAAA"}
|
package/dist/utils/http.d.ts
CHANGED
|
@@ -1,4 +1,8 @@
|
|
|
1
|
-
import { type SixbErrorCode } from "@sixb/core";
|
|
1
|
+
import { type ReadonlyJsonValue, type SixbErrorCode } from "@sixb/core";
|
|
2
|
+
interface RouteResponseSet {
|
|
3
|
+
status?: number | string;
|
|
4
|
+
headers?: unknown;
|
|
5
|
+
}
|
|
2
6
|
export declare function toIsoString(value: Date): string;
|
|
3
7
|
export declare function parseDate(value: string | undefined): Date | undefined;
|
|
4
8
|
export declare function parseOptionalInt(value: string | undefined): number | undefined;
|
|
@@ -16,10 +20,10 @@ export declare function unconfiguredStorageResponse(set: {
|
|
|
16
20
|
}, role: string): {
|
|
17
21
|
error: string;
|
|
18
22
|
};
|
|
19
|
-
export declare function handleRouteError(error: unknown, set: {
|
|
20
|
-
status?: number | string;
|
|
21
|
-
}): {
|
|
23
|
+
export declare function handleRouteError(error: unknown, set: RouteResponseSet): {
|
|
22
24
|
error: string;
|
|
23
25
|
code?: SixbErrorCode;
|
|
26
|
+
details?: ReadonlyJsonValue;
|
|
24
27
|
};
|
|
28
|
+
export {};
|
|
25
29
|
//# sourceMappingURL=http.d.ts.map
|
package/dist/utils/http.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"http.d.ts","sourceRoot":"","sources":["../../src/utils/http.ts"],"names":[],"mappings":"AAAA,OAAO,EAIL,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;AA6BnB,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"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.8",
|
|
4
4
|
"description": "HTTP and WebSocket API server for Sixb",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"sixb",
|
|
@@ -37,13 +37,13 @@
|
|
|
37
37
|
"zod-to-json-schema": "^3.24.0"
|
|
38
38
|
},
|
|
39
39
|
"peerDependencies": {
|
|
40
|
-
"@sixb/core": "0.1.
|
|
40
|
+
"@sixb/core": "0.1.8"
|
|
41
41
|
},
|
|
42
42
|
"devDependencies": {
|
|
43
43
|
"@sixb/auth-magic-link": "0.1.3",
|
|
44
44
|
"@sixb/auth-oidc": "0.1.2",
|
|
45
|
-
"@sixb/core": "0.1.
|
|
46
|
-
"@sixb/sqlite": "0.1.
|
|
45
|
+
"@sixb/core": "0.1.8",
|
|
46
|
+
"@sixb/sqlite": "0.1.8",
|
|
47
47
|
"@types/bun": "latest",
|
|
48
48
|
"typescript": "^5.7.0"
|
|
49
49
|
},
|
|
@@ -3,6 +3,8 @@ import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/c
|
|
|
3
3
|
import {
|
|
4
4
|
SIXB_BEARER_SECURITY_REQUIREMENT,
|
|
5
5
|
SIXB_CSRF_OR_BEARER_SECURITY_REQUIREMENT,
|
|
6
|
+
SIXB_SHARED_MUTATION_SECURITY_REQUIREMENT,
|
|
7
|
+
SIXB_SHARED_READ_SECURITY_REQUIREMENT,
|
|
6
8
|
} from "../openapi/security"
|
|
7
9
|
import type { RouteAccess } from "./public-routes"
|
|
8
10
|
|
|
@@ -12,6 +14,7 @@ export interface AccessTokenRoute {
|
|
|
12
14
|
readonly operationId: string
|
|
13
15
|
readonly method: string
|
|
14
16
|
readonly path: string
|
|
17
|
+
readonly sharedSession: boolean
|
|
15
18
|
}
|
|
16
19
|
|
|
17
20
|
// The routes that accept bearer access tokens: the `accessToken` projection of the canonical
|
|
@@ -26,7 +29,12 @@ export interface AccessTokenRoute {
|
|
|
26
29
|
// from SIXB_API_ROUTES.
|
|
27
30
|
export const ACCESS_TOKEN_ROUTES: readonly AccessTokenRoute[] = SIXB_API_ROUTES.filter(
|
|
28
31
|
(route) => route.accessToken
|
|
29
|
-
).map((route) => ({
|
|
32
|
+
).map((route) => ({
|
|
33
|
+
operationId: route.operationId,
|
|
34
|
+
method: route.method,
|
|
35
|
+
path: route.path,
|
|
36
|
+
sharedSession: route.sharedSession ?? false,
|
|
37
|
+
}))
|
|
30
38
|
|
|
31
39
|
/**
|
|
32
40
|
* OpenAPI security requirement for a bearer-capable route, derived from the
|
|
@@ -43,9 +51,16 @@ export function bearerSecurityRequirement(operationId: string) {
|
|
|
43
51
|
)
|
|
44
52
|
}
|
|
45
53
|
|
|
46
|
-
|
|
54
|
+
const standard = isCsrfExemptMethod(route.method)
|
|
47
55
|
? SIXB_BEARER_SECURITY_REQUIREMENT
|
|
48
56
|
: SIXB_CSRF_OR_BEARER_SECURITY_REQUIREMENT
|
|
57
|
+
if (!route.sharedSession) return standard
|
|
58
|
+
return [
|
|
59
|
+
...standard,
|
|
60
|
+
isCsrfExemptMethod(route.method)
|
|
61
|
+
? SIXB_SHARED_READ_SECURITY_REQUIREMENT
|
|
62
|
+
: SIXB_SHARED_MUTATION_SECURITY_REQUIREMENT,
|
|
63
|
+
]
|
|
49
64
|
}
|
|
50
65
|
|
|
51
66
|
export function isAccessTokenRoute(request: Request): boolean {
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AGENT_API_GATEWAY_PREFIX } from "@sixb/core/internal/agents"
|
|
2
2
|
import { isCsrfExemptMethod } from "@sixb/core/internal/auth"
|
|
3
|
+
import { isSharedAccessPublicPath } from "./shared-access"
|
|
3
4
|
|
|
4
5
|
const CONNECTOR_OAUTH_CALLBACK_PATH = "/auth/connectors/callback"
|
|
5
6
|
|
|
@@ -26,6 +27,10 @@ export function classifyRoute(request: Request): RouteAccess {
|
|
|
26
27
|
return { kind: "api", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
27
28
|
}
|
|
28
29
|
|
|
30
|
+
if (pathname === "/auth/device") {
|
|
31
|
+
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
32
|
+
}
|
|
33
|
+
|
|
29
34
|
if (pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
30
35
|
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
31
36
|
}
|
|
@@ -43,6 +48,10 @@ export function isPublicRoute(pathname: string, method: string): boolean {
|
|
|
43
48
|
return true
|
|
44
49
|
}
|
|
45
50
|
|
|
51
|
+
if (isSharedAccessPublicPath(pathname, method)) {
|
|
52
|
+
return true
|
|
53
|
+
}
|
|
54
|
+
|
|
46
55
|
if ((pathname === "/favicon.svg" || pathname === "/favicon.ico") && normalizedMethod === "GET") {
|
|
47
56
|
return true
|
|
48
57
|
}
|
|
@@ -72,6 +81,20 @@ export function isPublicRoute(pathname: string, method: string): boolean {
|
|
|
72
81
|
return true
|
|
73
82
|
}
|
|
74
83
|
|
|
84
|
+
if (
|
|
85
|
+
(pathname === "/api/auth/device-authorizations" ||
|
|
86
|
+
pathname === "/api/auth/device-authorizations/token") &&
|
|
87
|
+
normalizedMethod === "POST"
|
|
88
|
+
) {
|
|
89
|
+
return true
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
// Native HTML forms cannot set the CSRF header. The handler authenticates the
|
|
93
|
+
// browser session and verifies the submitted token against the CSRF cookie.
|
|
94
|
+
if (pathname === "/auth/device" && normalizedMethod === "POST") {
|
|
95
|
+
return true
|
|
96
|
+
}
|
|
97
|
+
|
|
75
98
|
if (
|
|
76
99
|
pathname.startsWith("/auth/assets/") &&
|
|
77
100
|
(normalizedMethod === "GET" || normalizedMethod === "HEAD")
|
package/src/auth/scope.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { OntologySource } from "@sixb/core"
|
|
2
2
|
import type { RequestExecutionAuthorization, Sixb } from "@sixb/core/internal/request-execution"
|
|
3
|
-
import type { AgentRunRecord } from "@sixb/core/storage"
|
|
3
|
+
import type { AgentRunRecord, ConversationAgentRunRecord } from "@sixb/core/storage"
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Per-request authorization state attached by the server's auth derive.
|
|
@@ -11,10 +11,11 @@ import type { AgentRunRecord } from "@sixb/core/storage"
|
|
|
11
11
|
export interface RequestAuthState {
|
|
12
12
|
readonly sixb: Sixb<readonly OntologySource[]> | null
|
|
13
13
|
/** Present for requests proxied through the run-scoped agent API gateway. */
|
|
14
|
-
readonly agentRun?:
|
|
14
|
+
readonly agentRun?: ConversationAgentRunRecord
|
|
15
15
|
/** Identifies which kind of active agent execution owns a gateway request. */
|
|
16
16
|
readonly agentExecution?:
|
|
17
17
|
| { readonly kind: "conversation"; readonly runId: string }
|
|
18
|
+
| { readonly kind: "subagent"; readonly runId: string; readonly parentRunId: string }
|
|
18
19
|
| { readonly kind: "workflow"; readonly nodeRunId: string }
|
|
19
20
|
}
|
|
20
21
|
|
|
@@ -0,0 +1,376 @@
|
|
|
1
|
+
import { createHash } from "node:crypto"
|
|
2
|
+
import type { SixbHostView } from "@sixb/core"
|
|
3
|
+
import {
|
|
4
|
+
CSRF_HEADER_NAME,
|
|
5
|
+
generateCsrfToken,
|
|
6
|
+
getCookie,
|
|
7
|
+
isCsrfExemptMethod,
|
|
8
|
+
verifyDoubleSubmitCsrf,
|
|
9
|
+
} from "@sixb/core/internal/auth"
|
|
10
|
+
import { matchesPathPattern, normalizeRoutePath, SIXB_API_ROUTES } from "@sixb/core/internal/http"
|
|
11
|
+
import { type SharedSessionContext, SharedSessionProtocol } from "@sixb/core/internal/shares"
|
|
12
|
+
import { hasForegroundSessionActivity } from "./session-activity"
|
|
13
|
+
|
|
14
|
+
export const SHARED_ACCESS_GRANT_HEADER_NAME = "x-sixb-share-grant"
|
|
15
|
+
|
|
16
|
+
const SHARED_SESSION_COOKIE_PREFIX = "sixb_share_session_"
|
|
17
|
+
const SHARED_CSRF_COOKIE_PREFIX = "sixb_share_csrf_"
|
|
18
|
+
const SHARED_COOKIE_PATH = "/api"
|
|
19
|
+
const STORED_IDENTIFIER_MAX_LENGTH = 128
|
|
20
|
+
|
|
21
|
+
const SHARED_SESSION_ROUTES = SIXB_API_ROUTES.filter((route) => route.sharedSession)
|
|
22
|
+
|
|
23
|
+
export interface SixbSharedAccessOptions {
|
|
24
|
+
/** Sliding inactivity window, always bounded by the grant's absolute expiration. */
|
|
25
|
+
readonly inactivityTtlMs?: number
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export interface SharedAccessCookieHeaders {
|
|
29
|
+
readonly setCookies: readonly string[]
|
|
30
|
+
readonly csrfToken: string
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export interface ResolvedSharedAccess {
|
|
34
|
+
readonly context: SharedSessionContext
|
|
35
|
+
readonly cookies: SharedAccessCookieHeaders
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export type SharedAccessRequestDecision =
|
|
39
|
+
| { readonly kind: "absent" }
|
|
40
|
+
| { readonly kind: "deny"; readonly response: Response }
|
|
41
|
+
| ({ readonly kind: "allow" } & ResolvedSharedAccess)
|
|
42
|
+
|
|
43
|
+
export type SharedAccessSignOutResult =
|
|
44
|
+
| { readonly kind: "invalid"; readonly setCookies: readonly string[] }
|
|
45
|
+
| { readonly kind: "csrf" }
|
|
46
|
+
| { readonly kind: "signedOut"; readonly setCookies: readonly string[] }
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Selects shared authority before ambient browser or bearer authentication.
|
|
50
|
+
*
|
|
51
|
+
* The selector header is deliberately not a credential. It chooses one grant-specific HttpOnly
|
|
52
|
+
* cookie, allowing several shared pages to coexist without ever merging their authority.
|
|
53
|
+
*/
|
|
54
|
+
export class SharedAccessBoundary {
|
|
55
|
+
private readonly host: SixbHostView
|
|
56
|
+
private readonly options: SixbSharedAccessOptions
|
|
57
|
+
private protocol: SharedSessionProtocol | undefined
|
|
58
|
+
|
|
59
|
+
constructor(host: SixbHostView, options: SixbSharedAccessOptions = {}) {
|
|
60
|
+
this.host = host
|
|
61
|
+
this.options = options
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/** Fail closed before route parsing can emit a route-specific validation response. */
|
|
65
|
+
preflightResponse(request: Request): Response | undefined {
|
|
66
|
+
if (isSharedAccessPublicRoute(request)) return
|
|
67
|
+
const selectedGrantId = request.headers.get(SHARED_ACCESS_GRANT_HEADER_NAME)
|
|
68
|
+
if (selectedGrantId === null) return
|
|
69
|
+
if (request.headers.has("authorization") || !isSharedSessionRoute(request)) {
|
|
70
|
+
return sharedAccessForbiddenResponse()
|
|
71
|
+
}
|
|
72
|
+
if (!isStoredIdentifier(selectedGrantId)) return sharedAccessUnauthenticatedResponse()
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
async resolveRequest(request: Request): Promise<SharedAccessRequestDecision> {
|
|
76
|
+
if (isSharedAccessPublicRoute(request)) return { kind: "absent" }
|
|
77
|
+
|
|
78
|
+
const selectedGrantId = request.headers.get(SHARED_ACCESS_GRANT_HEADER_NAME)
|
|
79
|
+
if (selectedGrantId === null) return { kind: "absent" }
|
|
80
|
+
|
|
81
|
+
const preflight = this.preflightResponse(request)
|
|
82
|
+
if (preflight) return { kind: "deny", response: preflight }
|
|
83
|
+
|
|
84
|
+
let resolved: ResolvedSharedAccess | null
|
|
85
|
+
try {
|
|
86
|
+
resolved = await this.resolveSession(request, selectedGrantId)
|
|
87
|
+
} catch {
|
|
88
|
+
return { kind: "deny", response: sharedAccessUnavailableResponse() }
|
|
89
|
+
}
|
|
90
|
+
if (!resolved) {
|
|
91
|
+
return { kind: "deny", response: sharedAccessUnauthenticatedResponse() }
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (
|
|
95
|
+
!isCsrfExemptMethod(request.method) &&
|
|
96
|
+
!verifyDoubleSubmitCsrf(request, {
|
|
97
|
+
cookieName: sharedCookieNames(selectedGrantId).csrf,
|
|
98
|
+
headerName: CSRF_HEADER_NAME,
|
|
99
|
+
})
|
|
100
|
+
) {
|
|
101
|
+
return { kind: "deny", response: sharedAccessForbiddenResponse() }
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return { kind: "allow", ...resolved }
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
async exchange(
|
|
108
|
+
request: Request,
|
|
109
|
+
grantId: string,
|
|
110
|
+
secret: string
|
|
111
|
+
): Promise<ResolvedSharedAccess | null> {
|
|
112
|
+
if (!isStoredIdentifier(grantId)) return null
|
|
113
|
+
const protocol = this.getProtocol()
|
|
114
|
+
|
|
115
|
+
const credential = await protocol.exchange(grantId, secret)
|
|
116
|
+
if (!credential) return null
|
|
117
|
+
|
|
118
|
+
const csrfToken = generateCsrfToken()
|
|
119
|
+
return {
|
|
120
|
+
context: credential.context,
|
|
121
|
+
cookies: this.createCookieHeaders({
|
|
122
|
+
request,
|
|
123
|
+
grantId,
|
|
124
|
+
sessionValue: credential.cookieValue,
|
|
125
|
+
csrfToken,
|
|
126
|
+
expiresAt: credential.context.expiresAt,
|
|
127
|
+
}),
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
async resolveSession(request: Request, grantId: string): Promise<ResolvedSharedAccess | null> {
|
|
132
|
+
if (!isStoredIdentifier(grantId)) return null
|
|
133
|
+
const protocol = this.getProtocol()
|
|
134
|
+
|
|
135
|
+
const names = sharedCookieNames(grantId)
|
|
136
|
+
const sessionValue = getCookie(request, names.session)
|
|
137
|
+
const foreground = hasForegroundSessionActivity(request)
|
|
138
|
+
const context = await protocol.resolve(grantId, sessionValue, {
|
|
139
|
+
activity: foreground ? "foreground" : "background",
|
|
140
|
+
})
|
|
141
|
+
if (!context || !sessionValue) return null
|
|
142
|
+
|
|
143
|
+
const existingCsrfToken = getCookie(request, names.csrf)
|
|
144
|
+
const csrfToken = existingCsrfToken ?? generateCsrfToken()
|
|
145
|
+
return {
|
|
146
|
+
context,
|
|
147
|
+
cookies: foreground
|
|
148
|
+
? this.createCookieHeaders({
|
|
149
|
+
request,
|
|
150
|
+
grantId,
|
|
151
|
+
sessionValue,
|
|
152
|
+
csrfToken,
|
|
153
|
+
expiresAt: context.expiresAt,
|
|
154
|
+
})
|
|
155
|
+
: {
|
|
156
|
+
csrfToken,
|
|
157
|
+
setCookies:
|
|
158
|
+
existingCsrfToken === undefined
|
|
159
|
+
? [
|
|
160
|
+
serializeSharedCookie({
|
|
161
|
+
request,
|
|
162
|
+
name: names.csrf,
|
|
163
|
+
value: csrfToken,
|
|
164
|
+
expiresAt: context.expiresAt,
|
|
165
|
+
maxAge: cookieMaxAge(context.expiresAt),
|
|
166
|
+
}),
|
|
167
|
+
]
|
|
168
|
+
: [],
|
|
169
|
+
},
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
async signOut(request: Request, grantId: string): Promise<SharedAccessSignOutResult> {
|
|
174
|
+
if (!isStoredIdentifier(grantId)) {
|
|
175
|
+
return { kind: "invalid", setCookies: [] }
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
const clearCookies = this.clearCookieHeaders(request, grantId)
|
|
179
|
+
const resolved = await this.resolveSession(request, grantId)
|
|
180
|
+
if (!resolved) return { kind: "invalid", setCookies: clearCookies }
|
|
181
|
+
|
|
182
|
+
if (
|
|
183
|
+
!verifyDoubleSubmitCsrf(request, {
|
|
184
|
+
cookieName: sharedCookieNames(grantId).csrf,
|
|
185
|
+
headerName: CSRF_HEADER_NAME,
|
|
186
|
+
})
|
|
187
|
+
) {
|
|
188
|
+
return { kind: "csrf" }
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
const protocol = this.getProtocol()
|
|
192
|
+
await protocol.revoke(resolved.context)
|
|
193
|
+
return { kind: "signedOut", setCookies: clearCookies }
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
clearCookieHeaders(request: Request, grantId: string): readonly string[] {
|
|
197
|
+
if (!isStoredIdentifier(grantId)) return []
|
|
198
|
+
const names = sharedCookieNames(grantId)
|
|
199
|
+
return [
|
|
200
|
+
serializeSharedCookie({
|
|
201
|
+
request,
|
|
202
|
+
name: names.session,
|
|
203
|
+
value: "",
|
|
204
|
+
expiresAt: new Date(0),
|
|
205
|
+
maxAge: 0,
|
|
206
|
+
httpOnly: true,
|
|
207
|
+
}),
|
|
208
|
+
serializeSharedCookie({
|
|
209
|
+
request,
|
|
210
|
+
name: names.csrf,
|
|
211
|
+
value: "",
|
|
212
|
+
expiresAt: new Date(0),
|
|
213
|
+
maxAge: 0,
|
|
214
|
+
}),
|
|
215
|
+
]
|
|
216
|
+
}
|
|
217
|
+
|
|
218
|
+
private createCookieHeaders(input: {
|
|
219
|
+
readonly request: Request
|
|
220
|
+
readonly grantId: string
|
|
221
|
+
readonly sessionValue: string
|
|
222
|
+
readonly csrfToken: string
|
|
223
|
+
readonly expiresAt: Date
|
|
224
|
+
}): SharedAccessCookieHeaders {
|
|
225
|
+
const names = sharedCookieNames(input.grantId)
|
|
226
|
+
const maxAge = cookieMaxAge(input.expiresAt)
|
|
227
|
+
return {
|
|
228
|
+
csrfToken: input.csrfToken,
|
|
229
|
+
setCookies: [
|
|
230
|
+
serializeSharedCookie({
|
|
231
|
+
request: input.request,
|
|
232
|
+
name: names.session,
|
|
233
|
+
value: input.sessionValue,
|
|
234
|
+
expiresAt: input.expiresAt,
|
|
235
|
+
maxAge,
|
|
236
|
+
httpOnly: true,
|
|
237
|
+
}),
|
|
238
|
+
serializeSharedCookie({
|
|
239
|
+
request: input.request,
|
|
240
|
+
name: names.csrf,
|
|
241
|
+
value: input.csrfToken,
|
|
242
|
+
expiresAt: input.expiresAt,
|
|
243
|
+
maxAge,
|
|
244
|
+
}),
|
|
245
|
+
],
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
private getProtocol(): SharedSessionProtocol {
|
|
250
|
+
if (this.protocol) return this.protocol
|
|
251
|
+
if (!this.host.storage.shareGrants || !this.host.storage.shareSessions) {
|
|
252
|
+
throw new Error("[SixbServer] Shared-access session storage is not configured.")
|
|
253
|
+
}
|
|
254
|
+
|
|
255
|
+
this.protocol = new SharedSessionProtocol({
|
|
256
|
+
host: this.host,
|
|
257
|
+
...(this.options.inactivityTtlMs === undefined
|
|
258
|
+
? {}
|
|
259
|
+
: { inactivityTtlMs: this.options.inactivityTtlMs }),
|
|
260
|
+
})
|
|
261
|
+
return this.protocol
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
export function isSharedAccessPublicRoute(request: Request): boolean {
|
|
266
|
+
return isSharedAccessPublicPath(new URL(request.url).pathname, request.method)
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export function isSharedAccessPublicPath(pathname: string, requestMethod: string): boolean {
|
|
270
|
+
const method = requestMethod.toUpperCase()
|
|
271
|
+
const normalizedPathname = normalizeRoutePath(pathname)
|
|
272
|
+
const suffix =
|
|
273
|
+
method === "POST" && normalizedPathname.endsWith("/exchange")
|
|
274
|
+
? "exchange"
|
|
275
|
+
: method === "GET" && normalizedPathname.endsWith("/session")
|
|
276
|
+
? "session"
|
|
277
|
+
: method === "POST" && normalizedPathname.endsWith("/sign-out")
|
|
278
|
+
? "sign-out"
|
|
279
|
+
: null
|
|
280
|
+
if (!suffix) return false
|
|
281
|
+
return matchesPathPattern(normalizedPathname, `/api/shared-access/:grantId/${suffix}`)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
export function isSharedSessionRoute(request: Request): boolean {
|
|
285
|
+
const method = request.method.toUpperCase()
|
|
286
|
+
const pathname = normalizeRoutePath(new URL(request.url).pathname)
|
|
287
|
+
return SHARED_SESSION_ROUTES.some(
|
|
288
|
+
(route) => route.method === method && matchesPathPattern(pathname, route.path)
|
|
289
|
+
)
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
export function sharedAccessCookieNames(grantId: string): {
|
|
293
|
+
readonly session: string
|
|
294
|
+
readonly csrf: string
|
|
295
|
+
} {
|
|
296
|
+
return sharedCookieNames(grantId)
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
export function sharedAccessUnauthenticatedResponse(): Response {
|
|
300
|
+
return sharedBoundaryJsonResponse({ error: "Shared access session is invalid" }, 401)
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
export function sharedAccessForbiddenResponse(): Response {
|
|
304
|
+
return sharedBoundaryJsonResponse({ error: "Shared access is not allowed for this request" }, 403)
|
|
305
|
+
}
|
|
306
|
+
|
|
307
|
+
export function sharedAccessUnavailableResponse(): Response {
|
|
308
|
+
return sharedBoundaryJsonResponse({ error: "Shared access is unavailable" }, 503)
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
export function sharedBoundaryJsonResponse(body: unknown, status: number): Response {
|
|
312
|
+
return new Response(JSON.stringify(body), {
|
|
313
|
+
status,
|
|
314
|
+
headers: sharedAccessSecurityHeaders(),
|
|
315
|
+
})
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
export function sharedAccessSecurityHeaders(): Headers {
|
|
319
|
+
return new Headers({
|
|
320
|
+
"cache-control": "no-store",
|
|
321
|
+
"content-security-policy": "default-src 'none'; frame-ancestors 'none'",
|
|
322
|
+
"content-type": "application/json; charset=utf-8",
|
|
323
|
+
"referrer-policy": "no-referrer",
|
|
324
|
+
"x-content-type-options": "nosniff",
|
|
325
|
+
"x-robots-tag": "noindex, nofollow",
|
|
326
|
+
})
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
function sharedCookieNames(grantId: string): { readonly session: string; readonly csrf: string } {
|
|
330
|
+
const digest = createHash("sha256").update(grantId).digest("hex")
|
|
331
|
+
return {
|
|
332
|
+
session: `${SHARED_SESSION_COOKIE_PREFIX}${digest}`,
|
|
333
|
+
csrf: `${SHARED_CSRF_COOKIE_PREFIX}${digest}`,
|
|
334
|
+
}
|
|
335
|
+
}
|
|
336
|
+
|
|
337
|
+
function serializeSharedCookie(input: {
|
|
338
|
+
readonly request: Request
|
|
339
|
+
readonly name: string
|
|
340
|
+
readonly value: string
|
|
341
|
+
readonly expiresAt: Date
|
|
342
|
+
readonly maxAge: number
|
|
343
|
+
readonly httpOnly?: boolean
|
|
344
|
+
}): string {
|
|
345
|
+
const parts = [
|
|
346
|
+
`${input.name}=${input.value}`,
|
|
347
|
+
`Path=${SHARED_COOKIE_PATH}`,
|
|
348
|
+
"SameSite=Strict",
|
|
349
|
+
`Max-Age=${Math.trunc(input.maxAge)}`,
|
|
350
|
+
`Expires=${input.expiresAt.toUTCString()}`,
|
|
351
|
+
]
|
|
352
|
+
if (input.httpOnly) parts.push("HttpOnly")
|
|
353
|
+
if (shouldUseSecureSharedCookie(input.request)) parts.push("Secure")
|
|
354
|
+
return parts.join("; ")
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
function cookieMaxAge(expiresAt: Date): number {
|
|
358
|
+
return Math.max(0, Math.floor((expiresAt.getTime() - Date.now()) / 1_000))
|
|
359
|
+
}
|
|
360
|
+
|
|
361
|
+
function shouldUseSecureSharedCookie(request: Request): boolean {
|
|
362
|
+
const url = new URL(request.url)
|
|
363
|
+
if (url.hostname === "localhost" || url.hostname === "127.0.0.1" || url.hostname === "::1") {
|
|
364
|
+
return false
|
|
365
|
+
}
|
|
366
|
+
return url.protocol === "https:" || process.env.NODE_ENV === "production"
|
|
367
|
+
}
|
|
368
|
+
|
|
369
|
+
function isStoredIdentifier(value: string): boolean {
|
|
370
|
+
return (
|
|
371
|
+
value.length > 0 &&
|
|
372
|
+
value.length <= STORED_IDENTIFIER_MAX_LENGTH &&
|
|
373
|
+
value.trim() === value &&
|
|
374
|
+
!value.includes("\0")
|
|
375
|
+
)
|
|
376
|
+
}
|