@fabrika/proxy-core 0.9.0-dev.11 → 0.9.0-dev.13
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 +5 -5
- package/src/authorize.ts +3 -18
- package/src/headers.ts +24 -6
- package/src/manifest.ts +2 -2
- package/types/src/headers.d.ts +16 -4
- package/types/src/manifest.d.ts +136 -136
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/proxy-core",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.13",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -43,14 +43,14 @@
|
|
|
43
43
|
}
|
|
44
44
|
},
|
|
45
45
|
"scripts": {
|
|
46
|
-
"typecheck": "
|
|
46
|
+
"typecheck": "tsrs --build tsconfig.test.json",
|
|
47
47
|
"test": "bun test"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
50
|
"zod": "^3.25.76",
|
|
51
|
-
"@fabrika/auth-core": "0.9.0-dev.
|
|
52
|
-
"@fabrika/jwks": "0.9.0-dev.
|
|
51
|
+
"@fabrika/auth-core": "0.9.0-dev.13",
|
|
52
|
+
"@fabrika/jwks": "0.9.0-dev.13",
|
|
53
53
|
"jose": "^5.9.0",
|
|
54
|
-
"@fabrika/platform": "0.9.0-dev.
|
|
54
|
+
"@fabrika/platform": "0.9.0-dev.13"
|
|
55
55
|
}
|
|
56
56
|
}
|
package/src/authorize.ts
CHANGED
|
@@ -30,6 +30,7 @@ import {
|
|
|
30
30
|
FORM_URLENCODED_TYPE,
|
|
31
31
|
formatEndpointHeader,
|
|
32
32
|
planEndpoint,
|
|
33
|
+
sameOriginTarget,
|
|
33
34
|
satisfies,
|
|
34
35
|
SESSION_COOKIE,
|
|
35
36
|
TOKEN_REFRESH_SKEW_SECONDS,
|
|
@@ -625,7 +626,8 @@ export class Authorizer {
|
|
|
625
626
|
return { outcome: 'deny', status: 403, reason: 'cross_site' }
|
|
626
627
|
}
|
|
627
628
|
const app = resolved.app
|
|
628
|
-
const
|
|
629
|
+
const returnTo = request.url.searchParams.get(LOGIN_REDIRECT_PARAM)
|
|
630
|
+
const target = returnTo === null ? null : sameOriginTarget(new URL(`${app.scheme}://${request.url.host}`).origin, returnTo)
|
|
629
631
|
if (target === null) {
|
|
630
632
|
return { outcome: 'deny', status: 400, reason: 'bad_redirect' }
|
|
631
633
|
}
|
|
@@ -688,29 +690,12 @@ function admittedOrigin(app: ProxyApp, row: ManifestEndpointRow, origin: string)
|
|
|
688
690
|
return form === 'environment' && isApplicationEntry(app) && (app.crossOrigins ?? []).includes(origin) ? origin : null
|
|
689
691
|
}
|
|
690
692
|
|
|
691
|
-
/**
|
|
692
|
-
* The absolute URL of `path` on `origin`, or `null` when `path` is not a path on that origin. A leading `//` or any
|
|
693
|
-
* `\` would make the browser read a host from it, and a control character or a space is never part of a return path.
|
|
694
|
-
*/
|
|
695
|
-
function sameOriginTarget(origin: string, path: string | null): string | null {
|
|
696
|
-
if (path === null || !path.startsWith('/') || path.startsWith('//') || path.includes('\\') || [...path].some(isControlOrSpace)) {
|
|
697
|
-
return null
|
|
698
|
-
}
|
|
699
|
-
const target = new URL(path, origin)
|
|
700
|
-
return target.origin === origin ? target.toString() : null
|
|
701
|
-
}
|
|
702
|
-
|
|
703
693
|
/** Whether a redeemed code's return URL is on the host the callback arrived at, and that host is one of the entry's. */
|
|
704
694
|
function returnsToHost(app: ProxyApp, callback: URL, returnUrl: string): boolean {
|
|
705
695
|
const target = URL.canParse(returnUrl) ? new URL(returnUrl) : null
|
|
706
696
|
return target !== null && target.hostname === callback.hostname && app.hosts.includes(target.hostname)
|
|
707
697
|
}
|
|
708
698
|
|
|
709
|
-
function isControlOrSpace(character: string): boolean {
|
|
710
|
-
const code = character.charCodeAt(0)
|
|
711
|
-
return code <= 0x20 || code === 0x7f
|
|
712
|
-
}
|
|
713
|
-
|
|
714
699
|
function invalidKey(): Denial {
|
|
715
700
|
return { outcome: 'deny', status: 401, reason: 'invalid_key' }
|
|
716
701
|
}
|
package/src/headers.ts
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
// "Response headers"). The proxy sets them on every answer, its own denials included; the framework sets the same
|
|
3
3
|
// definition in-process. Exported as `@fabrika/proxy-core/headers`, which imports nothing at runtime.
|
|
4
4
|
|
|
5
|
-
import type { CspExtensions, EndpointCache } from '@fabrika/auth-core'
|
|
5
|
+
import type { CspExtensions, EndpointCache, EndpointResponse } from '@fabrika/auth-core'
|
|
6
6
|
|
|
7
7
|
/** Every powerful feature off. ADR-0022 lists the same names; change both together. */
|
|
8
8
|
export const PERMISSIONS_POLICY_FEATURES: readonly string[] = [
|
|
@@ -169,6 +169,23 @@ export const BASE_HEADER_POLICY: HeaderPolicy = headerPolicy(NO_CSP_ORIGINS, nul
|
|
|
169
169
|
/** Raster formats a browser only ever renders as an image; every other download, SVG and HTML included, is an attachment. */
|
|
170
170
|
export const INLINE_FILE_TYPES: readonly string[] = ['image/png', 'image/jpeg', 'image/gif', 'image/webp']
|
|
171
171
|
|
|
172
|
+
/**
|
|
173
|
+
* XML a machine reads (a feed, a sitemap, an import file), shown inline only on a row of an `inline: true` kind
|
|
174
|
+
* (`response: 'inline-file'`). `FILE_TREATMENT`'s sandbox runs none of its script and loads nothing; XHTML and SVG
|
|
175
|
+
* are not among them.
|
|
176
|
+
*/
|
|
177
|
+
export const INLINE_DOCUMENT_TYPES: readonly string[] = ['application/xml', 'text/xml', 'application/rss+xml', 'application/atom+xml']
|
|
178
|
+
|
|
179
|
+
const INLINE_FILE_AND_DOCUMENT_TYPES: readonly string[] = Object.freeze([...INLINE_FILE_TYPES, ...INLINE_DOCUMENT_TYPES])
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* The types a row's answer is shown inline as: the inert images, and the XML documents only on an `inline-file` row.
|
|
183
|
+
* One constant per profile, so a composition can group its rows by it.
|
|
184
|
+
*/
|
|
185
|
+
export function inlineFileTypes(response: EndpointResponse | undefined): readonly string[] {
|
|
186
|
+
return response === 'inline-file' ? INLINE_FILE_AND_DOCUMENT_TYPES : INLINE_FILE_TYPES
|
|
187
|
+
}
|
|
188
|
+
|
|
172
189
|
/** What every answer of a download endpoint carries in place of the policy, its errors included. */
|
|
173
190
|
export const FILE_TREATMENT: HeaderPolicy = Object.freeze([
|
|
174
191
|
['X-Content-Type-Options', 'nosniff'],
|
|
@@ -244,8 +261,8 @@ export function applyCrossOriginHeaders(headers: Headers, policy: HeaderPolicy):
|
|
|
244
261
|
}
|
|
245
262
|
|
|
246
263
|
/** `null` and anything but one allowlisted value is an attachment; `Headers` joins repeated fields with `, `, so two never match. */
|
|
247
|
-
export function fileDisposition(contentType: string | null): 'inline' | 'attachment' {
|
|
248
|
-
return contentType !== null &&
|
|
264
|
+
export function fileDisposition(contentType: string | null, inline: readonly string[] = INLINE_FILE_TYPES): 'inline' | 'attachment' {
|
|
265
|
+
return contentType !== null && inline.includes(contentType) ? 'inline' : 'attachment'
|
|
249
266
|
}
|
|
250
267
|
|
|
251
268
|
/** Whatever the handler or an asset server set for these names is replaced; the removed and transport headers are dropped first. */
|
|
@@ -260,12 +277,13 @@ export function applyHeaderPolicy(headers: Headers, policy: HeaderPolicy): void
|
|
|
260
277
|
|
|
261
278
|
/**
|
|
262
279
|
* The file treatment over headers a download already carries: the disposition type follows the `Content-Type`
|
|
263
|
-
* exactly, and the parameters after it (the file name) are kept. The proxy passes `appFileTreatment` of its entry
|
|
280
|
+
* exactly, and the parameters after it (the file name) are kept. The proxy passes `appFileTreatment` of its entry, and
|
|
281
|
+
* `inlineFileTypes` of the row.
|
|
264
282
|
*/
|
|
265
|
-
export function applyFileTreatment(headers: Headers, treatment: HeaderPolicy = FILE_TREATMENT): void {
|
|
283
|
+
export function applyFileTreatment(headers: Headers, treatment: HeaderPolicy = FILE_TREATMENT, inline: readonly string[] = INLINE_FILE_TYPES): void {
|
|
266
284
|
applyHeaderPolicy(headers, treatment)
|
|
267
285
|
const parameters = headers.get('Content-Disposition')?.replace(/^[^;]*/, '') ?? ''
|
|
268
|
-
headers.set('Content-Disposition', `${fileDisposition(headers.get('Content-Type'))}${parameters}`)
|
|
286
|
+
headers.set('Content-Disposition', `${fileDisposition(headers.get('Content-Type'), inline)}${parameters}`)
|
|
269
287
|
}
|
|
270
288
|
|
|
271
289
|
/**
|
package/src/manifest.ts
CHANGED
|
@@ -301,7 +301,7 @@ export const proxyEndpointRowSchema = z.union([
|
|
|
301
301
|
requirement: requirementSchema,
|
|
302
302
|
delegation: z.enum(['members', 'creates']).nullable(),
|
|
303
303
|
crossOrigin: z.literal('environment').optional(),
|
|
304
|
-
response: z.
|
|
304
|
+
response: z.enum(['file', 'inline-file']).optional(),
|
|
305
305
|
}).strict(),
|
|
306
306
|
z.object({
|
|
307
307
|
...endpointRuleFields,
|
|
@@ -310,7 +310,7 @@ export const proxyEndpointRowSchema = z.union([
|
|
|
310
310
|
requirement: z.null(),
|
|
311
311
|
delegation: z.null(),
|
|
312
312
|
crossOrigin: z.enum(['environment', 'any']).optional(),
|
|
313
|
-
response: z.
|
|
313
|
+
response: z.enum(['file', 'inline-file']).optional(),
|
|
314
314
|
cache: z.union([z.literal('immutable'), z.object({ maxAgeSeconds: z.number().int().min(1).max(MAX_CACHE_AGE_SECONDS) }).strict()]).optional(),
|
|
315
315
|
authorization: z.literal('forward').optional(),
|
|
316
316
|
}).strict(),
|
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`.
|