@coffre/core 0.10.2 → 0.11.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/{access-CF4noOjL.d.ts → access-CU3xEOLH.d.ts} +96 -3
- package/dist/{access-Dl13x6mB.js → access-CembYDiI.js} +121 -7
- package/dist/access.d.ts +2 -2
- package/dist/access.js +2 -2
- package/dist/dotenv.js +1 -1
- package/dist/identity.d.ts +148 -13
- package/dist/identity.js +347 -19
- package/dist/kek.js +1 -1
- package/dist/schemas.js +1 -1
- package/dist/vault.d.ts +37 -7
- package/dist/workloads-CP54Q72p.d.ts +418 -0
- package/dist/workloads.d.ts +2 -206
- package/dist/workloads.js +395 -10
- package/package.json +4 -3
- package/src/access.ts +149 -9
- package/src/dotenv.ts +1 -1
- package/src/identity/constraints.ts +168 -0
- package/src/identity/dpop.ts +234 -0
- package/src/identity/index.ts +2 -0
- package/src/identity/signin/config.ts +33 -2
- package/src/identity/signin/sealed.ts +5 -2
- package/src/identity/tokens.ts +17 -7
- package/src/identity/verifier.ts +2 -2
- package/src/identity/workload-token.ts +12 -9
- package/src/identity/workloads.ts +523 -13
- package/src/kek/local.ts +4 -2
- package/src/vault.ts +38 -7
package/src/access.ts
CHANGED
|
@@ -132,7 +132,12 @@ export function assignableToEnvironment(role: Role, policy: Policy = DEFAULT_POL
|
|
|
132
132
|
|
|
133
133
|
/** A project role's definition in `policy`, or undefined for none. */
|
|
134
134
|
export function definitionOf(policy: Policy, role: Role): RoleDefinition | undefined {
|
|
135
|
-
return
|
|
135
|
+
return own(policy.roles, role);
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
/** A record's own value at `key`: `constructor` or `__proto__` names nothing. */
|
|
139
|
+
function own<T>(record: Readonly<Record<string, T>>, key: string): T | undefined {
|
|
140
|
+
return Object.hasOwn(record, key) ? record[key] : undefined;
|
|
136
141
|
}
|
|
137
142
|
|
|
138
143
|
/**
|
|
@@ -184,7 +189,7 @@ export function isInstanceRole(value: string): value is InstanceRole {
|
|
|
184
189
|
|
|
185
190
|
/** Whether an instance role holds `permission` where nothing is protected, as `policy` defines it: as it ships, unless told. */
|
|
186
191
|
export function instanceRoleGrants(role: InstanceRole, permission: Permission, policy: Policy = DEFAULT_POLICY): boolean {
|
|
187
|
-
return (policy.instanceRoles
|
|
192
|
+
return (own(policy.instanceRoles, role)?.permissions ?? []).includes(permission);
|
|
188
193
|
}
|
|
189
194
|
|
|
190
195
|
/**
|
|
@@ -289,6 +294,23 @@ export function ownsInstance(standing: { role: InstanceRole; scope: Scope }): bo
|
|
|
289
294
|
return standing.role === 'owner' && unscoped(standing.scope);
|
|
290
295
|
}
|
|
291
296
|
|
|
297
|
+
/**
|
|
298
|
+
* Whether the holder is an Owner of a project, as a person on no
|
|
299
|
+
* credential's scope: an Owner of the whole instance, one scoped to the
|
|
300
|
+
* project, or one by a grant on it. They alone issue a service's token or
|
|
301
|
+
* trust binding that reads its sensitive values (R32, `readsSensitive`),
|
|
302
|
+
* and so make a sensitive value of its own a secret in place, and take its
|
|
303
|
+
* environments' protection off (R30): an Owner reads any value there
|
|
304
|
+
* anyway, through a service account they give read (break-glass). An
|
|
305
|
+
* Owner scoped to environments by slug, Owner of every `prod`, owns no
|
|
306
|
+
* project, and an Owner's token, scoped, none.
|
|
307
|
+
*/
|
|
308
|
+
export function ownsProject(holder: Holdings, projectId: string): boolean {
|
|
309
|
+
if (holder.credentialScope != null || holder.service === true) return false;
|
|
310
|
+
const place = { projectId };
|
|
311
|
+
return (holder.role === 'owner' && inScope(holder.scope, place)) || holder.grants.some((grant) => grant.role === 'owner' && covers(grant, place));
|
|
312
|
+
}
|
|
313
|
+
|
|
292
314
|
/**
|
|
293
315
|
* Which projects, or environments, a scope takes in: all of them, only
|
|
294
316
|
* those listed, or all but those listed. Projects are listed by id, so a
|
|
@@ -427,7 +449,9 @@ export function grantKind(grant: GrantPlace): 'project' | 'environment' | null {
|
|
|
427
449
|
* Each grant keeps what its role held when the credential was issued, both
|
|
428
450
|
* columns (`permissions`), and no more than its issuer held, so neither a
|
|
429
451
|
* role an Owner widens later nor its issuer widens the credential
|
|
430
|
-
* (docs/design/roles.md, section 8, rule 3).
|
|
452
|
+
* (docs/design/roles.md, section 8, rule 3). A service's grant keeps too
|
|
453
|
+
* whether its issuer was an Owner of the place, who alone hands a service
|
|
454
|
+
* its sensitive values (`readsSensitive`).
|
|
431
455
|
*/
|
|
432
456
|
export type CredentialScope = readonly ScopeGrant[];
|
|
433
457
|
|
|
@@ -439,9 +463,14 @@ export type Columns = { normal: readonly Permission[]; protected: readonly Permi
|
|
|
439
463
|
* the credential was issued (`issuedGrant`). One kept by a release before
|
|
440
464
|
* 0.10, its role's name alone, holds that role as it ships, a constant no
|
|
441
465
|
* edit changes, so it never widens either: a built-in role's, or nothing
|
|
442
|
-
* for any other name.
|
|
466
|
+
* for any other name. A service's, whether it reads the sensitive values
|
|
467
|
+
* there: true only when an Owner of its project issued it
|
|
468
|
+
* (`readsSensitive`); left out on a person's, who reads none. A
|
|
469
|
+
* workload's, the keys there it may read rather than use, by ID, or `'*'`
|
|
470
|
+
* for every one (docs/design/workload-access.md, section 6.1): its
|
|
471
|
+
* binding's `reads` at that place, and left out for any other credential.
|
|
443
472
|
*/
|
|
444
|
-
export type ScopeGrant = GrantPlace & { role: Role; permissions?: Columns };
|
|
473
|
+
export type ScopeGrant = GrantPlace & { role: Role; permissions?: Columns; sensitive?: boolean; reads?: readonly string[] | '*' };
|
|
445
474
|
|
|
446
475
|
/**
|
|
447
476
|
* A grant of a scope with what its role holds now in `policy`, kept: what a
|
|
@@ -491,7 +520,7 @@ export function heldColumns(holder: Holdings, place: Place): Columns {
|
|
|
491
520
|
*/
|
|
492
521
|
export function protectedWithin(policy: Policy, place: Place): Place[] {
|
|
493
522
|
if (place.environmentId != null) return [];
|
|
494
|
-
return (policy.protectedIn
|
|
523
|
+
return (own(policy.protectedIn, place.projectId) ?? []).map(({ environmentId, slug }) => ({ projectId: place.projectId, environmentId, environmentSlug: slug }));
|
|
495
524
|
}
|
|
496
525
|
|
|
497
526
|
/** What a scope's grant holds, as it was issued, as a role holds it: whatever the role is now, which no edit changes. */
|
|
@@ -547,8 +576,12 @@ export function isCredentialScope(value: unknown): value is CredentialScope {
|
|
|
547
576
|
const column = (list: unknown) => Array.isArray(list) && list.every((permission) => PERMISSIONS.includes(permission as Permission)) && new Set(list).size === list.length;
|
|
548
577
|
return value.every((grant: unknown) => {
|
|
549
578
|
if (typeof grant !== 'object' || grant === null || Array.isArray(grant)) return false;
|
|
550
|
-
const { projectId, environmentId, role, permissions, ...rest } = grant as Record<string, unknown>;
|
|
579
|
+
const { projectId, environmentId, role, permissions, sensitive, reads, ...rest } = grant as Record<string, unknown>;
|
|
551
580
|
if (Object.keys(rest).length > 0 || typeof projectId !== 'string' || typeof role !== 'string') return false;
|
|
581
|
+
if (sensitive !== undefined && typeof sensitive !== 'boolean') return false;
|
|
582
|
+
// A workload's list is an environment's: on a project's grant it would read the whole project.
|
|
583
|
+
if (reads !== undefined && environmentId === null) return false;
|
|
584
|
+
if (reads !== undefined && reads !== '*' && !(Array.isArray(reads) && reads.every((id) => typeof id === 'string') && new Set(reads).size === reads.length)) return false;
|
|
552
585
|
// As issued, both columns; or, kept before 0.10, a built-in role's name alone, which holds it as it ships.
|
|
553
586
|
if (!ROLE_ID.test(role)) return false;
|
|
554
587
|
if (permissions === undefined) {
|
|
@@ -591,8 +624,23 @@ export type Holdings = {
|
|
|
591
624
|
policy?: Policy;
|
|
592
625
|
/** A service account's, which holds each role's normal column everywhere; a person's holds a protected environment's column there. */
|
|
593
626
|
service?: boolean;
|
|
627
|
+
/**
|
|
628
|
+
* What the request came in on (`CallerKind`): a workload's key-bound
|
|
629
|
+
* session is handed back only the values its scope lists (`useOnly`).
|
|
630
|
+
* Absent, anything but a workload.
|
|
631
|
+
*/
|
|
632
|
+
kind?: CallerKind;
|
|
594
633
|
};
|
|
595
634
|
|
|
635
|
+
/**
|
|
636
|
+
* What kind of credential a request comes in on: a person's (a session or
|
|
637
|
+
* a personal token), a bearer's (a service token, or one a trust binding
|
|
638
|
+
* exchanged), or a workload's key-bound session, which reads only plain
|
|
639
|
+
* values and those its binding lists (docs/design/workload-access.md,
|
|
640
|
+
* section 6.1). The vault is told it with every call (`Through`).
|
|
641
|
+
*/
|
|
642
|
+
export type CallerKind = 'person' | 'bearer' | 'workload';
|
|
643
|
+
|
|
596
644
|
/** Someone who holds nothing: a stranger, a removed member, a tampered row. */
|
|
597
645
|
export const NOTHING: Holdings = { role: 'member', scope: EVERYWHERE, grants: [] };
|
|
598
646
|
|
|
@@ -625,7 +673,7 @@ export function covers(grant: GrantPlace, place: Place): boolean {
|
|
|
625
673
|
export function allows(holder: Holdings, permission: Permission, place: Place): boolean {
|
|
626
674
|
if (holder.credentialScope != null && !scopeHolds(holder, permission, place)) return false;
|
|
627
675
|
const policy = holder.policy ?? DEFAULT_POLICY;
|
|
628
|
-
if (inScope(holder.scope, place) && holds(policy.instanceRoles
|
|
676
|
+
if (inScope(holder.scope, place) && holds(own(policy.instanceRoles, holder.role), permission, place, holder)) return true;
|
|
629
677
|
return holder.grants.some((grant) => covers(grant, place) && holds(definitionOf(policy, grant.role), permission, place, holder));
|
|
630
678
|
}
|
|
631
679
|
|
|
@@ -645,6 +693,98 @@ function scopeHolds(holder: Holdings, permission: Permission, place: Place): boo
|
|
|
645
693
|
return (holder.credentialScope ?? []).some((grant) => covers(grant, place) && holds(scopeDefinition(grant), permission, place, holder));
|
|
646
694
|
}
|
|
647
695
|
|
|
696
|
+
/**
|
|
697
|
+
* Whether a sensitive value of the project `projectId` is handed to
|
|
698
|
+
* `holder` (R32): never to a person, Owners included (R16); to a service
|
|
699
|
+
* account, only on a credential an Owner of that project issued, as a
|
|
700
|
+
* grant of its scope in the project says (`ScopeGrant`'s `sensitive`).
|
|
701
|
+
* The project is the value's own, wherever it is read: a reference's
|
|
702
|
+
* source's, which lends its value and nature (R23), while whoever reads it
|
|
703
|
+
* is decided where it is held. A person who could not read the value gets
|
|
704
|
+
* it through no account they set up, nor through a value made sensitive
|
|
705
|
+
* after they issued its token, nor through a reference into a project
|
|
706
|
+
* they do not own:
|
|
707
|
+
*
|
|
708
|
+
* ci, a Viewer of backend/dev, which holds STRIPE_SECRET_KEY, sensitive
|
|
709
|
+
* its token, issued by Ada, a Developer reads every other value there
|
|
710
|
+
* its token, issued by an Owner of backend reads STRIPE_SECRET_KEY too
|
|
711
|
+
* billing/dev/LEAK, a reference to it; a token for billing/dev
|
|
712
|
+
* issued by an Owner of billing alone reads every other value there
|
|
713
|
+
*/
|
|
714
|
+
export function readsSensitive(holder: Holdings, projectId: string): boolean {
|
|
715
|
+
return holder.service === true && (holder.credentialScope ?? []).some((grant) => grant.sensitive === true && grant.projectId === projectId);
|
|
716
|
+
}
|
|
717
|
+
|
|
718
|
+
/** A key, by its id and where its value is held: a reference's source's, an inherited key's parent's. */
|
|
719
|
+
export type HeldKey = { projectId: string; environmentId: string; secretId: string };
|
|
720
|
+
|
|
721
|
+
/**
|
|
722
|
+
* Whether a value is use-only to `holder` (docs/design/workload-access.md,
|
|
723
|
+
* section 6.1): a workload is handed back no secret or sensitive value but
|
|
724
|
+
* one its credential's scope lists, by the key's id, on a grant that covers
|
|
725
|
+
* the place where the value is held, never the place a request names. A
|
|
726
|
+
* rename therefore moves no listing, and no reference, fork or copy moves a
|
|
727
|
+
* value under one. Nobody else's: their roles and the value's nature decide.
|
|
728
|
+
* A plain value is no secret, use-only to nobody, so it is never asked of.
|
|
729
|
+
*
|
|
730
|
+
* api-prod lists STRIPE_WEBHOOK_SECRET's id at market/prod
|
|
731
|
+
* market/prod/STRIPE_WEBHOOK_SECRET read
|
|
732
|
+
* STRIPE_SECRET_KEY, renamed STRIPE_WEBHOOK_SECRET once that moved use only: another id
|
|
733
|
+
* market/dev/S, a reference to it, with "*" at market/dev use only: held in market/prod
|
|
734
|
+
*/
|
|
735
|
+
export function useOnly(holder: Holdings, key: HeldKey): boolean {
|
|
736
|
+
if (holder.kind !== 'workload') return false;
|
|
737
|
+
const place: Place = { projectId: key.projectId, environmentId: key.environmentId, environmentSlug: null };
|
|
738
|
+
return !(holder.credentialScope ?? []).some((grant) => covers(grant, place) && (grant.reads === '*' || (grant.reads?.includes(key.secretId) ?? false)));
|
|
739
|
+
}
|
|
740
|
+
|
|
741
|
+
/**
|
|
742
|
+
* A workload's credential scope with its binding's `reads` on it, by
|
|
743
|
+
* environment ID (docs/design/workload-access.md, section 6.1): each
|
|
744
|
+
* environment's list on a grant at that environment, the scope's own there,
|
|
745
|
+
* or, where only a grant on its project reaches it, a grant made at the
|
|
746
|
+
* environment holding no more than that one does there. What the scope
|
|
747
|
+
* holds is unchanged, only what of it is handed back: a place it reaches
|
|
748
|
+
* nowhere lists nothing, and a list a grant carried is replaced, so a
|
|
749
|
+
* session reads what its binding lists now. `projectOf` names each listed
|
|
750
|
+
* environment's project; one it does not name, gone since, lists nothing.
|
|
751
|
+
*
|
|
752
|
+
* scope viewer on market
|
|
753
|
+
* reads { <prod>: { keys: [<STRIPE_WEBHOOK_SECRET>] } }
|
|
754
|
+
* result viewer on market; viewer on market/prod, reading STRIPE_WEBHOOK_SECRET
|
|
755
|
+
*/
|
|
756
|
+
export function scopeWithReads(
|
|
757
|
+
scope: CredentialScope,
|
|
758
|
+
reads: Readonly<Record<string, { readonly keys?: readonly string[] | '*' }>> | undefined,
|
|
759
|
+
projectOf: ReadonlyMap<string, string>,
|
|
760
|
+
): CredentialScope {
|
|
761
|
+
const unlisted = scope.map(({ reads: _, ...grant }) => grant as ScopeGrant);
|
|
762
|
+
const result = [...unlisted];
|
|
763
|
+
for (const [environmentId, { keys }] of Object.entries(reads ?? {})) {
|
|
764
|
+
const projectId = projectOf.get(environmentId);
|
|
765
|
+
if (keys === undefined || projectId === undefined) continue;
|
|
766
|
+
const at = result.findIndex((grant) => grant.projectId === projectId && grant.environmentId === environmentId);
|
|
767
|
+
if (at >= 0) {
|
|
768
|
+
result[at] = { ...result[at]!, reads: keys };
|
|
769
|
+
continue;
|
|
770
|
+
}
|
|
771
|
+
const project = unlisted.find((grant) => grant.projectId === projectId && grant.environmentId === null);
|
|
772
|
+
if (project === undefined) continue;
|
|
773
|
+
// What the project's grant holds at the environment: its columns, but for what only a project holds.
|
|
774
|
+
const { permissions, protected: guarded } = scopeDefinition(project);
|
|
775
|
+
const here = (column: readonly Permission[]) => column.filter((permission) => !PROJECT_ONLY_PERMISSIONS.includes(permission));
|
|
776
|
+
result.push({
|
|
777
|
+
projectId,
|
|
778
|
+
environmentId,
|
|
779
|
+
role: project.role,
|
|
780
|
+
permissions: { normal: here(permissions), protected: here(guarded) },
|
|
781
|
+
...(project.sensitive === undefined ? {} : { sensitive: project.sensitive }),
|
|
782
|
+
reads: keys,
|
|
783
|
+
});
|
|
784
|
+
}
|
|
785
|
+
return result;
|
|
786
|
+
}
|
|
787
|
+
|
|
648
788
|
/**
|
|
649
789
|
* Whether the actor may give or take grants at this place: with
|
|
650
790
|
* `grant.manage` there, from a project grant or an instance role whose
|
|
@@ -771,7 +911,7 @@ export function issuesCredential(
|
|
|
771
911
|
* they hold `audit.read` in.
|
|
772
912
|
*/
|
|
773
913
|
export function readsWholeLog(holder: Holdings): boolean {
|
|
774
|
-
const role = (holder.policy ?? DEFAULT_POLICY).instanceRoles
|
|
914
|
+
const role = own((holder.policy ?? DEFAULT_POLICY).instanceRoles, holder.role);
|
|
775
915
|
return holder.credentialScope == null && unscoped(holder.scope)
|
|
776
916
|
&& role !== undefined && role.permissions.includes('audit.read') && role.protected.includes('audit.read');
|
|
777
917
|
}
|
package/src/dotenv.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function parseDotenv(input: string): ParseResult {
|
|
|
61
61
|
|
|
62
62
|
const key = withoutExport.slice(0, equals).trim();
|
|
63
63
|
if (!KEY_RE.test(key)) {
|
|
64
|
-
problems.push({ line: lineNumber, reason: 'key must match ^[A-Za-z_][A-Za-z0-9_]
|
|
64
|
+
problems.push({ line: lineNumber, reason: 'key must match ^[A-Za-z_][A-Za-z0-9_]{0,127}$' });
|
|
65
65
|
continue;
|
|
66
66
|
}
|
|
67
67
|
|
|
@@ -0,0 +1,168 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `narrow` child's limits (docs/design/workload-access.md, section 8.4):
|
|
3
|
+
* the places, credentials, methods and path prefixes it may reach, each
|
|
4
|
+
* left out for no limit of its own. A child holds the intersection of what
|
|
5
|
+
* it asked and what its parent holds, computed when it is made and stored
|
|
6
|
+
* under its row's MAC, and every operation it asks for is checked against
|
|
7
|
+
* them by `constraintsAllow`, on the URL the proxy is about to send.
|
|
8
|
+
*
|
|
9
|
+
* parent { credentials: ['stripe', 'openai'] } child asks { credentials: ['stripe'], paths: ['/v1/refunds'] }
|
|
10
|
+
* child { credentials: ['stripe'], paths: ['/v1/refunds'] }
|
|
11
|
+
* POST https://api.stripe.com/v1/refunds/re_1 allowed
|
|
12
|
+
* POST https://api.stripe.com/v1/refunds/%2e%2e/charges refused: it is /v1/charges once parsed
|
|
13
|
+
* POST https://api.stripe.com/v1/refundsX refused: a prefix matches whole segments
|
|
14
|
+
*/
|
|
15
|
+
import { fetchMethod, METHOD_TOKEN } from '@coffre/client/dpop';
|
|
16
|
+
|
|
17
|
+
import { CREDENTIAL_NAME } from './workloads.ts';
|
|
18
|
+
|
|
19
|
+
export type Constraints = {
|
|
20
|
+
/** Environments, `<project>/<environment>`. */
|
|
21
|
+
readonly places?: readonly string[];
|
|
22
|
+
/** The credentials, signers, verifiers, tunnels and minters it may reach, by name. */
|
|
23
|
+
readonly credentials?: readonly string[];
|
|
24
|
+
readonly methods?: readonly string[];
|
|
25
|
+
/** Path prefixes, each matching whole segments. */
|
|
26
|
+
readonly paths?: readonly string[];
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
/** The most entries in each list. */
|
|
30
|
+
export const MAX_CONSTRAINTS = 32;
|
|
31
|
+
|
|
32
|
+
/** A constraint that does not parse, said so the caller can fix it. */
|
|
33
|
+
export class ConstraintsInvalid extends Error {
|
|
34
|
+
constructor(message: string) {
|
|
35
|
+
super(message);
|
|
36
|
+
this.name = 'ConstraintsInvalid';
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const PLACE = /^[a-z0-9][a-z0-9-]{0,62}\/[a-z0-9][a-z0-9-]{0,62}(@me)?$/;
|
|
41
|
+
/** A path segment as a constraint names one: no escape, no `;`, no dot segment. */
|
|
42
|
+
const SEGMENT = /^[A-Za-z0-9\-_~!$&'()*+,=:@.]+$/;
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* What a path may not hold for a constrained session, since an upstream
|
|
46
|
+
* might read a segment otherwise than coffre: an escaped `.`, `/` or `\`,
|
|
47
|
+
* a `%25` (double encoding), or a `;`, raw or escaped
|
|
48
|
+
* (`/v1/refunds/..;/charges` and `/v1/refunds/..%3b/charges` are
|
|
49
|
+
* `/v1/charges` to Tomcat).
|
|
50
|
+
*/
|
|
51
|
+
const AMBIGUOUS = /%2e|%2f|%5c|%25|%3b|;/i;
|
|
52
|
+
|
|
53
|
+
function list(value: unknown, what: string, valid: (item: string) => boolean): string[] | undefined {
|
|
54
|
+
if (value === undefined) return undefined;
|
|
55
|
+
if (!Array.isArray(value) || value.length > MAX_CONSTRAINTS || value.some((item) => typeof item !== 'string' || !valid(item))) {
|
|
56
|
+
throw new ConstraintsInvalid(`${what} lists at most ${MAX_CONSTRAINTS} of them`);
|
|
57
|
+
}
|
|
58
|
+
return [...new Set(value as string[])].sort();
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function isPrefix(path: string): boolean {
|
|
62
|
+
if (path === '/') return true;
|
|
63
|
+
if (!path.startsWith('/') || path.endsWith('/')) return false;
|
|
64
|
+
return path.slice(1).split('/').every((segment) => SEGMENT.test(segment) && segment !== '.' && segment !== '..');
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
/** Whether `path` is `prefix` or below it, by whole segments. */
|
|
68
|
+
function under(path: string, prefix: string): boolean {
|
|
69
|
+
return prefix === '/' || path === prefix || path.startsWith(`${prefix}/`);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
* Constraints as a child asks for them, checked and canonical: each list
|
|
74
|
+
* sorted, without duplicates; methods as Fetch sends them; prefixes absolute,
|
|
75
|
+
* with no trailing slash, escape, `;` or dot segment, and none under
|
|
76
|
+
* another, which it would add nothing to. Throws `ConstraintsInvalid`.
|
|
77
|
+
*/
|
|
78
|
+
export function checkConstraints(input: unknown): Constraints {
|
|
79
|
+
if (typeof input !== 'object' || input === null || Array.isArray(input)) throw new ConstraintsInvalid('constraints are an object');
|
|
80
|
+
const { places, credentials, methods, paths, ...rest } = input as Record<string, unknown>;
|
|
81
|
+
if (Object.keys(rest).length > 0) throw new ConstraintsInvalid(`constraints hold places, credentials, methods and paths, not ${Object.keys(rest).join(', ')}`);
|
|
82
|
+
const checked: { -readonly [K in keyof Constraints]: Constraints[K] } = {};
|
|
83
|
+
const placeList = list(places, 'places', (place) => PLACE.test(place));
|
|
84
|
+
const credentialList = list(credentials, 'credentials', (name) => CREDENTIAL_NAME.test(name));
|
|
85
|
+
// As Fetch sends each, and so as a proof signs it: `get` is GET, and `M-SEARCH` stays itself.
|
|
86
|
+
const methodList = list(Array.isArray(methods) ? methods.map((method) => (typeof method === 'string' && METHOD_TOKEN.test(method) ? fetchMethod(method) : method)) : methods, 'methods', (method) => METHOD_TOKEN.test(method));
|
|
87
|
+
const pathList = list(paths, 'paths', isPrefix);
|
|
88
|
+
if (placeList !== undefined) checked.places = placeList;
|
|
89
|
+
if (credentialList !== undefined) checked.credentials = credentialList;
|
|
90
|
+
if (methodList !== undefined) checked.methods = methodList;
|
|
91
|
+
if (pathList !== undefined) checked.paths = outermost(pathList);
|
|
92
|
+
return checked;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** The prefixes no other one is above. */
|
|
96
|
+
function outermost(paths: readonly string[]): string[] {
|
|
97
|
+
return paths.filter((path) => !paths.some((other) => other !== path && under(path, other)));
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function both(a: readonly string[] | undefined, b: readonly string[] | undefined): readonly string[] | undefined {
|
|
101
|
+
if (a === undefined) return b;
|
|
102
|
+
if (b === undefined) return a;
|
|
103
|
+
return a.filter((item) => b.includes(item));
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/**
|
|
107
|
+
* What a child holds: what it asked within what its parent holds, list by
|
|
108
|
+
* list, and for paths each prefix of one side that is under one of the
|
|
109
|
+
* other's. A parent with none is a root, which only its scope bounds. Never
|
|
110
|
+
* wider than either: whatever `intersect(a, b)` allows, `a` and `b` allow.
|
|
111
|
+
*/
|
|
112
|
+
export function intersect(parent: Constraints | null, child: Constraints): Constraints {
|
|
113
|
+
if (parent === null) return child;
|
|
114
|
+
const result: { -readonly [K in keyof Constraints]: Constraints[K] } = {};
|
|
115
|
+
const places = both(parent.places, child.places);
|
|
116
|
+
const credentials = both(parent.credentials, child.credentials);
|
|
117
|
+
const methods = both(parent.methods, child.methods);
|
|
118
|
+
if (places !== undefined) result.places = places;
|
|
119
|
+
if (credentials !== undefined) result.credentials = credentials;
|
|
120
|
+
if (methods !== undefined) result.methods = methods;
|
|
121
|
+
if (parent.paths === undefined || child.paths === undefined) {
|
|
122
|
+
const paths = parent.paths ?? child.paths;
|
|
123
|
+
if (paths !== undefined) result.paths = paths;
|
|
124
|
+
} else {
|
|
125
|
+
const kept = [
|
|
126
|
+
...child.paths.filter((path) => parent.paths!.some((prefix) => under(path, prefix))),
|
|
127
|
+
...parent.paths.filter((path) => child.paths!.some((prefix) => under(path, prefix))),
|
|
128
|
+
];
|
|
129
|
+
result.paths = outermost([...new Set(kept)].sort());
|
|
130
|
+
}
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/** The constraints as a row's `constraints` column and its MAC hold them: `checkConstraints`'s keys in order. */
|
|
135
|
+
export function constraintsText(constraints: Constraints): string {
|
|
136
|
+
const { places, credentials, methods, paths } = constraints;
|
|
137
|
+
return JSON.stringify({ places, credentials, methods, paths });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
/**
|
|
141
|
+
* Whether one operation is within the constraints: its place and credential
|
|
142
|
+
* named, and, for one that sends a request upstream, its method and the
|
|
143
|
+
* path of the URL it is about to send, as the WHATWG parser resolved it.
|
|
144
|
+
* An operation with no request to check (`sign`, `verify`, `mint`, the
|
|
145
|
+
* tunnel) is refused wherever methods or paths are limited: a constraint
|
|
146
|
+
* that cannot be checked refuses.
|
|
147
|
+
*/
|
|
148
|
+
export function constraintsAllow(
|
|
149
|
+
constraints: Constraints | null,
|
|
150
|
+
operation: { place: string; credential: string; request?: { method: string; url: string | URL } },
|
|
151
|
+
): boolean {
|
|
152
|
+
if (constraints === null) return true;
|
|
153
|
+
if (constraints.places !== undefined && !constraints.places.includes(operation.place)) return false;
|
|
154
|
+
if (constraints.credentials !== undefined && !constraints.credentials.includes(operation.credential)) return false;
|
|
155
|
+
if (constraints.methods === undefined && constraints.paths === undefined) return true;
|
|
156
|
+
if (operation.request === undefined) return false;
|
|
157
|
+
// Exactly, as a proof signs it: a child of POST is refused `post`, which an upstream may read otherwise.
|
|
158
|
+
if (constraints.methods !== undefined && !(METHOD_TOKEN.test(operation.request.method) && constraints.methods.includes(fetchMethod(operation.request.method)))) return false;
|
|
159
|
+
if (constraints.paths === undefined) return true;
|
|
160
|
+
let path: string;
|
|
161
|
+
try {
|
|
162
|
+
path = new URL(String(operation.request.url)).pathname;
|
|
163
|
+
} catch {
|
|
164
|
+
return false;
|
|
165
|
+
}
|
|
166
|
+
if (AMBIGUOUS.test(path)) return false;
|
|
167
|
+
return constraints.paths.some((prefix) => under(path, prefix));
|
|
168
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checking a workload's proof (docs/design/workload-access.md, section
|
|
3
|
+
* 5.1): the verifying half of `@coffre/client/dpop`, whose canonicalization
|
|
4
|
+
* it runs, so both sides agree on every byte. Cheapest first:
|
|
5
|
+
*
|
|
6
|
+
* 1. shape at most 2 KiB, `typ` exactly `dpop+jwt`, `alg` exactly `ES256`
|
|
7
|
+
* 2. the key `jwk` exactly `kty`, `crv`, `x` and `y`, a point on P-256
|
|
8
|
+
* 3. claims `jti` 16 bytes, `iat` an integer, `hdr` at most 32 names, none unsigned
|
|
9
|
+
* (`parseProof`, no I/O)
|
|
10
|
+
* 4. the session row, from the token's hash: the server's, between the two
|
|
11
|
+
* 5. key and signature the thumbprint is the row's `jkt`, then ES256
|
|
12
|
+
* 6. what was signed `htm`, `htu`, `ath`, `req`, then `iat` within ±300 s
|
|
13
|
+
* (`verifyProof`)
|
|
14
|
+
* 7. the gate's nonce and `jti`: the server's again (`Gate`)
|
|
15
|
+
*
|
|
16
|
+
* Each claim the caller expects (`ath` with a token, `hdr` and `req` with a
|
|
17
|
+
* request's content) must be there, and one it does not expect must not.
|
|
18
|
+
* Two signatures of one payload, `(r, s)` and `(r, n − s)`, both verify:
|
|
19
|
+
* they carry one `jti`, which the gate takes once.
|
|
20
|
+
*/
|
|
21
|
+
import {
|
|
22
|
+
canonicalHtu,
|
|
23
|
+
fetchMethod,
|
|
24
|
+
fromBase64url,
|
|
25
|
+
MAX_PROOF_LENGTH,
|
|
26
|
+
MAX_SIGNED_HEADERS,
|
|
27
|
+
METHOD_TOKEN,
|
|
28
|
+
requestDigest,
|
|
29
|
+
sentTarget,
|
|
30
|
+
thumbprint,
|
|
31
|
+
tokenDigest,
|
|
32
|
+
UNSIGNED_HEADERS,
|
|
33
|
+
type ProofClaims,
|
|
34
|
+
type PublicJwk,
|
|
35
|
+
} from '@coffre/client/dpop';
|
|
36
|
+
|
|
37
|
+
export { canonicalHtu, canonicalRequest, fetchMethod, MAX_PROOF_LENGTH, MAX_SIGNED_HEADERS, sentTarget, thumbprint, type ProofClaims, type PublicJwk } from '@coffre/client/dpop';
|
|
38
|
+
|
|
39
|
+
/** How far a proof's `iat` may be from now: the nonce, not the clock, is what makes a proof fresh. */
|
|
40
|
+
export const PROOF_SKEW_SECONDS = 300;
|
|
41
|
+
|
|
42
|
+
/** Why a proof was refused, which a 401's `reason` names under `error="invalid_dpop_proof"`. */
|
|
43
|
+
export type ProofReason = 'malformed' | 'key' | 'jkt' | 'signature' | 'htm' | 'htu' | 'ath' | 'req' | 'iat';
|
|
44
|
+
|
|
45
|
+
export type ProofRefusal = { ok: false; reason: ProofReason; message: string };
|
|
46
|
+
|
|
47
|
+
/** A proof whose shape, key and claims hold: what `verifyProof` checks against the request. */
|
|
48
|
+
export type ParsedProof = {
|
|
49
|
+
ok: true;
|
|
50
|
+
jwk: PublicJwk;
|
|
51
|
+
claims: ProofClaims;
|
|
52
|
+
/** The headers it signs, in `hdr`'s order; null for a proof that signs no content. */
|
|
53
|
+
hdr: readonly string[] | null;
|
|
54
|
+
signingInput: string;
|
|
55
|
+
signature: Uint8Array;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
/** A proof that holds for its request: its key's thumbprint, and what the gate checks. */
|
|
59
|
+
export type VerifiedProof = { ok: true; jkt: string; jti: string; nonce: string | null; iat: number; hdr: readonly string[] | null };
|
|
60
|
+
|
|
61
|
+
/** What the request says a proof must sign. */
|
|
62
|
+
export type ProofExpectation = {
|
|
63
|
+
/** The request's method and URL, as received: `Request.method`, which the Fetch API has normalized as `fetchMethod` does. */
|
|
64
|
+
method: string;
|
|
65
|
+
url: string | URL;
|
|
66
|
+
/** The session row's `jkt`; none at the exchange, where the proof's key becomes the session's. */
|
|
67
|
+
jkt?: string;
|
|
68
|
+
/** The session token the request carries, which `ath` signs; none at the exchange. */
|
|
69
|
+
token?: string;
|
|
70
|
+
/** The request's headers and its body's digest, which `hdr` and `req` sign: for a request coffre forwards. */
|
|
71
|
+
content?: { headers: Headers; body: string };
|
|
72
|
+
/** Seconds `iat` may be from now: 300 unless said, 60 at the exchange. */
|
|
73
|
+
skewSeconds?: number;
|
|
74
|
+
/** Now, in milliseconds, for tests. */
|
|
75
|
+
now?: number;
|
|
76
|
+
};
|
|
77
|
+
|
|
78
|
+
const refuse = (reason: ProofReason, message: string): ProofRefusal => ({ ok: false, reason, message });
|
|
79
|
+
|
|
80
|
+
const DECODER = new TextDecoder('utf-8', { fatal: true });
|
|
81
|
+
const ENCODER = new TextEncoder();
|
|
82
|
+
const HEADER_NAME = /^[!#$%&'*+.^_`|~0-9a-z-]+$/;
|
|
83
|
+
const CLAIMS = new Set(['jti', 'htm', 'htu', 'iat', 'ath', 'nonce', 'hdr', 'req']);
|
|
84
|
+
|
|
85
|
+
/** A part of the proof as a JSON object, or null for anything else. */
|
|
86
|
+
function jsonPart(part: string): Record<string, unknown> | null {
|
|
87
|
+
const bytes = fromBase64url(part);
|
|
88
|
+
if (bytes === null) return null;
|
|
89
|
+
try {
|
|
90
|
+
const value: unknown = JSON.parse(DECODER.decode(bytes));
|
|
91
|
+
return typeof value === 'object' && value !== null && !Array.isArray(value) ? (value as Record<string, unknown>) : null;
|
|
92
|
+
} catch {
|
|
93
|
+
return null;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
function exactly(value: Record<string, unknown>, keys: readonly string[]): boolean {
|
|
98
|
+
const own = Object.keys(value);
|
|
99
|
+
return own.length === keys.length && keys.every((key) => Object.hasOwn(value, key));
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
const isDigest = (value: unknown): value is string => typeof value === 'string' && fromBase64url(value)?.length === 32;
|
|
103
|
+
|
|
104
|
+
/** Steps 1 to 3: the proof's shape, its key's and its claims', with no I/O. */
|
|
105
|
+
export function parseProof(proof: string): ParsedProof | ProofRefusal {
|
|
106
|
+
if (proof.length > MAX_PROOF_LENGTH) return refuse('malformed', `a proof is at most ${MAX_PROOF_LENGTH} characters`);
|
|
107
|
+
const parts = proof.split('.');
|
|
108
|
+
if (parts.length !== 3) return refuse('malformed', 'a proof is a compact JWS: three parts');
|
|
109
|
+
const [headerPart, payloadPart, signaturePart] = parts as [string, string, string];
|
|
110
|
+
const header = jsonPart(headerPart);
|
|
111
|
+
if (header === null || !exactly(header, ['typ', 'alg', 'jwk']) || header.typ !== 'dpop+jwt' || header.alg !== 'ES256') {
|
|
112
|
+
return refuse('malformed', 'a proof\'s header is exactly { typ: "dpop+jwt", alg: "ES256", jwk }');
|
|
113
|
+
}
|
|
114
|
+
const jwk = header.jwk as Record<string, unknown>;
|
|
115
|
+
if (
|
|
116
|
+
typeof jwk !== 'object' || jwk === null || Array.isArray(jwk) || !exactly(jwk, ['kty', 'crv', 'x', 'y'])
|
|
117
|
+
|| jwk.kty !== 'EC' || jwk.crv !== 'P-256' || !isCoordinate(jwk.x) || !isCoordinate(jwk.y)
|
|
118
|
+
) {
|
|
119
|
+
return refuse('key', "a proof's key is a P-256 public key: exactly kty, crv, x and y");
|
|
120
|
+
}
|
|
121
|
+
const signature = fromBase64url(signaturePart);
|
|
122
|
+
if (signature === null || signature.length !== 64) return refuse('malformed', 'an ES256 signature is 64 bytes, r then s');
|
|
123
|
+
const claims = jsonPart(payloadPart);
|
|
124
|
+
if (claims === null || Object.keys(claims).some((name) => !CLAIMS.has(name))) return refuse('malformed', "a proof's claims are jti, htm, htu, iat, and ath, nonce, hdr, req where they apply");
|
|
125
|
+
if (typeof claims.jti !== 'string' || fromBase64url(claims.jti)?.length !== 16) return refuse('malformed', 'jti is 16 random bytes, in base64url');
|
|
126
|
+
if (typeof claims.htm !== 'string' || !METHOD_TOKEN.test(claims.htm)) return refuse('malformed', 'htm is the request\'s method');
|
|
127
|
+
if (typeof claims.htu !== 'string') return refuse('malformed', 'htu is the request\'s URL');
|
|
128
|
+
if (!Number.isSafeInteger(claims.iat)) return refuse('malformed', 'iat is an integer, in seconds');
|
|
129
|
+
if (claims.ath !== undefined && !isDigest(claims.ath)) return refuse('malformed', 'ath is a SHA-256, in base64url');
|
|
130
|
+
if (claims.nonce !== undefined && (typeof claims.nonce !== 'string' || !/^[\x21-\x7e]{1,128}$/.test(claims.nonce))) {
|
|
131
|
+
return refuse('malformed', 'nonce is the one coffre gave');
|
|
132
|
+
}
|
|
133
|
+
if ((claims.hdr === undefined) !== (claims.req === undefined)) return refuse('malformed', 'hdr and req come together');
|
|
134
|
+
let hdr: string[] | null = null;
|
|
135
|
+
if (claims.hdr !== undefined) {
|
|
136
|
+
if (typeof claims.hdr !== 'string' || !isDigest(claims.req)) return refuse('malformed', 'hdr names headers, and req is a SHA-256');
|
|
137
|
+
hdr = claims.hdr === '' ? [] : claims.hdr.split(' ');
|
|
138
|
+
if (hdr.length > MAX_SIGNED_HEADERS) return refuse('malformed', `a proof signs at most ${MAX_SIGNED_HEADERS} headers`);
|
|
139
|
+
if (hdr.some((name) => !HEADER_NAME.test(name) || UNSIGNED_HEADERS.has(name)) || new Set(hdr).size !== hdr.length) {
|
|
140
|
+
return refuse('malformed', 'hdr names each header once, in lower case, and none the transport or the request to coffre owns');
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return { ok: true, jwk: jwk as PublicJwk, claims: claims as ProofClaims, hdr, signingInput: `${headerPart}.${payloadPart}`, signature };
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
function isCoordinate(value: unknown): value is string {
|
|
147
|
+
return typeof value === 'string' && fromBase64url(value)?.length === 32;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/**
|
|
151
|
+
* Steps 5 and 6: the proof against its request, `parseProof`'s first when
|
|
152
|
+
* given a string. Nothing here reads a store, so the gate (step 7) still
|
|
153
|
+
* decides whether this `jti` was seen.
|
|
154
|
+
*/
|
|
155
|
+
export async function verifyProof(proof: string | ParsedProof, expect: ProofExpectation): Promise<VerifiedProof | ProofRefusal> {
|
|
156
|
+
const parsed = typeof proof === 'string' ? parseProof(proof) : proof;
|
|
157
|
+
if (!parsed.ok) return parsed;
|
|
158
|
+
const { jwk, claims, hdr } = parsed;
|
|
159
|
+
const jkt = await thumbprint(jwk);
|
|
160
|
+
if (expect.jkt !== undefined && jkt !== expect.jkt) return refuse('jkt', 'the proof is signed by another key than the session\'s');
|
|
161
|
+
let key: CryptoKey;
|
|
162
|
+
try {
|
|
163
|
+
key = await crypto.subtle.importKey('jwk', { kty: jwk.kty, crv: jwk.crv, x: jwk.x, y: jwk.y }, { name: 'ECDSA', namedCurve: 'P-256' }, false, ['verify']);
|
|
164
|
+
} catch {
|
|
165
|
+
return refuse('key', "the proof's key is no point on P-256");
|
|
166
|
+
}
|
|
167
|
+
const valid = await crypto.subtle.verify({ name: 'ECDSA', hash: 'SHA-256' }, key, parsed.signature as Uint8Array<ArrayBuffer>, ENCODER.encode(parsed.signingInput));
|
|
168
|
+
if (!valid) return refuse('signature', 'the proof\'s signature does not verify');
|
|
169
|
+
|
|
170
|
+
if (claims.htm !== fetchMethod(expect.method)) return refuse('htm', 'the proof signs another method');
|
|
171
|
+
let htu: string;
|
|
172
|
+
try {
|
|
173
|
+
htu = canonicalHtu(expect.url);
|
|
174
|
+
} catch {
|
|
175
|
+
return refuse('htu', 'the request\'s URL cannot be signed');
|
|
176
|
+
}
|
|
177
|
+
if (claims.htu !== htu) return refuse('htu', 'the proof signs another URL');
|
|
178
|
+
if ((expect.token === undefined) !== (claims.ath === undefined)) {
|
|
179
|
+
return refuse('ath', expect.token === undefined ? 'this proof signs no token' : 'the proof signs no token: ath');
|
|
180
|
+
}
|
|
181
|
+
if (expect.token !== undefined && claims.ath !== (await tokenDigest(expect.token))) return refuse('ath', 'the proof signs another token');
|
|
182
|
+
if ((expect.content === undefined) !== (hdr === null)) {
|
|
183
|
+
return refuse('req', expect.content === undefined ? 'this proof signs no request content' : 'the proof signs no request content: hdr and req');
|
|
184
|
+
}
|
|
185
|
+
if (expect.content !== undefined) {
|
|
186
|
+
const headers: [string, string][] = [];
|
|
187
|
+
for (const name of hdr!) {
|
|
188
|
+
const value = expect.content.headers.get(name);
|
|
189
|
+
if (value === null) return refuse('req', `the proof signs a header the request lacks: ${name}`);
|
|
190
|
+
headers.push([name, value]);
|
|
191
|
+
}
|
|
192
|
+
let digest: string;
|
|
193
|
+
try {
|
|
194
|
+
digest = await requestDigest({ ...sentTarget(expect.url), headers, body: expect.content.body });
|
|
195
|
+
} catch {
|
|
196
|
+
return refuse('req', 'the request cannot be signed: a line break in its path, query or headers');
|
|
197
|
+
}
|
|
198
|
+
if (claims.req !== digest) return refuse('req', 'the proof signs another path as sent, query, header or body');
|
|
199
|
+
}
|
|
200
|
+
const skew = expect.skewSeconds ?? PROOF_SKEW_SECONDS;
|
|
201
|
+
const now = Math.floor((expect.now ?? Date.now()) / 1000);
|
|
202
|
+
if (Math.abs(now - claims.iat) > skew) return refuse('iat', `the proof was made more than ${skew} seconds from now`);
|
|
203
|
+
return { ok: true, jkt, jti: claims.jti, nonce: claims.nonce ?? null, iat: claims.iat, hdr };
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
/** A count a request asks the gate for: the requests under `key` in the last `windowMs`, at most `most`. */
|
|
207
|
+
export type GateCount = { key: string; windowMs: number; most: number };
|
|
208
|
+
|
|
209
|
+
/** What the gate answers a request: its nonce on success, or why not. */
|
|
210
|
+
export type GateAdmission =
|
|
211
|
+
| { ok: true; nonce: string }
|
|
212
|
+
| { ok: false; reason: 'use_dpop_nonce'; nonce: string }
|
|
213
|
+
| { ok: false; reason: 'replayed' | 'overloaded' }
|
|
214
|
+
/** `first`: the first refusal of this key in its window, which alerts. */
|
|
215
|
+
| { ok: false; reason: 'limit'; key: string; retryAfterMs: number; first: boolean };
|
|
216
|
+
|
|
217
|
+
/**
|
|
218
|
+
* One workload's gate (section 5.2): a Durable Object on Workers, an object
|
|
219
|
+
* in the process on Node. Its nonces are epochs: a gate accepts the current
|
|
220
|
+
* and the previous one, remembers each epoch's `jti`s, and draws a new epoch
|
|
221
|
+
* when it starts, so a restart forgets nothing that matters. It decides no
|
|
222
|
+
* one's access: freezes, revocations and grants are the database's.
|
|
223
|
+
*/
|
|
224
|
+
export interface Gate {
|
|
225
|
+
/** Its current nonce, `g<n>.<epoch>`, for an answer that admits no proof: the exchange's `DPoP-Nonce`. */
|
|
226
|
+
nonce(): Promise<string>;
|
|
227
|
+
/**
|
|
228
|
+
* Replay and nonce, for a request that carries a proof (a Cloudflare call
|
|
229
|
+
* carries none, and has counts only); then, in the same call, every count
|
|
230
|
+
* the request asks for. A nonce of an epoch gone gets `use_dpop_nonce`; a
|
|
231
|
+
* proof with none never reaches the gate, and gets `nonce()`'s.
|
|
232
|
+
*/
|
|
233
|
+
admit(request: { replay?: { session: string; jti: string; nonce: string }; counts?: readonly GateCount[] }): Promise<GateAdmission>;
|
|
234
|
+
}
|
package/src/identity/index.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// `@coffre/core/identity`: who is asking, and how coffre's sign-in finds out.
|
|
2
2
|
export * from './auth.ts';
|
|
3
|
+
export * from './constraints.ts';
|
|
4
|
+
export * from './dpop.ts';
|
|
3
5
|
export * from './github-app.ts';
|
|
4
6
|
export * from './signin/index.ts';
|
|
5
7
|
export * from './tokens.ts';
|