@fabrika/proxy-core 0.9.0-dev.2 → 0.9.0-dev.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/package.json +15 -5
- package/src/authorize.ts +105 -33
- package/src/brand.ts +121 -0
- package/src/cache.ts +0 -0
- package/src/constants.ts +9 -0
- package/src/handoff.ts +8 -0
- package/src/headers.ts +24 -6
- package/src/iam.ts +3 -1
- package/src/index.ts +4 -0
- package/src/manifest.ts +210 -12
- package/src/page-style.ts +505 -0
- package/src/pages.ts +150 -0
- package/src/service.ts +49 -48
- package/types/src/authorize.d.ts +27 -3
- package/types/src/brand.d.ts +104 -0
- package/types/src/cache.d.ts +6 -3
- package/types/src/constants.d.ts +7 -0
- package/types/src/handoff.d.ts +5 -0
- package/types/src/headers.d.ts +16 -4
- package/types/src/index.d.ts +3 -1
- package/types/src/manifest.d.ts +2187 -1160
- package/types/src/page-style.d.ts +40 -0
- package/types/src/pages.d.ts +62 -0
package/src/service.ts
CHANGED
|
@@ -35,9 +35,11 @@ import {
|
|
|
35
35
|
} from '@fabrika/auth-core'
|
|
36
36
|
import { uuidv7 } from '@fabrika/platform'
|
|
37
37
|
import { Authorizer, type AuthorizerOptions, type Decision, type DenyReason, type ForwardedRequest, type ResolvedApp } from './authorize'
|
|
38
|
+
import type { InstallationBrand } from './brand'
|
|
38
39
|
import type { TokenCache } from './cache'
|
|
39
40
|
import {
|
|
40
41
|
APP_QUERY_PARAM,
|
|
42
|
+
AUTH_SIGNOUT_PATH,
|
|
41
43
|
DEFAULT_HEALTH_PATH,
|
|
42
44
|
DEFAULT_VERIFY_PATH,
|
|
43
45
|
FORWARD_AUTHORIZATION_HEADER,
|
|
@@ -66,6 +68,7 @@ import type { DelegationIssuer, IamGateway } from './iam'
|
|
|
66
68
|
import { type LogFields, type ProxyLogger, redactPath, silentLogger } from './log'
|
|
67
69
|
import { formatOAuthBearerChallenge, isApplicationEntry, type ManifestEndpointRow, type ProxyApp, type ProxyManifest } from './manifest'
|
|
68
70
|
import { findOAuthMetadata, OAUTH_METADATA_VERIFY_PATH, oauthMetadataResponse } from './oauth'
|
|
71
|
+
import { errorAnswer, isPageNavigation, type PageContent, pageResponse, renderPage } from './pages'
|
|
69
72
|
|
|
70
73
|
export interface VerifyServiceConfig {
|
|
71
74
|
manifest: ProxyManifest
|
|
@@ -99,6 +102,8 @@ export function createVerifyService(config: VerifyServiceConfig): VerifyService
|
|
|
99
102
|
const byId = new Map<string, ResolvedApp>()
|
|
100
103
|
const byHost = new Map<string, ResolvedApp>()
|
|
101
104
|
const policies = new Map<string, HeaderPolicy>()
|
|
105
|
+
// The client's logo on every page this service answers with (ADR-0066); the fabrika mark without one.
|
|
106
|
+
const brand = config.manifest.brand ?? null
|
|
102
107
|
for (const app of config.manifest.apps) {
|
|
103
108
|
const resolved = resolveApp(app)
|
|
104
109
|
byId.set(app.id, resolved)
|
|
@@ -139,17 +144,19 @@ export function createVerifyService(config: VerifyServiceConfig): VerifyService
|
|
|
139
144
|
return withPolicy(textResponse(405, 'method not allowed'), BASE_HEADER_POLICY)
|
|
140
145
|
}
|
|
141
146
|
|
|
147
|
+
// The forwarded request's headers are this request's: `forward_auth` and the Worker copy the original ones.
|
|
148
|
+
const asPage = isPageNavigation(request.headers)
|
|
142
149
|
const read = readForwardedRequest(request, requestId)
|
|
143
150
|
if (!read.ok) {
|
|
144
151
|
const status = read.reason === 'non_canonical_path' ? 400 : 403
|
|
145
|
-
return withPolicy(denied(logger, { requestId }, { outcome: 'deny', status, reason: read.reason }), earlyPolicy(request, url))
|
|
152
|
+
return withPolicy(denied(logger, { requestId }, { outcome: 'deny', status, reason: read.reason }, { asPage, brand }), earlyPolicy(request, url))
|
|
146
153
|
}
|
|
147
154
|
const forwarded = read.request
|
|
148
155
|
|
|
149
156
|
const resolved = selectApp(url, forwarded.url.host, byId, byHost)
|
|
150
157
|
if (resolved === null) {
|
|
151
158
|
const fields = { requestId, host: forwarded.url.host, path: redactPath(forwarded.url.pathname) }
|
|
152
|
-
return withPolicy(denied(logger, fields, { outcome: 'deny', status: 403, reason: 'no_app' }), BASE_HEADER_POLICY)
|
|
159
|
+
return withPolicy(denied(logger, fields, { outcome: 'deny', status: 403, reason: 'no_app' }, { asPage, brand }), BASE_HEADER_POLICY)
|
|
153
160
|
}
|
|
154
161
|
|
|
155
162
|
if (url.pathname === OAUTH_METADATA_VERIFY_PATH) {
|
|
@@ -162,9 +169,12 @@ export function createVerifyService(config: VerifyServiceConfig): VerifyService
|
|
|
162
169
|
// The handoff callback is checked BEFORE the endpoint table: it is how a browser obtains a
|
|
163
170
|
// session, so it cannot itself be behind an endpoint. Because Caddy returns a non-2xx auth
|
|
164
171
|
// response verbatim, answering 302 + Set-Cookie here reaches the client and never the app.
|
|
172
|
+
// The sign-out is answered here for the same reason: a browser whose session is gone must still reach it.
|
|
165
173
|
const isCallback = forwarded.url.pathname === AUTH_CALLBACK_PATH
|
|
166
174
|
const decision = isCallback
|
|
167
175
|
? await authorizer.authorizeCallback(resolved, forwarded)
|
|
176
|
+
: forwarded.url.pathname === AUTH_SIGNOUT_PATH
|
|
177
|
+
? authorizer.signOut(resolved, forwarded)
|
|
168
178
|
: await authorizer.authorize(resolved, forwarded)
|
|
169
179
|
const fields: LogFields = {
|
|
170
180
|
requestId,
|
|
@@ -202,8 +212,14 @@ export function createVerifyService(config: VerifyServiceConfig): VerifyService
|
|
|
202
212
|
applyCrossOriginHeaders(answer.headers, preflightHeaders(decision.allowOrigin, decision.method))
|
|
203
213
|
return answer
|
|
204
214
|
}
|
|
205
|
-
|
|
206
|
-
const
|
|
215
|
+
// A download's every answer is an attachment, so its refusal stays the text: a page would be saved, not shown.
|
|
216
|
+
const download = isDownload(resolved, forwarded)
|
|
217
|
+
const answer = decision.outcome === 'handoff'
|
|
218
|
+
? handoff(logger, fields, decision)
|
|
219
|
+
: decision.outcome === 'signout'
|
|
220
|
+
? signedOut(logger, fields, decision)
|
|
221
|
+
: denied(logger, fields, decision, { isCallback, asPage: asPage && !download, brand })
|
|
222
|
+
const treated = download ? withFileTreatment(answer, appFileTreatment(resolved.app)) : withPolicy(answer, policy)
|
|
207
223
|
if (decision.outcome === 'deny' && decision.crossOrigin !== undefined) {
|
|
208
224
|
applyCrossOriginHeaders(treated.headers, crossOriginHeaders(decision.crossOrigin))
|
|
209
225
|
}
|
|
@@ -212,7 +228,7 @@ export function createVerifyService(config: VerifyServiceConfig): VerifyService
|
|
|
212
228
|
// The last line of the fail-closed guarantee. No `err` is inspected or logged: a caught
|
|
213
229
|
// error can stringify a URL, a header or a body, any of which may carry a credential.
|
|
214
230
|
logger.error('verify failed', { requestId })
|
|
215
|
-
return withPolicy(
|
|
231
|
+
return withPolicy(errorAnswer(403, DENY_TEXT[403], isPageNavigation(request.headers), brand), earlyPolicy(request, null))
|
|
216
232
|
}
|
|
217
233
|
}
|
|
218
234
|
|
|
@@ -238,6 +254,17 @@ function handoff(logger: ProxyLogger, fields: LogFields, decision: Extract<Decis
|
|
|
238
254
|
return handoffResponse(decision)
|
|
239
255
|
}
|
|
240
256
|
|
|
257
|
+
/**
|
|
258
|
+
* Clear the app session with the attributes it was set with, so the browser matches and drops it. The cookie is
|
|
259
|
+
* cleared whether or not the request carried one: the answer is the same for a browser already signed out.
|
|
260
|
+
*/
|
|
261
|
+
function signedOut(logger: ProxyLogger, fields: LogFields, decision: Extract<Decision, { outcome: 'signout' }>): Response {
|
|
262
|
+
logger.info('signout', fields)
|
|
263
|
+
const headers = new Headers({ location: decision.location, 'cache-control': 'no-store' })
|
|
264
|
+
headers.append('set-cookie', secureCookie(SESSION_COOKIE, '', 0))
|
|
265
|
+
return new Response(null, { status: 302, headers })
|
|
266
|
+
}
|
|
267
|
+
|
|
241
268
|
/** An answer the proxy writes reaches the client as-is, so it carries the policy the application's own answers do. */
|
|
242
269
|
function withPolicy(response: Response, policy: HeaderPolicy): Response {
|
|
243
270
|
applyHeaderPolicy(response.headers, policy)
|
|
@@ -262,7 +289,7 @@ function isDownload(resolved: ResolvedApp, forwarded: ForwardedRequest): boolean
|
|
|
262
289
|
* Render a redeemed handoff: set the app session on THIS host and send the browser where IAM said.
|
|
263
290
|
*
|
|
264
291
|
* This is the ONE place the proxy writes the long-lived app session. It separately writes a
|
|
265
|
-
* short-lived handoff verifier when starting login, then clears that verifier here.
|
|
292
|
+
* short-lived handoff verifier when starting login, then clears that verifier here. The sign-out clears the session.
|
|
266
293
|
*
|
|
267
294
|
* Every attribute is fixed by `SESSION_COOKIE`'s `__Host-` prefix: `Secure`, `Path=/`, and no
|
|
268
295
|
* `Domain`. The absent `Domain` is the substance — the session belongs to this app's host and no
|
|
@@ -284,12 +311,15 @@ function handoffResponse(decision: Extract<Decision, { outcome: 'handoff' }>): R
|
|
|
284
311
|
})
|
|
285
312
|
}
|
|
286
313
|
|
|
287
|
-
/**
|
|
314
|
+
/**
|
|
315
|
+
* Emit the log line for a refusal and render its response. The reason is logged, never returned. `asPage` is a
|
|
316
|
+
* navigation that is not a download (`./pages`), which reads the status's page in place of its text.
|
|
317
|
+
*/
|
|
288
318
|
function denied(
|
|
289
319
|
logger: ProxyLogger,
|
|
290
320
|
fields: LogFields,
|
|
291
321
|
decision: Extract<Decision, { outcome: 'deny' | 'login' }>,
|
|
292
|
-
isCallback = false,
|
|
322
|
+
{ isCallback = false, asPage, brand }: { isCallback?: boolean; asPage: boolean; brand: InstallationBrand | null },
|
|
293
323
|
): Response {
|
|
294
324
|
const reason: DenyReason = decision.reason
|
|
295
325
|
if (decision.outcome === 'login') {
|
|
@@ -299,7 +329,7 @@ function denied(
|
|
|
299
329
|
: loginRequired(decision.location, decision.handoff)
|
|
300
330
|
}
|
|
301
331
|
logger.warn('deny', { ...fields, reason, status: decision.status })
|
|
302
|
-
const response = isCallback ? callbackFailure(decision.status) :
|
|
332
|
+
const response = isCallback ? callbackFailure(decision.status, brand) : errorAnswer(decision.status, DENY_TEXT[decision.status], asPage, brand)
|
|
303
333
|
if (decision.clearHandoffState !== undefined) {
|
|
304
334
|
response.headers.append('set-cookie', clearHandoffCookie(decision.clearHandoffState))
|
|
305
335
|
}
|
|
@@ -310,9 +340,8 @@ function denied(
|
|
|
310
340
|
}
|
|
311
341
|
|
|
312
342
|
/**
|
|
313
|
-
* The callback refusal is
|
|
314
|
-
*
|
|
315
|
-
* redirect, and a viewport containing `forbidden` describes nothing the reader can act on.
|
|
343
|
+
* The callback refusal is always a page, also without `Sec-Fetch-Mode`: this path is only ever reached by
|
|
344
|
+
* a browser following IAM's redirect, and its text says what the sign-in did rather than the status's.
|
|
316
345
|
*
|
|
317
346
|
* It deliberately does NOT bounce back into login. A browser that dropped the handoff cookie on this
|
|
318
347
|
* host while keeping IAM's session would be sent straight back here, and the automatic retry becomes
|
|
@@ -322,42 +351,14 @@ function denied(
|
|
|
322
351
|
* out here anyway: `invalid_session` covers an expired verifier and a code IAM refused alike. Coarse
|
|
323
352
|
* deny reasons stay in the log (`../proxy/CLAUDE.md`).
|
|
324
353
|
*/
|
|
325
|
-
function callbackFailure(status: number): Response {
|
|
326
|
-
const
|
|
327
|
-
?
|
|
328
|
-
:
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
<head>
|
|
334
|
-
<meta charset="utf-8">
|
|
335
|
-
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
336
|
-
<title>${title}</title>
|
|
337
|
-
<style>
|
|
338
|
-
body { margin: 0; min-height: 100vh; display: flex; align-items: center; justify-content: center; background: #f4f4f5; color: #18181b;
|
|
339
|
-
font: 16px/1.6 system-ui, -apple-system, "Segoe UI", sans-serif; }
|
|
340
|
-
main { max-width: 27rem; padding: 2rem; }
|
|
341
|
-
h1 { margin: 0 0 .5rem; font-size: 1.25rem; }
|
|
342
|
-
p { margin: 0 0 1.5rem; color: #52525b; }
|
|
343
|
-
a { display: inline-block; padding: .55rem 1.1rem; border-radius: .375rem; background: #18181b; color: #fafafa; text-decoration: none; }
|
|
344
|
-
@media (prefers-color-scheme: dark) {
|
|
345
|
-
body { background: #18181b; color: #fafafa; }
|
|
346
|
-
p { color: #a1a1aa; }
|
|
347
|
-
a { background: #fafafa; color: #18181b; }
|
|
348
|
-
}
|
|
349
|
-
</style>
|
|
350
|
-
</head>
|
|
351
|
-
<body>
|
|
352
|
-
<main>
|
|
353
|
-
<h1>${title}</h1>
|
|
354
|
-
<p>${detail}</p>
|
|
355
|
-
<a href="/">Start again</a>
|
|
356
|
-
</main>
|
|
357
|
-
</body>
|
|
358
|
-
</html>
|
|
359
|
-
`
|
|
360
|
-
return new Response(body, { status, headers: { 'content-type': 'text/html; charset=utf-8', 'cache-control': 'no-store' } })
|
|
354
|
+
function callbackFailure(status: number, brand: InstallationBrand | null): Response {
|
|
355
|
+
const content: Omit<PageContent, 'action'> = status === 503
|
|
356
|
+
? { title: 'Sign-in is unavailable', detail: 'The sign-in service could not be reached. Please try again in a moment.' }
|
|
357
|
+
: {
|
|
358
|
+
title: 'Sign-in did not complete',
|
|
359
|
+
detail: 'The sign-in link has expired or has already been used. Signing in again will issue a new one.',
|
|
360
|
+
}
|
|
361
|
+
return pageResponse(status, renderPage({ ...content, action: { href: '/', label: 'Start again' } }, String(status), brand))
|
|
361
362
|
}
|
|
362
363
|
|
|
363
364
|
/** The bounce a document navigation gets: the browser follows it and comes back signed in. */
|
package/types/src/authorize.d.ts
CHANGED
|
@@ -43,8 +43,10 @@ export type DenyReason =
|
|
|
43
43
|
| 'caller_kind'
|
|
44
44
|
/** The token does not satisfy the endpoint's requirement. */
|
|
45
45
|
| 'insufficient_permission'
|
|
46
|
-
/** A session request that is not a `GET
|
|
46
|
+
/** A session request that is not a `GET`, or a sign-out, did not come from the app's own origin. */
|
|
47
47
|
| 'cross_site'
|
|
48
|
+
/** A sign-out's return is absent or not a path on the app's own origin. */
|
|
49
|
+
| 'bad_redirect'
|
|
48
50
|
/** The request's `Content-Type` is not one the endpoint admits. */
|
|
49
51
|
| 'content_type'
|
|
50
52
|
/**
|
|
@@ -77,8 +79,8 @@ export type Decision = {
|
|
|
77
79
|
/** The `Access-Control-Allow-Origin` the answer carries: the request's admitted origin, `*`, or none. */
|
|
78
80
|
crossOrigin: string | null;
|
|
79
81
|
/**
|
|
80
|
-
* Whether the request's own `Authorization` reaches the application: on
|
|
81
|
-
* carries a platform key. Every other anonymous request loses it (ADR-0022 rule 3).
|
|
82
|
+
* Whether the request's own `Authorization` reaches the application: on the ops row, and on a webhook row that
|
|
83
|
+
* forwards it unless it carries a platform key. Every other anonymous request loses it (ADR-0022 rule 3).
|
|
82
84
|
*/
|
|
83
85
|
forwardsAuthorization: boolean;
|
|
84
86
|
} | {
|
|
@@ -124,6 +126,15 @@ export type Decision = {
|
|
|
124
126
|
session: string;
|
|
125
127
|
expiresAt: number;
|
|
126
128
|
handoffState: string;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* A same-origin sign-out (ADR-0067 §5): the app session cookie is cleared and the browser goes to IAM's release,
|
|
132
|
+
* which returns it to `location`'s own redirect on this app's origin.
|
|
133
|
+
*/
|
|
134
|
+
| {
|
|
135
|
+
outcome: 'signout';
|
|
136
|
+
status: 302;
|
|
137
|
+
location: string;
|
|
127
138
|
};
|
|
128
139
|
/** The original request, reconstructed from what `forward_auth` forwarded. */
|
|
129
140
|
export interface ForwardedRequest {
|
|
@@ -221,6 +232,15 @@ export declare class Authorizer {
|
|
|
221
232
|
*/
|
|
222
233
|
authorizeCallback(resolved: ResolvedApp, request: ForwardedRequest): Promise<Decision>;
|
|
223
234
|
private redeem;
|
|
235
|
+
/**
|
|
236
|
+
* Sign the browser out of this host (ADR-0067 §5). Called for the reserved sign-out path only, BEFORE the endpoint
|
|
237
|
+
* is planned, for any entry and any session. It drops this session's cached token, so the next request re-mints
|
|
238
|
+
* from IAM, which has revoked the session by then or still holds it; the cookie itself is cleared by the response.
|
|
239
|
+
*
|
|
240
|
+
* Admission is `Sec-Fetch-Site: same-origin`, absent included: the request changes state, and another page must not
|
|
241
|
+
* sign a person out, as for a session request that is not a `GET` (ADR-0022 rule 3, step 6).
|
|
242
|
+
*/
|
|
243
|
+
signOut(resolved: ResolvedApp, request: ForwardedRequest): Decision;
|
|
224
244
|
private loginDecision;
|
|
225
245
|
/**
|
|
226
246
|
* Where to send the browser to log in, returning to the originally requested URL afterwards.
|
|
@@ -228,6 +248,10 @@ export declare class Authorizer {
|
|
|
228
248
|
* The scheme comes from the MANIFEST, not from the forwarded request: behind a TLS-terminating
|
|
229
249
|
* balancer the proxy is reached over plain HTTP and `X-Forwarded-Proto` says so, which would send
|
|
230
250
|
* the browser back to an `http://` URL for an origin only served over `https://`.
|
|
251
|
+
*
|
|
252
|
+
* `locale` is the language the application left for this browser on its host (`signInLocale`), passed on as IAM's
|
|
253
|
+
* `?locale=` so the first sign-in page speaks it. It picks IAM's words only: the decision, the return URL and the
|
|
254
|
+
* handoff are the same without it.
|
|
231
255
|
*/
|
|
232
256
|
private loginUrl;
|
|
233
257
|
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client's brand on fabrika's own pages (ADR-0066). An installation serves one client, so its logo is one setting
|
|
3
|
+
* of the installation: IAM keeps it, the console's Settings writes it, and the proxy manifest carries it to the pages the
|
|
4
|
+
* proxy answers with on every application host. A page shows it where it would otherwise draw the fabrika mark.
|
|
5
|
+
*
|
|
6
|
+
* A logo is an image a page embeds as a `data:` URI in an `<img>`, never markup: an SVG in an image runs no script, and
|
|
7
|
+
* a page that carries it loads nothing. Every consumer checks it here, the IAM write, the manifest parser and the
|
|
8
|
+
* console's own pre-check, so a logo that one of them admits passes the others. This module imports zod and nothing
|
|
9
|
+
* else, so the browser can use it.
|
|
10
|
+
*/
|
|
11
|
+
import { z } from 'zod';
|
|
12
|
+
export declare const BRAND_IMAGE_TYPES: readonly ["image/png", "image/webp", "image/svg+xml"];
|
|
13
|
+
export type BrandImageType = (typeof BRAND_IMAGE_TYPES)[number];
|
|
14
|
+
/** The most one image may weigh, decoded. A page carries it in every copy Caddy serves, so it stays a logo's size. */
|
|
15
|
+
export declare const MAX_BRAND_IMAGE_BYTES: number;
|
|
16
|
+
/** One image of the brand: its type and its bytes as canonical base64. */
|
|
17
|
+
export interface BrandImage {
|
|
18
|
+
readonly type: BrandImageType;
|
|
19
|
+
readonly base64: string;
|
|
20
|
+
}
|
|
21
|
+
/** The logo for a light page, and the one for a dark page when the light one would not read there. */
|
|
22
|
+
export interface InstallationBrand {
|
|
23
|
+
readonly light: BrandImage;
|
|
24
|
+
readonly dark?: BrandImage;
|
|
25
|
+
}
|
|
26
|
+
export type BrandImageProblem = 'type' | 'encoding' | 'size' | 'content';
|
|
27
|
+
/** Why an image cannot be the brand, or null. The type must be one of three and must be what the bytes are. */
|
|
28
|
+
export declare function brandImageProblem(image: {
|
|
29
|
+
readonly type: string;
|
|
30
|
+
readonly base64: string;
|
|
31
|
+
}): BrandImageProblem | null;
|
|
32
|
+
export declare function isBrandImageType(value: string): value is BrandImageType;
|
|
33
|
+
export declare const brandImageSchema: z.ZodEffects<z.ZodObject<{
|
|
34
|
+
type: z.ZodEnum<["image/png", "image/webp", "image/svg+xml"]>;
|
|
35
|
+
base64: z.ZodString;
|
|
36
|
+
}, "strict", z.ZodTypeAny, {
|
|
37
|
+
base64: string;
|
|
38
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
39
|
+
}, {
|
|
40
|
+
base64: string;
|
|
41
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
42
|
+
}>, {
|
|
43
|
+
base64: string;
|
|
44
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
45
|
+
}, {
|
|
46
|
+
base64: string;
|
|
47
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
48
|
+
}>;
|
|
49
|
+
export declare const installationBrandSchema: z.ZodObject<{
|
|
50
|
+
light: z.ZodEffects<z.ZodObject<{
|
|
51
|
+
type: z.ZodEnum<["image/png", "image/webp", "image/svg+xml"]>;
|
|
52
|
+
base64: z.ZodString;
|
|
53
|
+
}, "strict", z.ZodTypeAny, {
|
|
54
|
+
base64: string;
|
|
55
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
56
|
+
}, {
|
|
57
|
+
base64: string;
|
|
58
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
59
|
+
}>, {
|
|
60
|
+
base64: string;
|
|
61
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
62
|
+
}, {
|
|
63
|
+
base64: string;
|
|
64
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
65
|
+
}>;
|
|
66
|
+
dark: z.ZodOptional<z.ZodEffects<z.ZodObject<{
|
|
67
|
+
type: z.ZodEnum<["image/png", "image/webp", "image/svg+xml"]>;
|
|
68
|
+
base64: z.ZodString;
|
|
69
|
+
}, "strict", z.ZodTypeAny, {
|
|
70
|
+
base64: string;
|
|
71
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
72
|
+
}, {
|
|
73
|
+
base64: string;
|
|
74
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
75
|
+
}>, {
|
|
76
|
+
base64: string;
|
|
77
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
78
|
+
}, {
|
|
79
|
+
base64: string;
|
|
80
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
81
|
+
}>>;
|
|
82
|
+
}, "strict", z.ZodTypeAny, {
|
|
83
|
+
light: {
|
|
84
|
+
base64: string;
|
|
85
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
86
|
+
};
|
|
87
|
+
dark?: {
|
|
88
|
+
base64: string;
|
|
89
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
90
|
+
} | undefined;
|
|
91
|
+
}, {
|
|
92
|
+
light: {
|
|
93
|
+
base64: string;
|
|
94
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
95
|
+
};
|
|
96
|
+
dark?: {
|
|
97
|
+
base64: string;
|
|
98
|
+
type: "image/png" | "image/webp" | "image/svg+xml";
|
|
99
|
+
} | undefined;
|
|
100
|
+
}>;
|
|
101
|
+
/** The image as the `src` of an `<img>`. Base64 holds no `{`, so a Caddy `static_response` body keeps it as it is. */
|
|
102
|
+
export declare function brandImageDataUri(image: BrandImage): string;
|
|
103
|
+
/** Canonical base64 of `bytes`, the spelling the check requires. Chunked, so a large file stays within `fromCharCode`'s arguments. */
|
|
104
|
+
export declare function brandImageBase64(bytes: Uint8Array): string;
|
package/types/src/cache.d.ts
CHANGED
|
@@ -26,16 +26,19 @@ export interface TokenCache {
|
|
|
26
26
|
delete(key: string): void;
|
|
27
27
|
}
|
|
28
28
|
/**
|
|
29
|
-
* A bounded in-memory cache. Insertion-ordered eviction (Map iteration order) keeps it to
|
|
30
|
-
* `
|
|
29
|
+
* A bounded in-memory cache. Insertion-ordered eviction (Map iteration order) keeps it to `maxEntries` and to
|
|
30
|
+
* `maxBytes` of keys and tokens together, so a flood of distinct credentials cannot grow it without bound. The byte
|
|
31
|
+
* budget is what holds on Cloudflare: 10,000 application tokens of 24 KiB would pass a Worker isolate's 128 MB.
|
|
31
32
|
*
|
|
32
33
|
* The key is derived from a raw credential (see `cacheKey`). It is never logged, never serialized
|
|
33
34
|
* and never leaves the process.
|
|
34
35
|
*/
|
|
35
36
|
export declare class MemoryTokenCache implements TokenCache {
|
|
36
37
|
private readonly maxEntries;
|
|
38
|
+
private readonly maxBytes;
|
|
37
39
|
private readonly entries;
|
|
38
|
-
|
|
40
|
+
private bytes;
|
|
41
|
+
constructor(maxEntries?: number, maxBytes?: number);
|
|
39
42
|
get(key: string): CachedToken | undefined;
|
|
40
43
|
set(key: string, value: CachedToken): void;
|
|
41
44
|
delete(key: string): void;
|
package/types/src/constants.d.ts
CHANGED
|
@@ -35,6 +35,13 @@ export declare const APP_QUERY_PARAM = "app";
|
|
|
35
35
|
* credential that was just stripped from the logged URI.
|
|
36
36
|
*/
|
|
37
37
|
export declare const LOGIN_REDIRECT_PARAM = "redirect";
|
|
38
|
+
/**
|
|
39
|
+
* Reserved on every app host beside the handoff callback, and answered before endpoint selection: it clears the app
|
|
40
|
+
* session and sends the browser to IAM's release (ADR-0067 §5). It takes the return path in `LOGIN_REDIRECT_PARAM`.
|
|
41
|
+
*/
|
|
42
|
+
export declare const AUTH_SIGNOUT_PATH = "/__fabrika/auth/signout";
|
|
43
|
+
/** IAM's path that revokes the browser's terminal sessions and returns it to the application (ADR-0067 §5). */
|
|
44
|
+
export declare const SIGNOUT_RELEASE_PATH = "/auth/terminals/release";
|
|
38
45
|
/** The JWKS cache TTL and the unknown-`kid` refetch cooldown, owned by the verifier both planes share. */
|
|
39
46
|
export { JWKS_REFETCH_COOLDOWN_SECONDS, JWKS_TTL_SECONDS } from '@fabrika/jwks';
|
|
40
47
|
/** Default IAM request timeout. A hung IAM must deny, not hang every request behind it. */
|
package/types/src/handoff.d.ts
CHANGED
|
@@ -5,6 +5,11 @@ export interface HandoffAttempt {
|
|
|
5
5
|
}
|
|
6
6
|
/** Create the browser-held verifier and the public values IAM carries through the login. */
|
|
7
7
|
export declare function createHandoffAttempt(): Promise<HandoffAttempt>;
|
|
8
|
+
/**
|
|
9
|
+
* A verifier made for no challenge. IAM consumes a code before it compares the verifier, so redeeming a code with this
|
|
10
|
+
* one only spends the code.
|
|
11
|
+
*/
|
|
12
|
+
export declare function unmatchedVerifier(): string;
|
|
8
13
|
/** S256, matching PKCE: the verifier never rides in a URL or reaches IAM through the browser. */
|
|
9
14
|
export declare function handoffChallenge(verifier: string): Promise<string>;
|
|
10
15
|
/** Return the dynamic `__Host-` cookie name for a validated public state. */
|
package/types/src/headers.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { CspExtensions, EndpointCache } from '@fabrika/auth-core';
|
|
1
|
+
import type { CspExtensions, EndpointCache, EndpointResponse } from '@fabrika/auth-core';
|
|
2
2
|
/** Every powerful feature off. ADR-0022 lists the same names; change both together. */
|
|
3
3
|
export declare const PERMISSIONS_POLICY_FEATURES: readonly string[];
|
|
4
4
|
export type HeaderPolicy = readonly (readonly [name: string, value: string])[];
|
|
@@ -59,6 +59,17 @@ export declare function appHeaderPolicy(app: {
|
|
|
59
59
|
export declare const BASE_HEADER_POLICY: HeaderPolicy;
|
|
60
60
|
/** Raster formats a browser only ever renders as an image; every other download, SVG and HTML included, is an attachment. */
|
|
61
61
|
export declare const INLINE_FILE_TYPES: readonly string[];
|
|
62
|
+
/**
|
|
63
|
+
* XML a machine reads (a feed, a sitemap, an import file), shown inline only on a row of an `inline: true` kind
|
|
64
|
+
* (`response: 'inline-file'`). `FILE_TREATMENT`'s sandbox runs none of its script and loads nothing; XHTML and SVG
|
|
65
|
+
* are not among them.
|
|
66
|
+
*/
|
|
67
|
+
export declare const INLINE_DOCUMENT_TYPES: readonly string[];
|
|
68
|
+
/**
|
|
69
|
+
* The types a row's answer is shown inline as: the inert images, and the XML documents only on an `inline-file` row.
|
|
70
|
+
* One constant per profile, so a composition can group its rows by it.
|
|
71
|
+
*/
|
|
72
|
+
export declare function inlineFileTypes(response: EndpointResponse | undefined): readonly string[];
|
|
62
73
|
/** What every answer of a download endpoint carries in place of the policy, its errors included. */
|
|
63
74
|
export declare const FILE_TREATMENT: HeaderPolicy;
|
|
64
75
|
/** The file treatment of a manifest entry's downloads, its transport header included. */
|
|
@@ -91,14 +102,15 @@ export declare function preflightHeaders(allowOrigin: string, method: string): H
|
|
|
91
102
|
/** `crossOriginHeaders` over headers that already carry the answer's own policy; `Vary` is added to, never replaced. */
|
|
92
103
|
export declare function applyCrossOriginHeaders(headers: Headers, policy: HeaderPolicy): void;
|
|
93
104
|
/** `null` and anything but one allowlisted value is an attachment; `Headers` joins repeated fields with `, `, so two never match. */
|
|
94
|
-
export declare function fileDisposition(contentType: string | null): 'inline' | 'attachment';
|
|
105
|
+
export declare function fileDisposition(contentType: string | null, inline?: readonly string[]): 'inline' | 'attachment';
|
|
95
106
|
/** Whatever the handler or an asset server set for these names is replaced; the removed and transport headers are dropped first. */
|
|
96
107
|
export declare function applyHeaderPolicy(headers: Headers, policy: HeaderPolicy): void;
|
|
97
108
|
/**
|
|
98
109
|
* The file treatment over headers a download already carries: the disposition type follows the `Content-Type`
|
|
99
|
-
* exactly, and the parameters after it (the file name) are kept. The proxy passes `appFileTreatment` of its entry
|
|
110
|
+
* exactly, and the parameters after it (the file name) are kept. The proxy passes `appFileTreatment` of its entry, and
|
|
111
|
+
* `inlineFileTypes` of the row.
|
|
100
112
|
*/
|
|
101
|
-
export declare function applyFileTreatment(headers: Headers, treatment?: HeaderPolicy): void;
|
|
113
|
+
export declare function applyFileTreatment(headers: Headers, treatment?: HeaderPolicy, inline?: readonly string[]): void;
|
|
102
114
|
/**
|
|
103
115
|
* A cacheable row's successful answer (`http.cache`): its `Cache-Control` replaces the `no-store` of the policy or the
|
|
104
116
|
* file treatment. Every other answer, an error or a redirect included, keeps `no-store`.
|
package/types/src/index.d.ts
CHANGED
|
@@ -2,7 +2,7 @@ export { Authorizer } from './authorize';
|
|
|
2
2
|
export type { AuthorizerOptions, Decision, DenyReason, ForwardedRequest, ResolvedApp } from './authorize';
|
|
3
3
|
export { cacheKey, MemoryTokenCache } from './cache';
|
|
4
4
|
export type { CachedToken, TokenCache } from './cache';
|
|
5
|
-
export { APP_QUERY_PARAM, CLIENT_ADDRESS_HEADER, DEFAULT_HEALTH_PATH, DEFAULT_IAM_TIMEOUT_MS, DEFAULT_VERIFY_PATH, DELEGATION_HEADER, ENDPOINT_HEADER, FORWARD_AUTHORIZATION_HEADER, FORWARDED_HOST_HEADER, FORWARDED_METHOD_HEADER, FORWARDED_PROTO_HEADER, FORWARDED_URI_HEADER, JWKS_TTL_SECONDS, LOGIN_REDIRECT_PARAM, PREFLIGHT_HEADER, PROXY_TOKEN_HEADER, REQUEST_ID_HEADER, UNTRUSTED_FORWARD_HEADERS, } from './constants';
|
|
5
|
+
export { APP_QUERY_PARAM, AUTH_SIGNOUT_PATH, CLIENT_ADDRESS_HEADER, DEFAULT_HEALTH_PATH, DEFAULT_IAM_TIMEOUT_MS, DEFAULT_VERIFY_PATH, DELEGATION_HEADER, ENDPOINT_HEADER, FORWARD_AUTHORIZATION_HEADER, FORWARDED_HOST_HEADER, FORWARDED_METHOD_HEADER, FORWARDED_PROTO_HEADER, FORWARDED_URI_HEADER, JWKS_TTL_SECONDS, LOGIN_REDIRECT_PARAM, PREFLIGHT_HEADER, PROXY_TOKEN_HEADER, REQUEST_ID_HEADER, SIGNOUT_RELEASE_PATH, UNTRUSTED_FORWARD_HEADERS, } from './constants';
|
|
6
6
|
export { carriesPlatformKey, readBearer, readCookie } from './credentials';
|
|
7
7
|
export { stripFabrikaCookies } from './handoff';
|
|
8
8
|
export { HttpIamGateway, IamUnavailableError } from './iam';
|
|
@@ -10,6 +10,8 @@ export type { DelegationIssuer, DelegationRequest, HttpIamGatewayOptions, IamGat
|
|
|
10
10
|
export { consoleLogger, redactPath, redactUrl, silentLogger } from './log';
|
|
11
11
|
export type { LogFields, LogValue, ProxyLogger } from './log';
|
|
12
12
|
export { findOAuthMetadata, OAUTH_METADATA_VERIFY_PATH, oauthMetadataResponse } from './oauth';
|
|
13
|
+
export { errorAnswer, errorPage, FETCH_MODE_HEADER, isPageNavigation, PAGE_CONTENT_TYPE, pageResponse, renderPage } from './pages';
|
|
14
|
+
export type { ErrorPageStatus, PageAction, PageContent } from './pages';
|
|
13
15
|
export { createVerifyService } from './service';
|
|
14
16
|
export type { VerifyService, VerifyServiceConfig } from './service';
|
|
15
17
|
export { TokenVerifier } from './verifier';
|