@sixb/server 0.1.19 → 0.1.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 +13 -22
- package/dist/artifacts/frame.d.ts +13 -0
- package/dist/artifacts/frame.d.ts.map +1 -0
- package/dist/auth/browser-origin.d.ts +9 -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/files/content.d.ts +2 -3
- package/dist/files/content.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3241 -2445
- package/dist/index.js.map +31 -26
- package/dist/openapi/tags.d.ts +10 -2
- package/dist/openapi/tags.d.ts.map +1 -1
- package/dist/registerRoutes.d.ts +3 -0
- package/dist/registerRoutes.d.ts.map +1 -1
- package/dist/routes/action-runs.d.ts +0 -2
- package/dist/routes/action-runs.d.ts.map +1 -1
- package/dist/routes/activity.d.ts +35 -0
- package/dist/routes/activity.d.ts.map +1 -0
- package/dist/routes/agents.d.ts +18 -29
- package/dist/routes/agents.d.ts.map +1 -1
- package/dist/routes/artifact-frames.d.ts +98 -0
- package/dist/routes/artifact-frames.d.ts.map +1 -0
- package/dist/routes/artifacts.d.ts +852 -0
- package/dist/routes/artifacts.d.ts.map +1 -0
- package/dist/routes/auth.d.ts +9 -18
- package/dist/routes/auth.d.ts.map +1 -1
- package/dist/routes/connector-connection-runs.d.ts +59 -59
- package/dist/routes/connector-connections.d.ts +2 -2
- package/dist/routes/datasets.d.ts +7 -7
- package/dist/routes/events.d.ts +1 -1
- package/dist/routes/objects.d.ts +0 -2
- package/dist/routes/objects.d.ts.map +1 -1
- package/dist/routes/pipelines.d.ts +31 -31
- package/dist/routes/projections.d.ts +10 -10
- package/dist/routes/share-grants.d.ts +5 -5
- package/dist/routes/syncs.d.ts +38 -38
- package/dist/routes/workflows.d.ts +30 -34
- package/dist/routes/workflows.d.ts.map +1 -1
- package/dist/routes/ws/events.d.ts.map +1 -1
- package/dist/routes/ws/subscription-hub.d.ts +8 -3
- package/dist/routes/ws/subscription-hub.d.ts.map +1 -1
- package/dist/schemas/activity.d.ts +1278 -0
- package/dist/schemas/activity.d.ts.map +1 -0
- package/dist/schemas/agents.d.ts +96 -144
- package/dist/schemas/agents.d.ts.map +1 -1
- package/dist/schemas/ai-accounting.d.ts +24 -24
- package/dist/schemas/ai-limits.d.ts +26 -26
- package/dist/schemas/artifacts.d.ts +1305 -0
- package/dist/schemas/artifacts.d.ts.map +1 -0
- package/dist/schemas/auth.d.ts +34 -69
- package/dist/schemas/auth.d.ts.map +1 -1
- package/dist/schemas/connectors.d.ts +30 -30
- package/dist/schemas/datasets.d.ts +10 -10
- package/dist/schemas/events.d.ts +6 -6
- package/dist/schemas/files.d.ts +0 -3
- package/dist/schemas/files.d.ts.map +1 -1
- package/dist/schemas/pipelines.d.ts +35 -35
- package/dist/schemas/projections.d.ts +40 -40
- package/dist/schemas/share-grants.d.ts +16 -16
- package/dist/schemas/syncs.d.ts +36 -36
- package/dist/schemas/workflows.d.ts +84 -84
- package/dist/server.d.ts +1 -2
- package/dist/server.d.ts.map +1 -1
- package/package.json +6 -6
- package/src/artifacts/frame.ts +46 -0
- package/src/auth/browser-origin.ts +40 -240
- package/src/auth/experience.ts +1 -4
- package/src/auth/guard.ts +4 -32
- package/src/auth/public-routes.ts +11 -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/files/content.ts +9 -13
- package/src/index.ts +1 -1
- package/src/openapi/tags.ts +8 -0
- package/src/registerRoutes.ts +9 -0
- package/src/routes/activity.ts +327 -0
- package/src/routes/agents.ts +1 -1
- package/src/routes/artifact-frames.ts +138 -0
- package/src/routes/artifacts.ts +442 -0
- package/src/routes/auth.ts +32 -111
- package/src/routes/file-downloads.ts +1 -3
- package/src/routes/ws/events.ts +3 -2
- package/src/routes/ws/subscription-hub.ts +53 -20
- package/src/schemas/activity.ts +285 -0
- package/src/schemas/agents.ts +1 -2
- package/src/schemas/artifacts.ts +158 -0
- package/src/schemas/auth.ts +2 -15
- package/src/schemas/files.ts +0 -6
- package/src/server.ts +27 -24
- 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sixb/server",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.21",
|
|
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.21"
|
|
42
42
|
},
|
|
43
43
|
"devDependencies": {
|
|
44
|
-
"@sixb/auth-magic-link": "0.1.
|
|
45
|
-
"@sixb/auth-oidc": "0.1.
|
|
44
|
+
"@sixb/auth-magic-link": "0.1.6",
|
|
45
|
+
"@sixb/auth-oidc": "0.1.6",
|
|
46
46
|
"@sixb/cli-core": "0.1.8",
|
|
47
|
-
"@sixb/core": "0.1.
|
|
48
|
-
"@sixb/sqlite": "0.1.
|
|
47
|
+
"@sixb/core": "0.1.21",
|
|
48
|
+
"@sixb/sqlite": "0.1.21",
|
|
49
49
|
"@types/bun": "latest",
|
|
50
50
|
"typescript": "^5.7.0"
|
|
51
51
|
},
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { ARTIFACT_FRAME_ROUTE_PREFIX } from "@sixb/core/internal/artifacts/frames"
|
|
2
|
+
import {
|
|
3
|
+
type ResolvedSixbApiBrowserPolicy,
|
|
4
|
+
resolveApiBrowserPublicOrigin,
|
|
5
|
+
} from "../auth/browser-origin"
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Hosts a frame may load from besides its own files: CSS and script libraries and web fonts. Each
|
|
9
|
+
* is a public CDN; a frame that uses one contacts it when it opens.
|
|
10
|
+
*/
|
|
11
|
+
const FRAME_CDN_ALLOWLIST = [
|
|
12
|
+
"https://cdn.jsdelivr.net",
|
|
13
|
+
"https://cdnjs.cloudflare.com",
|
|
14
|
+
"https://unpkg.com",
|
|
15
|
+
"https://fonts.googleapis.com",
|
|
16
|
+
"https://fonts.gstatic.com",
|
|
17
|
+
] as const
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* The policy every frame response carries, 404s included. The frame is sandboxed without
|
|
21
|
+
* `allow-same-origin`, so its page cannot read the app's cookies or call the API as the reader;
|
|
22
|
+
* it loads only its own version's files, under its token, and the CDNs above; only the app's
|
|
23
|
+
* origins may show it.
|
|
24
|
+
*/
|
|
25
|
+
export function frameContentSecurityPolicy(input: {
|
|
26
|
+
readonly policy: ResolvedSixbApiBrowserPolicy
|
|
27
|
+
readonly request: Request
|
|
28
|
+
readonly token: string
|
|
29
|
+
}): string {
|
|
30
|
+
const origin = resolveApiBrowserPublicOrigin(input.policy, input.request)
|
|
31
|
+
const base = `${origin}${ARTIFACT_FRAME_ROUTE_PREFIX}${input.token}/`
|
|
32
|
+
const cdn = FRAME_CDN_ALLOWLIST.join(" ")
|
|
33
|
+
return [
|
|
34
|
+
"default-src 'none'",
|
|
35
|
+
`script-src ${base} 'unsafe-inline' ${cdn}`,
|
|
36
|
+
`style-src ${base} 'unsafe-inline' ${cdn}`,
|
|
37
|
+
`img-src ${base} data: blob: ${cdn}`,
|
|
38
|
+
`font-src ${base} data: ${cdn}`,
|
|
39
|
+
`media-src ${base} data: blob:`,
|
|
40
|
+
`connect-src ${base}`,
|
|
41
|
+
"form-action 'none'",
|
|
42
|
+
"base-uri 'none'",
|
|
43
|
+
`frame-ancestors 'self' ${input.policy.allowedOrigins.join(" ")}`.trim(),
|
|
44
|
+
"sandbox allow-scripts allow-popups allow-popups-to-escape-sandbox allow-modals",
|
|
45
|
+
].join("; ")
|
|
46
|
+
}
|
|
@@ -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,33 @@ 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
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
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
|
-
|
|
90
|
+
/**
|
|
91
|
+
* Whether the request's Origin may call the API with a session. An Origin that is not an http(s)
|
|
92
|
+
* origin, such as a sandboxed frame's `null`, is not allowed, never an error: the CORS plugin asks
|
|
93
|
+
* this of every request, and a throw there replaces the route's response with the error's.
|
|
94
|
+
*/
|
|
209
95
|
export function isAllowedApiBrowserOrigin(
|
|
210
96
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
211
97
|
request: Request
|
|
212
98
|
): boolean {
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
return
|
|
99
|
+
try {
|
|
100
|
+
const origin = normalizeRequestOrigin(request)
|
|
101
|
+
return origin !== null && isAllowedOrigin(policy, request, origin)
|
|
102
|
+
} catch (error) {
|
|
103
|
+
if (error instanceof BrowserOriginError) return false
|
|
104
|
+
throw error
|
|
216
105
|
}
|
|
217
|
-
|
|
218
|
-
return (
|
|
219
|
-
findAllowedBrowserOrigin(policy, origin) !== null ||
|
|
220
|
-
isSameOriginApiRequest(policy, origin, request)
|
|
221
|
-
)
|
|
222
106
|
}
|
|
223
107
|
|
|
224
108
|
export function resolveApiBrowserAuthRedirectContext(
|
|
@@ -226,58 +110,21 @@ export function resolveApiBrowserAuthRedirectContext(
|
|
|
226
110
|
request: Request,
|
|
227
111
|
input: AuthRedirectInput
|
|
228
112
|
): AuthRedirectContext {
|
|
229
|
-
const audience = resolveRequiredAuthAudience(input.audience)
|
|
230
|
-
const returnTo = resolveApiBrowserReturnTo(policy, request, input, audience)
|
|
231
|
-
|
|
232
113
|
return {
|
|
233
|
-
|
|
234
|
-
returnTo,
|
|
114
|
+
returnTo: resolveApiBrowserReturnTo(policy, request, input),
|
|
235
115
|
requestOrigin: resolveApiBrowserPublicOrigin(policy, request),
|
|
236
116
|
}
|
|
237
117
|
}
|
|
238
118
|
|
|
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
|
-
|
|
119
|
+
/** An invitation lands where the inviter works, or on the app when the request has no Origin. */
|
|
258
120
|
export function resolveApiBrowserInvitationRedirectContext(
|
|
259
121
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
260
122
|
request: Request,
|
|
261
123
|
input: AuthInvitationRedirectInput
|
|
262
124
|
): AuthInvitationRedirectContext {
|
|
263
125
|
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
126
|
return resolveApiBrowserAuthRedirectContext(policy, request, {
|
|
279
|
-
|
|
280
|
-
fallbackReturnToOrigin: destination.origin,
|
|
127
|
+
fallbackReturnToOrigin: authContext.browserOrigin ?? policy.allowedOrigins[0],
|
|
281
128
|
returnTo: input.returnTo,
|
|
282
129
|
})
|
|
283
130
|
}
|
|
@@ -289,51 +136,21 @@ export function resolveApiBrowserPublicOrigin(
|
|
|
289
136
|
return policy.publicOrigin ?? new URL(request.url).origin
|
|
290
137
|
}
|
|
291
138
|
|
|
292
|
-
function
|
|
139
|
+
function isAllowedOrigin(
|
|
293
140
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
141
|
+
request: Request,
|
|
294
142
|
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
143
|
): 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
|
|
144
|
+
return (
|
|
145
|
+
policy.allowedOrigins.includes(origin) ||
|
|
146
|
+
origin === resolveApiBrowserPublicOrigin(policy, request)
|
|
147
|
+
)
|
|
330
148
|
}
|
|
331
149
|
|
|
332
150
|
function resolveApiBrowserReturnTo(
|
|
333
151
|
policy: ResolvedSixbApiBrowserPolicy,
|
|
334
152
|
request: Request,
|
|
335
|
-
input: AuthRedirectInput
|
|
336
|
-
audience: AuthSessionAudience
|
|
153
|
+
input: AuthRedirectInput
|
|
337
154
|
): string {
|
|
338
155
|
const rawReturnTo = input.returnTo?.trim()
|
|
339
156
|
const value =
|
|
@@ -354,35 +171,18 @@ function resolveApiBrowserReturnTo(
|
|
|
354
171
|
throw new BrowserOriginError("[SixbServer] Auth return target must be an absolute URL.")
|
|
355
172
|
}
|
|
356
173
|
|
|
357
|
-
if (
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
174
|
+
if (
|
|
175
|
+
(url.protocol !== "http:" && url.protocol !== "https:") ||
|
|
176
|
+
url.username ||
|
|
177
|
+
url.password ||
|
|
178
|
+
!isAllowedOrigin(policy, request, url.origin)
|
|
179
|
+
) {
|
|
363
180
|
throw new BrowserOriginError("[SixbServer] Auth return target is not allowed.")
|
|
364
181
|
}
|
|
365
182
|
|
|
366
183
|
return url.toString()
|
|
367
184
|
}
|
|
368
185
|
|
|
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
186
|
function normalizeRequestOrigin(request: Request): string | null {
|
|
387
187
|
const origin = request.headers.get("origin")
|
|
388
188
|
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
|
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { AGENT_API_GATEWAY_PREFIX } from "@sixb/core/internal/agents"
|
|
2
|
+
import { ARTIFACT_FRAME_ROUTE_PREFIX } from "@sixb/core/internal/artifacts/frames"
|
|
2
3
|
import { isCsrfExemptMethod } from "@sixb/core/internal/auth"
|
|
3
4
|
import { FILE_DOWNLOAD_ROUTE_PREFIX } from "@sixb/core/internal/blob-storage"
|
|
4
5
|
import { isSharedAccessPublicPath } from "./shared-access"
|
|
@@ -10,11 +11,6 @@ export type RouteAccessKind = "public" | "api" | "html" | "websocket"
|
|
|
10
11
|
export interface RouteAccess {
|
|
11
12
|
readonly kind: RouteAccessKind
|
|
12
13
|
readonly csrfProtected: boolean
|
|
13
|
-
/**
|
|
14
|
-
* An instance account page every signed-in user needs, whichever web app they may open: approving
|
|
15
|
-
* a CLI login. Application access does not gate it.
|
|
16
|
-
*/
|
|
17
|
-
readonly account?: true
|
|
18
14
|
}
|
|
19
15
|
|
|
20
16
|
export function classifyRoute(request: Request): RouteAccess {
|
|
@@ -33,11 +29,7 @@ export function classifyRoute(request: Request): RouteAccess {
|
|
|
33
29
|
return { kind: "api", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
34
30
|
}
|
|
35
31
|
|
|
36
|
-
if (pathname === "/auth/device") {
|
|
37
|
-
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method), account: true }
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
if (pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
32
|
+
if (pathname === "/auth/device" || pathname === "/docs" || pathname.startsWith("/docs/")) {
|
|
41
33
|
return { kind: "html", csrfProtected: !isCsrfExemptMethod(request.method) }
|
|
42
34
|
}
|
|
43
35
|
|
|
@@ -80,6 +72,15 @@ export function isPublicRoute(pathname: string, method: string): boolean {
|
|
|
80
72
|
return true
|
|
81
73
|
}
|
|
82
74
|
|
|
75
|
+
// A frame's page is sandboxed with an opaque origin, so it cannot hold a session either. The
|
|
76
|
+
// token in a frame link's path is the credential.
|
|
77
|
+
if (
|
|
78
|
+
pathname.startsWith(ARTIFACT_FRAME_ROUTE_PREFIX) &&
|
|
79
|
+
(normalizedMethod === "GET" || normalizedMethod === "HEAD")
|
|
80
|
+
) {
|
|
81
|
+
return true
|
|
82
|
+
}
|
|
83
|
+
|
|
83
84
|
// Public because a webhook cannot carry a session: the signature its connector
|
|
84
85
|
// verifies is the credential. POST only — `WebhookDefinition.method` is the literal
|
|
85
86
|
// `"POST"`, so nothing else is ever registered here, and the allow-list should not be
|
package/src/auth/responses.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import type { AuthSessionAudience } from "@sixb/core"
|
|
2
1
|
import { returnToForRequest } from "./return-to"
|
|
3
2
|
|
|
4
3
|
export function jsonAuthRequiredResponse(): Response {
|
|
@@ -17,7 +16,6 @@ export function htmlAuthRedirectResponse(
|
|
|
17
16
|
request: Request,
|
|
18
17
|
options: {
|
|
19
18
|
readonly absoluteReturnTo?: boolean
|
|
20
|
-
readonly audience?: AuthSessionAudience
|
|
21
19
|
} = {}
|
|
22
20
|
): Response {
|
|
23
21
|
const requestUrl = new URL(request.url)
|
|
@@ -25,9 +23,6 @@ export function htmlAuthRedirectResponse(
|
|
|
25
23
|
? new URL(returnToForRequest(request), requestUrl.origin).toString()
|
|
26
24
|
: returnToForRequest(request)
|
|
27
25
|
const params = new URLSearchParams({ returnTo: rawReturnTo })
|
|
28
|
-
if (options.absoluteReturnTo && options.audience) {
|
|
29
|
-
params.set("audience", options.audience)
|
|
30
|
-
}
|
|
31
26
|
|
|
32
27
|
return new Response(null, {
|
|
33
28
|
status: 302,
|
|
@@ -13,9 +13,7 @@ export function createSessionRenewalCookieHeaders(input: {
|
|
|
13
13
|
readonly session: AuthenticatedAuthSession
|
|
14
14
|
readonly csrfToken?: string
|
|
15
15
|
}): { readonly csrfToken: string; readonly headers: readonly [string, string] } | null {
|
|
16
|
-
const cookieOptions = input.host.auth.getCookieOptions(
|
|
17
|
-
audience: input.session.session.audience,
|
|
18
|
-
})
|
|
16
|
+
const cookieOptions = input.host.auth.getCookieOptions()
|
|
19
17
|
const sessionValue = getCookie(input.request, cookieOptions.sessionCookieName)
|
|
20
18
|
if (!sessionValue) {
|
|
21
19
|
return null
|
|
@@ -299,7 +299,7 @@ export function isSharedAccessPublicPath(pathname: string, requestMethod: string
|
|
|
299
299
|
/**
|
|
300
300
|
* The header selects the grant. File GET/HEAD routes also accept the selector in the query, because
|
|
301
301
|
* `<img>`, `<video>`, and download links cannot send headers. Either way it only names which
|
|
302
|
-
* grant cookie to read; the HttpOnly cookie remains the credential
|
|
302
|
+
* grant cookie to read; the HttpOnly cookie remains the credential.
|
|
303
303
|
*/
|
|
304
304
|
function selectSharedAccessGrant(request: Request): SharedAccessGrantSelection {
|
|
305
305
|
const header = request.headers.get(SHARED_ACCESS_GRANT_HEADER_NAME)
|