@fabrika/auth-core 0.9.0-dev.11 → 0.9.0-dev.12
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 +2 -2
- package/src/canonical-path.ts +18 -0
- package/src/client-address.ts +74 -0
- package/src/contract.ts +41 -7
- package/src/egress.ts +97 -0
- package/src/index.ts +2 -0
- package/src/wire.ts +2 -1
- package/types/src/canonical-path.d.ts +6 -0
- package/types/src/client-address.d.ts +7 -0
- package/types/src/contract.d.ts +19 -6
- package/types/src/egress.d.ts +27 -0
- package/types/src/index.d.ts +2 -0
- package/types/src/wire.d.ts +2 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fabrika/auth-core",
|
|
3
|
-
"version": "0.9.0-dev.
|
|
3
|
+
"version": "0.9.0-dev.12",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
}
|
|
24
24
|
},
|
|
25
25
|
"scripts": {
|
|
26
|
-
"typecheck": "
|
|
26
|
+
"typecheck": "tsrs --build tsconfig.test.json",
|
|
27
27
|
"test": "bun test"
|
|
28
28
|
}
|
|
29
29
|
}
|
package/src/canonical-path.ts
CHANGED
|
@@ -50,6 +50,24 @@ export function rawRequestTarget(url: string): RequestTarget {
|
|
|
50
50
|
return target.pathname === '' ? { pathname: '/', search: target.search } : target
|
|
51
51
|
}
|
|
52
52
|
|
|
53
|
+
/**
|
|
54
|
+
* The absolute URL of `path` on `origin`, or `null` when `path` is not a path of that origin: the one rule for a
|
|
55
|
+
* redirect or return target that must stay on its own origin. A leading `//` or any `\` would make a browser read a
|
|
56
|
+
* host from it, and a browser strips a tab or newline before parsing, so no control character is admitted.
|
|
57
|
+
*/
|
|
58
|
+
export function sameOriginTarget(origin: string, path: string): string | null {
|
|
59
|
+
if (!path.startsWith('/') || path.startsWith('//') || path.includes('\\') || [...path].some(isControl)) {
|
|
60
|
+
return null
|
|
61
|
+
}
|
|
62
|
+
const target = new URL(path, origin)
|
|
63
|
+
return target.origin === origin ? target.toString() : null
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
function isControl(character: string): boolean {
|
|
67
|
+
const code = character.charCodeAt(0)
|
|
68
|
+
return code < 0x20 || code === 0x7f
|
|
69
|
+
}
|
|
70
|
+
|
|
53
71
|
/** A segment one reader decodes and another refuses would route differently, so a malformed escape is refused. */
|
|
54
72
|
function isDecodable(segment: string): boolean {
|
|
55
73
|
try {
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
// The client a per-client abuse bucket counts, derived from the address an ingress wrote. IAM and the application
|
|
2
|
+
// runtime both key on it, so one client is one bucket on either side.
|
|
3
|
+
|
|
4
|
+
/** Longest header value read; an IPv6 address with a zone id fits with room to spare. */
|
|
5
|
+
const MAX_ADDRESS_LENGTH = 64
|
|
6
|
+
|
|
7
|
+
const IPV4 = /^(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)(?:\.(25[0-5]|2[0-4]\d|1\d\d|[1-9]?\d)){3}$/
|
|
8
|
+
const HEXTET = /^[0-9a-f]{1,4}$/
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* The eight groups of an IPv6 address, or `null`. An embedded IPv4 tail (`::ffff:192.0.2.1`) counts as two groups,
|
|
12
|
+
* and a zone id (`%eth0`) is dropped.
|
|
13
|
+
*/
|
|
14
|
+
function ipv6Groups(text: string): number[] | null {
|
|
15
|
+
const address = text.split('%')[0] ?? ''
|
|
16
|
+
const halves = address.split('::')
|
|
17
|
+
if (halves.length > 2) {
|
|
18
|
+
return null
|
|
19
|
+
}
|
|
20
|
+
const groupsOf = (half: string): number[] | null => {
|
|
21
|
+
if (half === '') {
|
|
22
|
+
return []
|
|
23
|
+
}
|
|
24
|
+
const groups: number[] = []
|
|
25
|
+
const parts = half.split(':')
|
|
26
|
+
for (const [index, part] of parts.entries()) {
|
|
27
|
+
if (index === parts.length - 1 && IPV4.test(part)) {
|
|
28
|
+
const [a = 0, b = 0, c = 0, d = 0] = part.split('.').map(Number)
|
|
29
|
+
groups.push(a * 256 + b, c * 256 + d)
|
|
30
|
+
} else if (HEXTET.test(part)) {
|
|
31
|
+
groups.push(Number.parseInt(part, 16))
|
|
32
|
+
} else {
|
|
33
|
+
return null
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
return groups
|
|
37
|
+
}
|
|
38
|
+
const head = groupsOf(halves[0] ?? '')
|
|
39
|
+
const tail = halves.length === 2 ? groupsOf(halves[1] ?? '') : []
|
|
40
|
+
if (head === null || tail === null) {
|
|
41
|
+
return null
|
|
42
|
+
}
|
|
43
|
+
if (halves.length === 1) {
|
|
44
|
+
return head.length === 8 ? head : null
|
|
45
|
+
}
|
|
46
|
+
const missing = 8 - head.length - tail.length
|
|
47
|
+
return missing < 1 ? null : [...head, ...Array.from({ length: missing }, () => 0), ...tail]
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* The client a client-address header value counts as: an IPv4 address, or an IPv6 address's /64 (one subscriber's
|
|
52
|
+
* prefix, of which it may hold every address); an IPv4-mapped IPv6 address counts as its IPv4 address. Only the first
|
|
53
|
+
* value counts, so a caller that appends a second copy cannot change the key. `null` when the value is absent or no
|
|
54
|
+
* IP address.
|
|
55
|
+
*/
|
|
56
|
+
export function clientAddressKey(header: string | null): string | null {
|
|
57
|
+
const value = (header ?? '').split(',')[0]?.trim().toLowerCase() ?? ''
|
|
58
|
+
if (value === '' || value.length > MAX_ADDRESS_LENGTH) {
|
|
59
|
+
return null
|
|
60
|
+
}
|
|
61
|
+
if (IPV4.test(value)) {
|
|
62
|
+
return value
|
|
63
|
+
}
|
|
64
|
+
const groups = ipv6Groups(value.startsWith('[') && value.endsWith(']') ? value.slice(1, -1) : value)
|
|
65
|
+
if (groups === null) {
|
|
66
|
+
return null
|
|
67
|
+
}
|
|
68
|
+
const mapped = groups.slice(0, 5).every((group) => group === 0) && groups[5] === 0xffff
|
|
69
|
+
if (mapped) {
|
|
70
|
+
const [high = 0, low = 0] = groups.slice(6)
|
|
71
|
+
return [high >> 8, high & 0xff, low >> 8, low & 0xff].join('.')
|
|
72
|
+
}
|
|
73
|
+
return `${groups.slice(0, 4).map((group) => group.toString(16)).join(':')}::/64`
|
|
74
|
+
}
|
package/src/contract.ts
CHANGED
|
@@ -27,7 +27,7 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
27
27
|
readonly mounts: Readonly<Record<string, MountArtifact>>
|
|
28
28
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>
|
|
29
29
|
/**
|
|
30
|
-
* The file kinds (`c.files({ types, maxBytes, scan? })`): classes of stored files a table's file column holds. A kind
|
|
30
|
+
* The file kinds (`c.files({ types, maxBytes, scan?, inline? })`): classes of stored files a table's file column holds. A kind
|
|
31
31
|
* has no owner and no endpoint; the table that holds a file is its authority. Absent unless declared, so the digest stays.
|
|
32
32
|
*/
|
|
33
33
|
readonly fileKinds?: Readonly<Record<string, FileKindArtifact>>
|
|
@@ -189,7 +189,8 @@ interface EndpointRowBase {
|
|
|
189
189
|
readonly crossOrigin?: CrossOriginForm
|
|
190
190
|
/**
|
|
191
191
|
* `file`: the procedure answers a stored file (an output `file('<kind>')`), so the proxy and the application give every
|
|
192
|
-
* answer of it, a denial included, ADR-0022's file treatment.
|
|
192
|
+
* answer of it, a denial included, ADR-0022's file treatment. `inline-file`: the same, for a kind declared `inline:
|
|
193
|
+
* true`, whose XML documents are shown too. Absent otherwise, so every other row keeps its digest.
|
|
193
194
|
*/
|
|
194
195
|
readonly response?: EndpointResponse
|
|
195
196
|
/**
|
|
@@ -209,8 +210,8 @@ interface EndpointRowBase {
|
|
|
209
210
|
/** What the proxy does with an anonymous request's `Authorization` on a row that names it: forward it to the application. */
|
|
210
211
|
export type EndpointAuthorization = 'forward'
|
|
211
212
|
|
|
212
|
-
/** The answer profile of a row that answers a stored file. */
|
|
213
|
-
export type EndpointResponse = 'file'
|
|
213
|
+
/** The answer profile of a row that answers a stored file: `inline-file` also shows the XML documents a machine reads. */
|
|
214
|
+
export type EndpointResponse = 'file' | 'inline-file'
|
|
214
215
|
|
|
215
216
|
/** A cacheable row's lifetime: `maxAgeSeconds`, or `immutable`, a year, for an input that names an immutable value. */
|
|
216
217
|
export type EndpointCache = { readonly maxAgeSeconds: number } | 'immutable'
|
|
@@ -223,7 +224,7 @@ export const FILE_RESPONSE_KINDS: readonly EndpointKind[] = ['query', 'mutation'
|
|
|
223
224
|
|
|
224
225
|
/** Whether every answer of a row gets the file treatment: a collection's download, or a procedure that answers a file. */
|
|
225
226
|
export function answersFile(row: { readonly kind: string; readonly response?: EndpointResponse }): boolean {
|
|
226
|
-
return row.kind === 'download' || row.response
|
|
227
|
+
return row.kind === 'download' || row.response !== undefined
|
|
227
228
|
}
|
|
228
229
|
|
|
229
230
|
/** How an endpoint admits another origin: from the environment's list, or (a form or a public procedure) from any origin. */
|
|
@@ -343,6 +344,29 @@ export function isFileShape(shape: OutputShape): shape is FileShape {
|
|
|
343
344
|
return shape.type === 'file'
|
|
344
345
|
}
|
|
345
346
|
|
|
347
|
+
/** The kinds of the files a schema holds, anywhere in it, each once per place it appears. */
|
|
348
|
+
export function fileKindsIn(shape: SchemaShape): readonly string[] {
|
|
349
|
+
switch (shape.type) {
|
|
350
|
+
case 'file':
|
|
351
|
+
return [shape.kind]
|
|
352
|
+
case 'array':
|
|
353
|
+
return fileKindsIn(shape.items)
|
|
354
|
+
case 'tuple':
|
|
355
|
+
return [...shape.items.flatMap(fileKindsIn), ...(shape.rest === null ? [] : fileKindsIn(shape.rest))]
|
|
356
|
+
case 'record':
|
|
357
|
+
return fileKindsIn(shape.value)
|
|
358
|
+
case 'object':
|
|
359
|
+
return Object.values(shape.fields).flatMap(fileKindsIn)
|
|
360
|
+
case 'optional':
|
|
361
|
+
case 'nullable':
|
|
362
|
+
return fileKindsIn(shape.inner)
|
|
363
|
+
case 'union':
|
|
364
|
+
return shape.options.flatMap(fileKindsIn)
|
|
365
|
+
default:
|
|
366
|
+
return []
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
346
370
|
/**
|
|
347
371
|
* What a procedure answers: a JSON value of a schema, a file of rows (`attachment()` of `@fabrika/app/contract`), or a
|
|
348
372
|
* redirect (`redirect()`).
|
|
@@ -674,6 +698,11 @@ export interface FileKindArtifact {
|
|
|
674
698
|
readonly maxBytes: number
|
|
675
699
|
/** Present when every file of the kind waits `quarantined` for a clean malware verdict before it is served. */
|
|
676
700
|
readonly scan?: true
|
|
701
|
+
/**
|
|
702
|
+
* Present when its files are shown rather than downloaded: every type is an inert image or an XML document a machine
|
|
703
|
+
* reads, and a row answering it is `response: 'inline-file'`. Absent otherwise, so every other kind keeps its digest.
|
|
704
|
+
*/
|
|
705
|
+
readonly inline?: true
|
|
677
706
|
}
|
|
678
707
|
|
|
679
708
|
export interface JobArtifact {
|
|
@@ -754,8 +783,8 @@ export interface DeclaredReach {
|
|
|
754
783
|
*/
|
|
755
784
|
readonly signs?: readonly string[]
|
|
756
785
|
/**
|
|
757
|
-
* The HTTPS origins this site's code calls (`fetch`), sorted
|
|
758
|
-
* unless declared, so the digest stays.
|
|
786
|
+
* The HTTPS origins this site's code calls (`fetch`), sorted, each an exact origin or a one-label pattern
|
|
787
|
+
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job. Absent unless declared, so the digest stays.
|
|
759
788
|
*/
|
|
760
789
|
readonly egress?: readonly string[]
|
|
761
790
|
/**
|
|
@@ -832,6 +861,11 @@ export interface TablePolicyArtifact {
|
|
|
832
861
|
* actions are the file's authority. Absent unless declared, so the digest stays.
|
|
833
862
|
*/
|
|
834
863
|
readonly files?: Readonly<Record<string, string>>
|
|
864
|
+
/**
|
|
865
|
+
* A view (ADR-0072): read like its scope's tables, written by nothing, its containment stated by its SQL alone.
|
|
866
|
+
* Absent for a table, so the digest stays.
|
|
867
|
+
*/
|
|
868
|
+
readonly view?: true
|
|
835
869
|
}
|
|
836
870
|
|
|
837
871
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
package/src/egress.ts
ADDED
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
// What a site's `egress` entry is, and which request URL it admits: the one rule the contract build, the artifact parser,
|
|
2
|
+
// the runtime guard on `fetch`, the checker and the approval diff share (ADR-0012 §15). An entry is an exact `https`
|
|
3
|
+
// origin or a pattern `https://*.<domain>[:port]` whose `*` stands for exactly one DNS label.
|
|
4
|
+
|
|
5
|
+
/** One parsed `egress` entry. `port` is `''` for the default port, as `URL.port` spells it. */
|
|
6
|
+
export type EgressEntry =
|
|
7
|
+
| { readonly kind: 'origin'; readonly origin: string; readonly host: string; readonly port: string }
|
|
8
|
+
| { readonly kind: 'pattern'; readonly pattern: string; readonly domain: string; readonly port: string }
|
|
9
|
+
|
|
10
|
+
export type EgressEntryParse = { readonly ok: true; readonly entry: EgressEntry } | { readonly ok: false; readonly problem: string }
|
|
11
|
+
|
|
12
|
+
/** What every pattern starts with: the scheme and the one wildcard label. */
|
|
13
|
+
const EGRESS_WILDCARD_PREFIX = 'https://*.'
|
|
14
|
+
|
|
15
|
+
const HOSTNAME = /^(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)*[a-z0-9](?:[a-z0-9-]*[a-z0-9])?$/
|
|
16
|
+
const NUMERIC_LABEL = /^[0-9]+$/
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* `value` as an `egress` entry, or why it is none. Each entry is written canonically (lower case, punycode, no default
|
|
20
|
+
* port, no trailing dot, no path), so an artifact names one entry one way; a problem names the canonical spelling when
|
|
21
|
+
* there is one.
|
|
22
|
+
*/
|
|
23
|
+
export function parseEgressEntry(value: string): EgressEntryParse {
|
|
24
|
+
return value.startsWith(EGRESS_WILDCARD_PREFIX) ? parsePattern(value) : parseOrigin(value)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
function parseOrigin(value: string): EgressEntryParse {
|
|
28
|
+
const url = urlOf(value)
|
|
29
|
+
if (url === null || url.protocol !== 'https:') return refused('is not an https origin')
|
|
30
|
+
if (url.hostname.endsWith('.')) return refused(canonicalProblem(url, `https://${url.host.replace(/\.(?=:|$)/, '')}`))
|
|
31
|
+
if (!HOSTNAME.test(url.hostname)) {
|
|
32
|
+
return refused(url.hostname.includes('*') ? 'puts a wildcard elsewhere than one leading label' : 'is not an https origin with a literal host')
|
|
33
|
+
}
|
|
34
|
+
if (url.origin !== value) return refused(canonicalProblem(url, url.origin))
|
|
35
|
+
return { ok: true, entry: { kind: 'origin', origin: value, host: url.hostname, port: url.port } }
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
function parsePattern(value: string): EgressEntryParse {
|
|
39
|
+
const rest = value.slice(EGRESS_WILDCARD_PREFIX.length)
|
|
40
|
+
const url = urlOf(`https://${rest}`)
|
|
41
|
+
if (url === null) return refused('is not an https origin pattern')
|
|
42
|
+
if (url.hostname.includes('*')) return refused('has more than one wildcard label (allowed: one leading *.)')
|
|
43
|
+
if (url.hostname.endsWith('.')) return refused(canonicalProblem(url, `${EGRESS_WILDCARD_PREFIX}${url.host.replace(/\.(?=:|$)/, '')}`))
|
|
44
|
+
if (!HOSTNAME.test(url.hostname)) return refused('is not an https origin pattern with a literal domain')
|
|
45
|
+
const labels = url.hostname.split('.')
|
|
46
|
+
if (NUMERIC_LABEL.test(labels.at(-1) ?? '')) return refused('puts its wildcard on an IP address (allowed: a domain name)')
|
|
47
|
+
if (isPublicSuffix(labels)) {
|
|
48
|
+
return refused(`puts its wildcard on the public suffix '${url.hostname}' (allowed: a domain of your own, as in 'https://*.example.com')`)
|
|
49
|
+
}
|
|
50
|
+
if (url.origin !== `https://${rest}`) return refused(canonicalProblem(url, `${EGRESS_WILDCARD_PREFIX}${url.host}`))
|
|
51
|
+
return { ok: true, entry: { kind: 'pattern', pattern: value, domain: url.hostname, port: url.port } }
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* Whether `labels` name a public suffix by this rule, which stands in for the public suffix list (the platform ships no
|
|
56
|
+
* copy of it): one label (`com`), or two labels under a two-letter country code whose first has at
|
|
57
|
+
* most three characters (`co.uk`, `com.au`, `ne.jp`). A suffix this rule cannot tell, such as a longer second-level
|
|
58
|
+
* label or a shared hosting domain, is the approver's to judge: the diff shows every pattern as a wider grant.
|
|
59
|
+
*/
|
|
60
|
+
function isPublicSuffix(labels: readonly string[]): boolean {
|
|
61
|
+
if (labels.length < 2) return true
|
|
62
|
+
const top = labels.at(-1) ?? ''
|
|
63
|
+
const second = labels.at(-2) ?? ''
|
|
64
|
+
return labels.length === 2 && /^[a-z]{2}$/.test(top) && second.length <= 3
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Whether `url` is a request an entry of `entries` admits: its host and port, a trailing dot of the host aside. */
|
|
68
|
+
export function egressAdmits(entries: readonly EgressEntry[], url: URL): boolean {
|
|
69
|
+
if (url.protocol !== 'https:') return false
|
|
70
|
+
const host = url.hostname.endsWith('.') ? url.hostname.slice(0, -1) : url.hostname
|
|
71
|
+
return entries.some((entry) => entry.port === url.port && (entry.kind === 'origin' ? entry.host === host : isOneLabelUnder(host, entry.domain)))
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/** `host` is exactly one non-empty label followed by `.<domain>`, so `evil-example.com` is not under `example.com`. */
|
|
75
|
+
function isOneLabelUnder(host: string, domain: string): boolean {
|
|
76
|
+
const suffix = `.${domain}`
|
|
77
|
+
if (!host.endsWith(suffix)) return false
|
|
78
|
+
const label = host.slice(0, -suffix.length)
|
|
79
|
+
return label.length > 0 && !label.includes('.')
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
function canonicalProblem(url: URL, canonical: string): string {
|
|
83
|
+
const bare = url.pathname === '/' && url.search === '' && url.hash === '' && url.username === '' && url.password === ''
|
|
84
|
+
return bare ? `is not written canonically (write it as '${canonical}')` : 'carries a path, query or credentials (allowed: an origin only)'
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
function refused(problem: string): EgressEntryParse {
|
|
88
|
+
return { ok: false, problem }
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function urlOf(value: string): URL | null {
|
|
92
|
+
try {
|
|
93
|
+
return new URL(value)
|
|
94
|
+
} catch {
|
|
95
|
+
return null
|
|
96
|
+
}
|
|
97
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
// @fabrika/auth-core — pure logic, types, and wire names shared across auth components and apps.
|
|
2
2
|
export * from './app-environment'
|
|
3
3
|
export * from './canonical-path'
|
|
4
|
+
export * from './client-address'
|
|
4
5
|
export * from './contract'
|
|
5
6
|
export * from './contract-canonical'
|
|
6
7
|
export * from './dev-environment'
|
|
7
8
|
export * from './device'
|
|
9
|
+
export * from './egress'
|
|
8
10
|
export * from './endpoint-digest'
|
|
9
11
|
export * from './endpoints'
|
|
10
12
|
export * from './environment'
|
package/src/wire.ts
CHANGED
|
@@ -65,7 +65,8 @@ export function proxySecretVariable(id: string): string {
|
|
|
65
65
|
|
|
66
66
|
/**
|
|
67
67
|
* The variable holding the secret the platform proxy sends IAM's installation entry in `PROXY_SECRET_HEADER`. The proxy
|
|
68
|
-
* and IAM hold it under this one name. It proves only who wrote IAM's
|
|
68
|
+
* and IAM hold it under this one name. It proves only who wrote IAM's request-id header; IAM keys every request without
|
|
69
|
+
* it on one shared client bucket.
|
|
69
70
|
*/
|
|
70
71
|
export const IAM_PROXY_SECRET_VARIABLE = 'FABRIKA_INSTALLATION_PROXY_SECRET_IAM'
|
|
71
72
|
|
|
@@ -18,3 +18,9 @@ export declare function splitRequestTarget(target: string): RequestTarget;
|
|
|
18
18
|
* the string because `new URL()` resolves dot segments and so hides the very paths that must be refused.
|
|
19
19
|
*/
|
|
20
20
|
export declare function rawRequestTarget(url: string): RequestTarget;
|
|
21
|
+
/**
|
|
22
|
+
* The absolute URL of `path` on `origin`, or `null` when `path` is not a path of that origin: the one rule for a
|
|
23
|
+
* redirect or return target that must stay on its own origin. A leading `//` or any `\` would make a browser read a
|
|
24
|
+
* host from it, and a browser strips a tab or newline before parsing, so no control character is admitted.
|
|
25
|
+
*/
|
|
26
|
+
export declare function sameOriginTarget(origin: string, path: string): string | null;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The client a client-address header value counts as: an IPv4 address, or an IPv6 address's /64 (one subscriber's
|
|
3
|
+
* prefix, of which it may hold every address); an IPv4-mapped IPv6 address counts as its IPv4 address. Only the first
|
|
4
|
+
* value counts, so a caller that appends a second copy cannot change the key. `null` when the value is absent or no
|
|
5
|
+
* IP address.
|
|
6
|
+
*/
|
|
7
|
+
export declare function clientAddressKey(header: string | null): string | null;
|
package/types/src/contract.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ export interface ContractArtifact extends EndpointTable {
|
|
|
22
22
|
readonly mounts: Readonly<Record<string, MountArtifact>>;
|
|
23
23
|
readonly files: Readonly<Record<string, FileCollectionArtifact>>;
|
|
24
24
|
/**
|
|
25
|
-
* The file kinds (`c.files({ types, maxBytes, scan? })`): classes of stored files a table's file column holds. A kind
|
|
25
|
+
* The file kinds (`c.files({ types, maxBytes, scan?, inline? })`): classes of stored files a table's file column holds. A kind
|
|
26
26
|
* has no owner and no endpoint; the table that holds a file is its authority. Absent unless declared, so the digest stays.
|
|
27
27
|
*/
|
|
28
28
|
readonly fileKinds?: Readonly<Record<string, FileKindArtifact>>;
|
|
@@ -174,7 +174,8 @@ interface EndpointRowBase {
|
|
|
174
174
|
readonly crossOrigin?: CrossOriginForm;
|
|
175
175
|
/**
|
|
176
176
|
* `file`: the procedure answers a stored file (an output `file('<kind>')`), so the proxy and the application give every
|
|
177
|
-
* answer of it, a denial included, ADR-0022's file treatment.
|
|
177
|
+
* answer of it, a denial included, ADR-0022's file treatment. `inline-file`: the same, for a kind declared `inline:
|
|
178
|
+
* true`, whose XML documents are shown too. Absent otherwise, so every other row keeps its digest.
|
|
178
179
|
*/
|
|
179
180
|
readonly response?: EndpointResponse;
|
|
180
181
|
/**
|
|
@@ -192,8 +193,8 @@ interface EndpointRowBase {
|
|
|
192
193
|
}
|
|
193
194
|
/** What the proxy does with an anonymous request's `Authorization` on a row that names it: forward it to the application. */
|
|
194
195
|
export type EndpointAuthorization = 'forward';
|
|
195
|
-
/** The answer profile of a row that answers a stored file. */
|
|
196
|
-
export type EndpointResponse = 'file';
|
|
196
|
+
/** The answer profile of a row that answers a stored file: `inline-file` also shows the XML documents a machine reads. */
|
|
197
|
+
export type EndpointResponse = 'file' | 'inline-file';
|
|
197
198
|
/** A cacheable row's lifetime: `maxAgeSeconds`, or `immutable`, a year, for an input that names an immutable value. */
|
|
198
199
|
export type EndpointCache = {
|
|
199
200
|
readonly maxAgeSeconds: number;
|
|
@@ -332,6 +333,8 @@ export interface FileShape {
|
|
|
332
333
|
readonly kind: string;
|
|
333
334
|
}
|
|
334
335
|
export declare function isFileShape(shape: OutputShape): shape is FileShape;
|
|
336
|
+
/** The kinds of the files a schema holds, anywhere in it, each once per place it appears. */
|
|
337
|
+
export declare function fileKindsIn(shape: SchemaShape): readonly string[];
|
|
335
338
|
/**
|
|
336
339
|
* What a procedure answers: a JSON value of a schema, a file of rows (`attachment()` of `@fabrika/app/contract`), or a
|
|
337
340
|
* redirect (`redirect()`).
|
|
@@ -621,6 +624,11 @@ export interface FileKindArtifact {
|
|
|
621
624
|
readonly maxBytes: number;
|
|
622
625
|
/** Present when every file of the kind waits `quarantined` for a clean malware verdict before it is served. */
|
|
623
626
|
readonly scan?: true;
|
|
627
|
+
/**
|
|
628
|
+
* Present when its files are shown rather than downloaded: every type is an inert image or an XML document a machine
|
|
629
|
+
* reads, and a row answering it is `response: 'inline-file'`. Absent otherwise, so every other kind keeps its digest.
|
|
630
|
+
*/
|
|
631
|
+
readonly inline?: true;
|
|
624
632
|
}
|
|
625
633
|
export interface JobArtifact {
|
|
626
634
|
readonly schedule: string;
|
|
@@ -694,8 +702,8 @@ export interface DeclaredReach {
|
|
|
694
702
|
*/
|
|
695
703
|
readonly signs?: readonly string[];
|
|
696
704
|
/**
|
|
697
|
-
* The HTTPS origins this site's code calls (`fetch`), sorted
|
|
698
|
-
* unless declared, so the digest stays.
|
|
705
|
+
* The HTTPS origins this site's code calls (`fetch`), sorted, each an exact origin or a one-label pattern
|
|
706
|
+
* (`parseEgressEntry`): a credentialed procedure, a webhook or a job. Absent unless declared, so the digest stays.
|
|
699
707
|
*/
|
|
700
708
|
readonly egress?: readonly string[];
|
|
701
709
|
/**
|
|
@@ -764,6 +772,11 @@ export interface TablePolicyArtifact {
|
|
|
764
772
|
* actions are the file's authority. Absent unless declared, so the digest stays.
|
|
765
773
|
*/
|
|
766
774
|
readonly files?: Readonly<Record<string, string>>;
|
|
775
|
+
/**
|
|
776
|
+
* A view (ADR-0072): read like its scope's tables, written by nothing, its containment stated by its SQL alone.
|
|
777
|
+
* Absent for a table, so the digest stays.
|
|
778
|
+
*/
|
|
779
|
+
readonly view?: true;
|
|
767
780
|
}
|
|
768
781
|
/** A column's own read action, its own write action, or both; an absent one is left out. */
|
|
769
782
|
export interface ColumnPolicyArtifact {
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/** One parsed `egress` entry. `port` is `''` for the default port, as `URL.port` spells it. */
|
|
2
|
+
export type EgressEntry = {
|
|
3
|
+
readonly kind: 'origin';
|
|
4
|
+
readonly origin: string;
|
|
5
|
+
readonly host: string;
|
|
6
|
+
readonly port: string;
|
|
7
|
+
} | {
|
|
8
|
+
readonly kind: 'pattern';
|
|
9
|
+
readonly pattern: string;
|
|
10
|
+
readonly domain: string;
|
|
11
|
+
readonly port: string;
|
|
12
|
+
};
|
|
13
|
+
export type EgressEntryParse = {
|
|
14
|
+
readonly ok: true;
|
|
15
|
+
readonly entry: EgressEntry;
|
|
16
|
+
} | {
|
|
17
|
+
readonly ok: false;
|
|
18
|
+
readonly problem: string;
|
|
19
|
+
};
|
|
20
|
+
/**
|
|
21
|
+
* `value` as an `egress` entry, or why it is none. Each entry is written canonically (lower case, punycode, no default
|
|
22
|
+
* port, no trailing dot, no path), so an artifact names one entry one way; a problem names the canonical spelling when
|
|
23
|
+
* there is one.
|
|
24
|
+
*/
|
|
25
|
+
export declare function parseEgressEntry(value: string): EgressEntryParse;
|
|
26
|
+
/** Whether `url` is a request an entry of `entries` admits: its host and port, a trailing dot of the host aside. */
|
|
27
|
+
export declare function egressAdmits(entries: readonly EgressEntry[], url: URL): boolean;
|
package/types/src/index.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
export * from './app-environment';
|
|
2
2
|
export * from './canonical-path';
|
|
3
|
+
export * from './client-address';
|
|
3
4
|
export * from './contract';
|
|
4
5
|
export * from './contract-canonical';
|
|
5
6
|
export * from './dev-environment';
|
|
6
7
|
export * from './device';
|
|
8
|
+
export * from './egress';
|
|
7
9
|
export * from './endpoint-digest';
|
|
8
10
|
export * from './endpoints';
|
|
9
11
|
export * from './environment';
|
package/types/src/wire.d.ts
CHANGED
|
@@ -53,7 +53,8 @@ export declare const FABRIKA_PROXY_SECRET = "FABRIKA_PROXY_SECRET";
|
|
|
53
53
|
export declare function proxySecretVariable(id: string): string;
|
|
54
54
|
/**
|
|
55
55
|
* The variable holding the secret the platform proxy sends IAM's installation entry in `PROXY_SECRET_HEADER`. The proxy
|
|
56
|
-
* and IAM hold it under this one name. It proves only who wrote IAM's
|
|
56
|
+
* and IAM hold it under this one name. It proves only who wrote IAM's request-id header; IAM keys every request without
|
|
57
|
+
* it on one shared client bucket.
|
|
57
58
|
*/
|
|
58
59
|
export declare const IAM_PROXY_SECRET_VARIABLE = "FABRIKA_INSTALLATION_PROXY_SECRET_IAM";
|
|
59
60
|
/**
|