@plitzi/sdk-kernel 0.0.0-stage → 0.39.2
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/CHANGELOG.md +10 -0
- package/README.md +80 -2
- package/dist/build/esbuild.d.ts +16 -0
- package/dist/build/index.d.ts +1 -0
- package/dist/build/index.mjs +35 -0
- package/dist/cache/CompressedFileCache.d.ts +18 -0
- package/dist/cache/TtlCache.d.ts +65 -0
- package/dist/cache/index.d.ts +3 -0
- package/dist/cache/index.mjs +1 -0
- package/dist/chunks/TtlCache-J_jG9oL9.mjs +200 -0
- package/dist/chunks/channel-DnVf7PJB.mjs +190 -0
- package/dist/chunks/csrf-BLWcaYOV.mjs +295 -0
- package/dist/chunks/link-C9wyDS9H.mjs +124 -0
- package/dist/chunks/query-DGbrN3mN.mjs +20 -0
- package/dist/chunks/scopes-Co6ZjhAm.mjs +46 -0
- package/dist/chunks/serverLog-BKaKjjc4.mjs +137 -0
- package/dist/chunks/session-B-dTEjeG.mjs +253 -0
- package/dist/chunks/sessionActivity-Ch7xuQ_o.mjs +43 -0
- package/dist/chunks/spaceDeployment-J2IMLfij.mjs +76 -0
- package/dist/chunks/stage-y6deE9LJ.mjs +345 -0
- package/dist/chunks/supervisor-Dh34v1vq.mjs +117 -0
- package/dist/chunks/tail-D-USrZIR.mjs +55 -0
- package/dist/chunks/tokens-CBd5tXut.mjs +262 -0
- package/dist/data/index.d.ts +2 -0
- package/dist/data/index.mjs +68 -0
- package/dist/data/projectData.d.ts +21 -0
- package/dist/deployment/hostDeployment.d.ts +8 -0
- package/dist/deployment/index.d.ts +3 -0
- package/dist/deployment/index.mjs +19 -0
- package/dist/deployment/spaceDeployment.d.ts +11 -0
- package/dist/engine/index.d.ts +2 -0
- package/dist/engine/index.mjs +1 -0
- package/dist/engine/page.d.ts +49 -0
- package/dist/engine/rsc.d.ts +32 -0
- package/dist/files/atomicFile.d.ts +10 -0
- package/dist/files/index.d.ts +1 -0
- package/dist/files/index.mjs +32 -0
- package/dist/http/bearer.d.ts +5 -0
- package/dist/http/buildResponseHelpers.d.ts +23 -0
- package/dist/http/closeOnSignals.d.ts +28 -0
- package/dist/http/compress.d.ts +20 -0
- package/dist/http/dispatcher.d.ts +15 -0
- package/dist/http/drain.d.ts +18 -0
- package/dist/http/fleet/channel.d.ts +103 -0
- package/dist/http/fleet/link.d.ts +28 -0
- package/dist/http/fleet/role.d.ts +46 -0
- package/dist/http/fleet/supervisor.d.ts +29 -0
- package/dist/http/freePort.d.ts +24 -0
- package/dist/http/health.d.ts +21 -0
- package/dist/http/index.d.ts +48 -0
- package/dist/http/index.mjs +1313 -0
- package/dist/http/middlewares/auth.d.ts +2 -0
- package/dist/http/middlewares/basicAuth.d.ts +6 -0
- package/dist/http/mimeTypes.d.ts +13 -0
- package/dist/http/navigation.d.ts +14 -0
- package/dist/http/onAbort.d.ts +12 -0
- package/dist/http/probes.d.ts +4 -0
- package/dist/http/requestParser.d.ts +22 -0
- package/dist/http/runMiddlewares.d.ts +6 -0
- package/dist/http/securityHeaders.d.ts +18 -0
- package/dist/http/server.d.ts +39 -0
- package/dist/http/socketResponse.d.ts +18 -0
- package/dist/http/sse.d.ts +26 -0
- package/dist/http/stages/crossSiteWrites.d.ts +24 -0
- package/dist/http/stages/health.d.ts +11 -0
- package/dist/http/stages/middlewares.d.ts +3 -0
- package/dist/http/stages/static.d.ts +4 -0
- package/dist/http/staticFiles.d.ts +3 -0
- package/dist/http/stopping.d.ts +11 -0
- package/dist/http/transports.d.ts +31 -0
- package/dist/http/types.d.ts +29 -0
- package/dist/http/unusedPort.d.ts +10 -0
- package/dist/http/webExchange.d.ts +18 -0
- package/dist/http/wsFrame.d.ts +3 -0
- package/dist/identity/accounts.d.ts +278 -0
- package/dist/identity/authorize.d.ts +96 -0
- package/dist/identity/credentials.d.ts +40 -0
- package/dist/identity/csrf.d.ts +139 -0
- package/dist/identity/debugAuthorization.d.ts +24 -0
- package/dist/identity/domains.d.ts +41 -0
- package/dist/identity/identity.d.ts +119 -0
- package/dist/identity/index.d.ts +21 -0
- package/dist/identity/index.mjs +731 -0
- package/dist/identity/passwords.d.ts +15 -0
- package/dist/identity/previewToken.d.ts +21 -0
- package/dist/identity/requestIdentity.d.ts +14 -0
- package/dist/identity/scopes.d.ts +56 -0
- package/dist/identity/session.d.ts +185 -0
- package/dist/identity/sessionActivity.d.ts +11 -0
- package/dist/identity/spaceTokens.d.ts +174 -0
- package/dist/index.d.ts +17 -0
- package/dist/index.mjs +1 -0
- package/dist/log/index.d.ts +3 -0
- package/dist/log/index.mjs +3 -0
- package/dist/log/serverLog.d.ts +49 -0
- package/dist/log/tail.d.ts +43 -0
- package/dist/mysql/accounts.d.ts +4 -0
- package/dist/mysql/admin.d.ts +58 -0
- package/dist/mysql/config.d.ts +82 -0
- package/dist/mysql/identities.d.ts +35 -0
- package/dist/mysql/index.d.ts +7 -0
- package/dist/mysql/index.mjs +1203 -0
- package/dist/mysql/pool.d.ts +3 -0
- package/dist/mysql/query.d.ts +12 -0
- package/dist/mysql/schema.d.ts +43 -0
- package/dist/mysql/sessions.d.ts +23 -0
- package/dist/mysql/spaceTokens.d.ts +11 -0
- package/dist/mysql/store.d.ts +66 -0
- package/dist/outbound/index.d.ts +4 -0
- package/dist/outbound/index.mjs +314 -0
- package/dist/outbound/inside.d.ts +36 -0
- package/dist/outbound/outboundGuard.d.ts +69 -0
- package/dist/pubsub/index.d.ts +3 -0
- package/dist/pubsub/index.mjs +76 -0
- package/dist/pubsub/memoryPubSub.d.ts +10 -0
- package/dist/pubsub/redisPubSub.d.ts +24 -0
- package/dist/stats/index.d.ts +9 -0
- package/dist/stats/index.mjs +228 -0
- package/dist/stats/load.d.ts +31 -0
- package/dist/stats/memory.d.ts +20 -0
- package/dist/stats/pools.d.ts +15 -0
- package/dist/stats/recorder.d.ts +34 -0
- package/dist/stats/stage.d.ts +15 -0
- package/dist/stats/types.d.ts +309 -0
- package/dist/testing/certificates.d.ts +21 -0
- package/dist/testing/fleet.d.ts +28 -0
- package/dist/testing/goneRuns.d.ts +5 -0
- package/dist/testing/index.d.ts +5 -0
- package/dist/testing/index.mjs +270 -0
- package/dist/testing/keys.d.ts +2 -0
- package/dist/testing/runNames.d.ts +10 -0
- package/dist/tokens/index.d.ts +2 -0
- package/dist/tokens/index.mjs +1 -0
- package/dist/tokens/tokens.d.ts +190 -0
- package/dist/types/adapters.d.ts +388 -0
- package/dist/types/config.d.ts +240 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/index.mjs +1 -0
- package/dist/types/log.d.ts +119 -0
- package/dist/types/oauth.d.ts +246 -0
- package/dist/types/pipeline.d.ts +239 -0
- package/package.json +67 -3
|
@@ -0,0 +1,731 @@
|
|
|
1
|
+
import { i as csrfFailureMessage, n as createCsrf, r as crossSiteRequest, t as carrierOf } from "../chunks/csrf-BLWcaYOV.mjs";
|
|
2
|
+
import { n as SCOPES, r as authFailureMessage, t as OFF_BROWSER_SPACE_SCOPES } from "../chunks/scopes-Co6ZjhAm.mjs";
|
|
3
|
+
import { a as verifyPassword, i as hashPassword, n as activityDue, r as generateToken, t as SESSION_ACTIVITY_RESOLUTION_SECONDS } from "../chunks/sessionActivity-Ch7xuQ_o.mjs";
|
|
4
|
+
import { _ as sessionHintValue, a as createSessionCookies, b as writeRenewalGuard, c as parseSessionHint, d as readRenewalGuard, f as readSessionHint, g as sessionHintCookieName, h as sessionCookieParams, i as clearSessionCookies, l as readFlowCookie, m as registrableDomain, n as appendCookies, o as isLocalHost, p as readSessionToken, r as clearFlowCookie, s as isPrivateNetworkHost, t as RENEWAL_GUARD_SECONDS, u as readRefreshToken, v as sessionReturnTarget, x as writeSessionCookies, y as writeFlowCookie } from "../chunks/session-B-dTEjeG.mjs";
|
|
5
|
+
// src/identity/authorize.ts
|
|
6
|
+
var matches = (path, matchers) => matchers.some((matcher) => {
|
|
7
|
+
if (matcher instanceof RegExp) return matcher.test(path);
|
|
8
|
+
return typeof matcher === "function" ? matcher(path) : matcher === path;
|
|
9
|
+
});
|
|
10
|
+
var requirementFor = (policy, path) => policy.rules.find((rule) => matches(path, rule.match))?.requirement ?? policy.fallback;
|
|
11
|
+
/**
|
|
12
|
+
* Decides whether a request may proceed, and with what identity — the same decision on every transport, which is
|
|
13
|
+
* the point of it living here rather than inside one framework's middleware. Callers bind it to their own: Express
|
|
14
|
+
* puts the result on `req` and answers 401 itself, this server's pipeline does the same with its own response.
|
|
15
|
+
*/
|
|
16
|
+
var createAuthorizer = (identity, policy) => async (carrier, path) => {
|
|
17
|
+
const requirement = requirementFor(policy, path);
|
|
18
|
+
if (requirement === "public") return { ok: true };
|
|
19
|
+
const [actorResult, grantResult] = await Promise.all([identity.resolveActor(carrier), identity.resolveGrant(carrier)]);
|
|
20
|
+
const actor = actorResult.ok && actorResult.actor.verified ? actorResult.actor : void 0;
|
|
21
|
+
const grant = grantResult.ok ? grantResult.grant : void 0;
|
|
22
|
+
if ((requirement === "grant" || requirement === "grant+actor") && !grant) return {
|
|
23
|
+
ok: false,
|
|
24
|
+
status: 401,
|
|
25
|
+
reason: grantResult.ok ? "missing" : grantResult.reason
|
|
26
|
+
};
|
|
27
|
+
if (requirement === "actor" || requirement === "grant+actor") {
|
|
28
|
+
if (!actorResult.ok) return {
|
|
29
|
+
ok: false,
|
|
30
|
+
status: 401,
|
|
31
|
+
reason: actorResult.reason
|
|
32
|
+
};
|
|
33
|
+
if (!actor) return {
|
|
34
|
+
ok: false,
|
|
35
|
+
status: 401,
|
|
36
|
+
reason: "inactive"
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
return {
|
|
40
|
+
ok: true,
|
|
41
|
+
actor,
|
|
42
|
+
grant
|
|
43
|
+
};
|
|
44
|
+
};
|
|
45
|
+
/**
|
|
46
|
+
* A global capability, checked off the actor the guard already resolved — no query. This is the whole of RBAC that
|
|
47
|
+
* applies outside a space: platform-wide routes rather than "may you touch this space", which is `identity.can()` and
|
|
48
|
+
* needs the membership half too.
|
|
49
|
+
*
|
|
50
|
+
* An answer rather than a middleware, so it reads the same from any host. The distinction it exists to make is 401
|
|
51
|
+
* against 403: "nobody is here" and "you are here and this is not yours" are different facts, and collapsing them
|
|
52
|
+
* tells a signed-in caller to sign in again.
|
|
53
|
+
*/
|
|
54
|
+
var checkPermission = (actor, permission) => {
|
|
55
|
+
if (!actor?.id) return {
|
|
56
|
+
ok: false,
|
|
57
|
+
status: 401,
|
|
58
|
+
error: "Not authenticated"
|
|
59
|
+
};
|
|
60
|
+
if (!actor.permissions.includes(permission)) return {
|
|
61
|
+
ok: false,
|
|
62
|
+
status: 403,
|
|
63
|
+
error: "Insufficient permissions"
|
|
64
|
+
};
|
|
65
|
+
return { ok: true };
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* The space half: may this actor act on this space at all, and is being its owner required?
|
|
69
|
+
*
|
|
70
|
+
* The answer that matters is the middle one. A non-member gets **404, not 403** — telling a stranger "you may not
|
|
71
|
+
* touch this space" confirms the space exists, and whether a given slug belongs to somebody is not a fact an
|
|
72
|
+
* outsider gets to establish by asking. Owners and members are told apart afterwards, because by then the caller has
|
|
73
|
+
* already proved they belong there and 403 gives away nothing.
|
|
74
|
+
*
|
|
75
|
+
* Resolving the membership is the deployment's — its tables, and whether a route names a space by id or by slug.
|
|
76
|
+
*/
|
|
77
|
+
var checkSpaceAccess = (actor, membership, { owner = false } = {}) => {
|
|
78
|
+
if (!actor?.id) return {
|
|
79
|
+
ok: false,
|
|
80
|
+
status: 401,
|
|
81
|
+
error: "Not authenticated"
|
|
82
|
+
};
|
|
83
|
+
if (!membership) return {
|
|
84
|
+
ok: false,
|
|
85
|
+
status: 404,
|
|
86
|
+
error: "Space not found"
|
|
87
|
+
};
|
|
88
|
+
if (owner && !membership.isOwner) return {
|
|
89
|
+
ok: false,
|
|
90
|
+
status: 403,
|
|
91
|
+
error: "Insufficient permissions"
|
|
92
|
+
};
|
|
93
|
+
return { ok: true };
|
|
94
|
+
};
|
|
95
|
+
// src/identity/credentials.ts
|
|
96
|
+
var parseCookieHeader = (cookieHeader) => {
|
|
97
|
+
const cookies = {};
|
|
98
|
+
for (const part of cookieHeader.split(";")) {
|
|
99
|
+
const eqIndex = part.indexOf("=");
|
|
100
|
+
if (eqIndex === -1) continue;
|
|
101
|
+
cookies[part.slice(0, eqIndex).trim()] = decodeURIComponent(part.slice(eqIndex + 1).trim());
|
|
102
|
+
}
|
|
103
|
+
return cookies;
|
|
104
|
+
};
|
|
105
|
+
var readCookies = (carrier) => {
|
|
106
|
+
if (carrier.cookies) return carrier.cookies;
|
|
107
|
+
const cookieHeader = carrier.headers.cookie;
|
|
108
|
+
return cookieHeader ? parseCookieHeader(cookieHeader) : {};
|
|
109
|
+
};
|
|
110
|
+
var headerValue = (value) => (Array.isArray(value) ? value[0] : value)?.trim() ?? "";
|
|
111
|
+
var bearer = (carrier) => headerValue(carrier.headers.authorization).replace(/^Bearer\s+/i, "");
|
|
112
|
+
var unique = (candidates) => [...new Set(candidates.filter(Boolean))];
|
|
113
|
+
/**
|
|
114
|
+
* Where a credential of each kind is allowed to ride.
|
|
115
|
+
*
|
|
116
|
+
* `Authorization: Bearer` carries a session token on one role and a space token on another, so it is a candidate for
|
|
117
|
+
* both and the typed verifier decides which it actually is — that is what `scope` is for. Trying the wrong kind
|
|
118
|
+
* costs nothing: it fails on its scope claim before any database is touched.
|
|
119
|
+
*/
|
|
120
|
+
/** The query parameter a space token rides in: how a page on a host serving many spaces names the one it is. */
|
|
121
|
+
var SPACE_TOKEN_PARAM = "access-token";
|
|
122
|
+
var createCarriers = (sessionCookieName) => ({
|
|
123
|
+
userTokenCandidates: (carrier) => unique([
|
|
124
|
+
headerValue(carrier.headers["plitzi-access-token"]),
|
|
125
|
+
bearer(carrier),
|
|
126
|
+
readCookies(carrier)[sessionCookieName(carrier.hostname)] ?? ""
|
|
127
|
+
]),
|
|
128
|
+
spaceTokenCandidates: (carrier) => {
|
|
129
|
+
const queryToken = carrier.query?.[SPACE_TOKEN_PARAM];
|
|
130
|
+
return unique([
|
|
131
|
+
headerValue(carrier.headers["x-access-token"]),
|
|
132
|
+
bearer(carrier),
|
|
133
|
+
typeof queryToken === "string" ? queryToken : ""
|
|
134
|
+
]);
|
|
135
|
+
}
|
|
136
|
+
});
|
|
137
|
+
/**
|
|
138
|
+
* The origin the caller claims to be presenting from — the `Origin` header, and nothing else. Distinct from this
|
|
139
|
+
* server's own origin (see `requestOrigin` in the request parser): this one is the claim a credential's domain
|
|
140
|
+
* binding is checked against.
|
|
141
|
+
*
|
|
142
|
+
* Empty when the header is absent, which is a fact the caller downstream has to be able to see. This used to fall
|
|
143
|
+
* back to `carrier.hostname`, and that fallback could only ever deny: a hostname carries no scheme, so it matched no
|
|
144
|
+
* entry in any origins list, and every server-to-server caller — a self-hosted deployment reading its own space
|
|
145
|
+
* through `createCloudAdapters`, most of all — was refused with `origin-not-allowed` while the branch written to
|
|
146
|
+
* handle a missing Origin was unreachable.
|
|
147
|
+
*/
|
|
148
|
+
var presentedOrigin = (carrier) => headerValue(carrier.headers.origin);
|
|
149
|
+
// src/identity/debugAuthorization.ts
|
|
150
|
+
/**
|
|
151
|
+
* Whether a page — and what its flows did — may be debugged. One rule for the render and for every run it reports.
|
|
152
|
+
*
|
|
153
|
+
* The server decides first, through `debugMode`: set, it speaks for every space, and `false` is a refusal no space can
|
|
154
|
+
* turn around. Left unset, a development server authorizes it, and so does a space whose own settings switched
|
|
155
|
+
* `debugMode` on. The settings are what this server loaded, never anything the request carries.
|
|
156
|
+
*
|
|
157
|
+
* A page nobody authorized is told nothing: not the steps behind it, not even that a flow ran.
|
|
158
|
+
*/
|
|
159
|
+
var authorizesDebugging = (config, settings) => config.debugMode ?? (config.devMode === true || settings?.debugMode === true);
|
|
160
|
+
/**
|
|
161
|
+
* The same rule, for a request that has not loaded the space yet.
|
|
162
|
+
*
|
|
163
|
+
* The settings are read only when the server left the answer to the space. A space that cannot be read authorizes
|
|
164
|
+
* nothing: debugging is the one thing about a page that fails closed.
|
|
165
|
+
*/
|
|
166
|
+
var resolveDebugAuthorization = async (config, loadSettings) => {
|
|
167
|
+
if (config.debugMode !== void 0 || config.devMode === true) return authorizesDebugging(config, void 0);
|
|
168
|
+
try {
|
|
169
|
+
return authorizesDebugging(config, await loadSettings());
|
|
170
|
+
} catch {
|
|
171
|
+
return false;
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
// src/identity/domains.ts
|
|
175
|
+
/**
|
|
176
|
+
* Declared domains are stored and signed as full origins (`https://site.example.com`) while a request host is bare
|
|
177
|
+
* (`site.example.com`), so both sides are reduced to a hostname before being compared. A non-web value still reduces
|
|
178
|
+
* to something — `plitzi-desktop` to itself, `chrome-extension://…` to its authority — but neither is a host a
|
|
179
|
+
* request ever reports, so it never matches.
|
|
180
|
+
*/
|
|
181
|
+
var hostnameOf = (value) => {
|
|
182
|
+
const trimmed = value.trim().toLowerCase();
|
|
183
|
+
if (!trimmed) return "";
|
|
184
|
+
try {
|
|
185
|
+
return new URL(trimmed.includes("://") ? trimmed : `https://${trimmed}`).hostname;
|
|
186
|
+
} catch {
|
|
187
|
+
return "";
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
/** The wildcard a space sets when its embed target is genuinely unknown. Named so an API can warn about it. */
|
|
191
|
+
var ANY_DOMAIN = "*";
|
|
192
|
+
/**
|
|
193
|
+
* May a token declaring `origins` be presented on `host`?
|
|
194
|
+
*
|
|
195
|
+
* `platformHosts` are this deployment's own — its builder, its renderer, its MCP endpoint — which serve first-party
|
|
196
|
+
* traffic for every space and are therefore valid destinations for any token, whatever domains it declares. They are
|
|
197
|
+
* passed in rather than read from configuration here because only the deployment knows what it runs.
|
|
198
|
+
*/
|
|
199
|
+
var domainAllowed = (host, origins, platformHosts = []) => {
|
|
200
|
+
if (origins.includes("*")) return true;
|
|
201
|
+
const hostname = hostnameOf(host);
|
|
202
|
+
if (!hostname) return false;
|
|
203
|
+
return [...platformHosts.map(hostnameOf), ...origins.map(hostnameOf)].filter(Boolean).includes(hostname);
|
|
204
|
+
};
|
|
205
|
+
/**
|
|
206
|
+
* User input arrives as whatever someone typed — `example.com`, `https://example.com/`, `HTTPS://Example.com/x`. It
|
|
207
|
+
* is stored as a canonical origin so the signed claim, the stored column and the comparison all agree.
|
|
208
|
+
*/
|
|
209
|
+
var normalizeDomain = (value) => {
|
|
210
|
+
const trimmed = value.trim();
|
|
211
|
+
if (trimmed === "*") return "*";
|
|
212
|
+
if (!hostnameOf(trimmed)) return;
|
|
213
|
+
try {
|
|
214
|
+
const url = new URL(trimmed.includes("://") ? trimmed : `https://${trimmed}`);
|
|
215
|
+
return `${url.protocol}//${url.host}`;
|
|
216
|
+
} catch {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
};
|
|
220
|
+
/**
|
|
221
|
+
* Who may put this space in an iframe, as CSP `frame-ancestors` sources.
|
|
222
|
+
*
|
|
223
|
+
* The deployment's own hosts are the floor — a builder previews every space in one — and a space widens it with the
|
|
224
|
+
* domains its owner declared. `*` opts out entirely. Without this a published space is framable from any site on the
|
|
225
|
+
* web, which is how one customer wraps another's space inside their own page and passes it off as theirs.
|
|
226
|
+
*
|
|
227
|
+
* Unlike the token's domain binding, this one is enforced by the browser, which is why it is worth stating even
|
|
228
|
+
* though a determined caller can ignore the header: it stops the attack that needs a real visitor's browser.
|
|
229
|
+
*/
|
|
230
|
+
var frameAncestors = (declared, platformHosts = []) => {
|
|
231
|
+
if (declared.includes("*")) return ["*"];
|
|
232
|
+
return [.../* @__PURE__ */ new Set([
|
|
233
|
+
"'self'",
|
|
234
|
+
...platformHosts,
|
|
235
|
+
...declared
|
|
236
|
+
])];
|
|
237
|
+
};
|
|
238
|
+
/**
|
|
239
|
+
* Which origins a request bearing this grant may be answered for.
|
|
240
|
+
*
|
|
241
|
+
* A space is reachable from the origins its own token declares, plus this deployment's own apps; `*` means anywhere,
|
|
242
|
+
* and a grant that declares nothing at all falls back to the deployment's own unless it allows anonymous origins.
|
|
243
|
+
* Returning `true` means "reflect whatever asked", which is what a CORS layer wants for the wildcard case.
|
|
244
|
+
*/
|
|
245
|
+
var corsOrigins = (declared, platformOrigins = [], allowWithoutOrigin = false) => {
|
|
246
|
+
const origins = declared ?? [];
|
|
247
|
+
if (origins.includes("*") || origins.length === 0 && allowWithoutOrigin) return true;
|
|
248
|
+
return [.../* @__PURE__ */ new Set([...platformOrigins, ...origins])];
|
|
249
|
+
};
|
|
250
|
+
// src/identity/identity.ts
|
|
251
|
+
var createIdentity = ({ tokens, carriers, adapters, config = {}, presentedOrigin }) => {
|
|
252
|
+
const { platformHosts = [], platformOrigins = [], allowWithoutOrigin = false, log } = config;
|
|
253
|
+
/**
|
|
254
|
+
* The single user-token validator. Every transport goes through it, so there is one expiry rule and one status
|
|
255
|
+
* rule — the alternative, which this replaced, was a variant per role where only one of them checked `status`.
|
|
256
|
+
*/
|
|
257
|
+
const resolveActorFromToken = async (token) => {
|
|
258
|
+
const verified = tokens.verifyUserToken(token);
|
|
259
|
+
if (!verified.ok) return verified;
|
|
260
|
+
const actor = await adapters.findAccountByToken(token);
|
|
261
|
+
if (!actor || String(actor.id) !== verified.payload.sub) return {
|
|
262
|
+
ok: false,
|
|
263
|
+
reason: "revoked"
|
|
264
|
+
};
|
|
265
|
+
if (!actor.expiresAt || actor.expiresAt < Math.round(Date.now() / 1e3)) return {
|
|
266
|
+
ok: false,
|
|
267
|
+
reason: "expired"
|
|
268
|
+
};
|
|
269
|
+
const actingId = Number(verified.payload.act?.sub);
|
|
270
|
+
return {
|
|
271
|
+
ok: true,
|
|
272
|
+
actor: Number.isInteger(actingId) ? {
|
|
273
|
+
...actor,
|
|
274
|
+
impersonatedBy: actingId
|
|
275
|
+
} : actor
|
|
276
|
+
};
|
|
277
|
+
};
|
|
278
|
+
const resolveActor = async (carrier) => {
|
|
279
|
+
const candidates = carriers.userTokenCandidates(carrier);
|
|
280
|
+
if (candidates.length === 0) return {
|
|
281
|
+
ok: false,
|
|
282
|
+
reason: "missing"
|
|
283
|
+
};
|
|
284
|
+
let lastFailure = "missing";
|
|
285
|
+
for (const candidate of candidates) {
|
|
286
|
+
const result = await resolveActorFromToken(candidate);
|
|
287
|
+
if (result.ok) return result;
|
|
288
|
+
if (result.reason !== "wrong-type") lastFailure = result.reason;
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
ok: false,
|
|
292
|
+
reason: lastFailure
|
|
293
|
+
};
|
|
294
|
+
};
|
|
295
|
+
const originAllowed = (origin, origins) => origins.includes("*") || [...platformOrigins, ...origins].includes(origin);
|
|
296
|
+
const resolveGrantFromToken = async (token, origin, { skipOrigin = false, host } = {}) => {
|
|
297
|
+
const verified = tokens.verifySpaceToken(token);
|
|
298
|
+
if (!verified.ok) return verified;
|
|
299
|
+
const { spaceId, spaceScope: scope, origins } = verified.payload;
|
|
300
|
+
const stored = await adapters.findSpaceToken?.(token);
|
|
301
|
+
if (!stored || stored.spaceId !== spaceId) return {
|
|
302
|
+
ok: false,
|
|
303
|
+
reason: "revoked"
|
|
304
|
+
};
|
|
305
|
+
if (stored.scope !== scope) return {
|
|
306
|
+
ok: false,
|
|
307
|
+
reason: "scope-mismatch"
|
|
308
|
+
};
|
|
309
|
+
const grant = {
|
|
310
|
+
spaceId,
|
|
311
|
+
scope,
|
|
312
|
+
userId: stored.userId,
|
|
313
|
+
...stored.client === void 0 ? {} : { client: stored.client },
|
|
314
|
+
origins
|
|
315
|
+
};
|
|
316
|
+
if (scope === "render" && host !== void 0 && !domainAllowed(host, origins, platformHosts)) {
|
|
317
|
+
log?.("Access Not Authorized - Domain", {
|
|
318
|
+
spaceId,
|
|
319
|
+
host,
|
|
320
|
+
origins
|
|
321
|
+
});
|
|
322
|
+
return {
|
|
323
|
+
ok: false,
|
|
324
|
+
reason: "domain-not-allowed"
|
|
325
|
+
};
|
|
326
|
+
}
|
|
327
|
+
if (skipOrigin) return {
|
|
328
|
+
ok: true,
|
|
329
|
+
grant
|
|
330
|
+
};
|
|
331
|
+
if (origins.length === 0 && !allowWithoutOrigin) {
|
|
332
|
+
log?.("Access Not Authorized - Origin", {
|
|
333
|
+
spaceId,
|
|
334
|
+
allowWithoutOrigin: false
|
|
335
|
+
});
|
|
336
|
+
return {
|
|
337
|
+
ok: false,
|
|
338
|
+
reason: "origin-not-allowed"
|
|
339
|
+
};
|
|
340
|
+
}
|
|
341
|
+
/**
|
|
342
|
+
* No `Origin` means no browser made this request — and what that is worth depends entirely on whether the
|
|
343
|
+
* credential was a secret to begin with.
|
|
344
|
+
*
|
|
345
|
+
* A **public** one — `render`, which ships in the clear inside every published page — is held to the allowlist
|
|
346
|
+
* even so, and therefore refused here. The check only ever worked because a BROWSER is made to state where it is
|
|
347
|
+
* presenting from; a client that simply omits the header is not proving anything, it is declining to be asked. If
|
|
348
|
+
* that were enough, a render key lifted from someone's page would be enough to serve a byte-identical clone of
|
|
349
|
+
* their site from any server, and the domain binding above would not stop it: a self-hosted renderer addresses
|
|
350
|
+
* this platform's own host, which is allowed by construction.
|
|
351
|
+
*
|
|
352
|
+
* A **secret** one — `host` for a server that renders the space as its own, `agent` for a consented integration —
|
|
353
|
+
* has nothing to prove by an origin, because possessing it is the proof. That is what `space:host` is FOR: it is
|
|
354
|
+
* shown once, never embedded, and revocable on its own row, so self-hosting no longer has to be paid for by
|
|
355
|
+
* making the public key work off-browser.
|
|
356
|
+
*/
|
|
357
|
+
if (!origin) {
|
|
358
|
+
if (OFF_BROWSER_SPACE_SCOPES.includes(scope) || allowWithoutOrigin) return {
|
|
359
|
+
ok: true,
|
|
360
|
+
grant
|
|
361
|
+
};
|
|
362
|
+
log?.("Access Not Authorized - Origin", {
|
|
363
|
+
spaceId,
|
|
364
|
+
scope,
|
|
365
|
+
reason: "public token presented with no Origin"
|
|
366
|
+
});
|
|
367
|
+
return {
|
|
368
|
+
ok: false,
|
|
369
|
+
reason: "origin-not-allowed"
|
|
370
|
+
};
|
|
371
|
+
}
|
|
372
|
+
if (!originAllowed(origin, origins)) {
|
|
373
|
+
log?.("Access Not Authorized - Origin", {
|
|
374
|
+
spaceId,
|
|
375
|
+
origin,
|
|
376
|
+
origins
|
|
377
|
+
});
|
|
378
|
+
return {
|
|
379
|
+
ok: false,
|
|
380
|
+
reason: "origin-not-allowed"
|
|
381
|
+
};
|
|
382
|
+
}
|
|
383
|
+
return {
|
|
384
|
+
ok: true,
|
|
385
|
+
grant
|
|
386
|
+
};
|
|
387
|
+
};
|
|
388
|
+
const resolveGrant = async (carrier, options = {}) => {
|
|
389
|
+
const candidates = carriers.spaceTokenCandidates(carrier);
|
|
390
|
+
if (candidates.length === 0) return {
|
|
391
|
+
ok: false,
|
|
392
|
+
reason: "missing"
|
|
393
|
+
};
|
|
394
|
+
const origin = presentedOrigin(carrier);
|
|
395
|
+
const host = options.host ?? carrier.hostname;
|
|
396
|
+
let lastFailure = "missing";
|
|
397
|
+
for (const candidate of candidates) {
|
|
398
|
+
const result = await resolveGrantFromToken(candidate, origin, {
|
|
399
|
+
...options,
|
|
400
|
+
host
|
|
401
|
+
});
|
|
402
|
+
if (result.ok) return result;
|
|
403
|
+
if (result.reason !== "wrong-type") lastFailure = result.reason;
|
|
404
|
+
}
|
|
405
|
+
return {
|
|
406
|
+
ok: false,
|
|
407
|
+
reason: lastFailure
|
|
408
|
+
};
|
|
409
|
+
};
|
|
410
|
+
/**
|
|
411
|
+
* May this actor do this, here?
|
|
412
|
+
*
|
|
413
|
+
* Both halves are required. The global capability says the account is allowed to do this kind of thing at all;
|
|
414
|
+
* the space role says it may do it *in this space*. A global permission is a property of the account and never an
|
|
415
|
+
* assertion about a particular space, which is why neither half alone is an answer.
|
|
416
|
+
*/
|
|
417
|
+
const can = async (actor, spaceId, permission) => {
|
|
418
|
+
if (!actor.verified || !actor.permissions.includes(permission)) return false;
|
|
419
|
+
const membership = await adapters.findMembership?.(actor.id, spaceId);
|
|
420
|
+
return membership !== void 0 && membership.permissions.includes(permission);
|
|
421
|
+
};
|
|
422
|
+
/**
|
|
423
|
+
* An `agent` grant carries no session — its authority is the member who consented, resolved live, so that losing
|
|
424
|
+
* access to the space revokes every agent token that member authorised.
|
|
425
|
+
*/
|
|
426
|
+
const grantCan = async (grant, permission) => {
|
|
427
|
+
if (grant.scope !== "agent" || !grant.userId) return false;
|
|
428
|
+
const membership = await adapters.findMembership?.(grant.userId, grant.spaceId);
|
|
429
|
+
return membership !== void 0 && membership.permissions.includes(permission);
|
|
430
|
+
};
|
|
431
|
+
return {
|
|
432
|
+
resolveActor,
|
|
433
|
+
resolveActorFromToken,
|
|
434
|
+
resolveGrant,
|
|
435
|
+
resolveGrantFromToken,
|
|
436
|
+
can,
|
|
437
|
+
grantCan
|
|
438
|
+
};
|
|
439
|
+
};
|
|
440
|
+
// src/identity/previewToken.ts
|
|
441
|
+
var PREVIEW_TOKEN_PARAM = "__pt";
|
|
442
|
+
/**
|
|
443
|
+
* Where a REUSABLE draft token is remembered for the rest of the visit.
|
|
444
|
+
*
|
|
445
|
+
* The query param alone previews one URL, which is all a screenshot ever needed. A person iterating does more than
|
|
446
|
+
* look at one URL: they follow a link, the SDK asks `/_rsc` for fresh data, they press back. Every one of those is a
|
|
447
|
+
* request without the param, and answering the saved space to a browser that is looking at a draft is the kind of
|
|
448
|
+
* confusion that gets reported as "the preview randomly reverts".
|
|
449
|
+
*
|
|
450
|
+
* `HttpOnly` because nothing in the page has any use for it, and `SameSite=Lax` so another site cannot cause a draft
|
|
451
|
+
* to be resolved in a visitor's browser. It is set only for a token the store minted as reusable.
|
|
452
|
+
*/
|
|
453
|
+
var PREVIEW_COOKIE = "plitzi_draft";
|
|
454
|
+
var cookieValue = (header, name) => {
|
|
455
|
+
if (!header) return;
|
|
456
|
+
for (const part of header.split(";")) {
|
|
457
|
+
const separator = part.indexOf("=");
|
|
458
|
+
if (separator > 0 && part.slice(0, separator).trim() === name) return decodeURIComponent(part.slice(separator + 1).trim());
|
|
459
|
+
}
|
|
460
|
+
};
|
|
461
|
+
/**
|
|
462
|
+
* The draft this request is looking at, whichever way it says so.
|
|
463
|
+
*
|
|
464
|
+
* The query param wins: it is how a session is STARTED, and re-minting while an older one is still in the cookie has
|
|
465
|
+
* to answer the new draft or the loop shows stale work.
|
|
466
|
+
*/
|
|
467
|
+
var readDraftToken = (req) => {
|
|
468
|
+
return req.query["__pt"] || cookieValue(req.headers.cookie, "plitzi_draft");
|
|
469
|
+
};
|
|
470
|
+
// src/identity/spaceTokens.ts
|
|
471
|
+
var ROTATION_WARNING = "The previous token stopped working. Every site embedding it must be redeployed.";
|
|
472
|
+
/**
|
|
473
|
+
* Said once, at the only moment it can be acted on. A host credential is the space's read access WITHOUT the origin
|
|
474
|
+
* check that makes the public one safe to publish, so what keeps it from being a way to clone the space is that it
|
|
475
|
+
* stays secret — and a caller who does not know it is never shown again will paste it into a page.
|
|
476
|
+
*/
|
|
477
|
+
var HOST_SECRET_WARNING = "Store this now — it is not shown again. Unlike the public token it is NOT safe to embed in a page or commit to a public repository: anyone holding it can serve this space from their own server. Revoke it if it leaks.";
|
|
478
|
+
var DAY_SECONDS = 86400;
|
|
479
|
+
var now = () => Math.floor(Date.now() / 1e3);
|
|
480
|
+
var notFound = {
|
|
481
|
+
ok: false,
|
|
482
|
+
status: 404,
|
|
483
|
+
body: { error: "Token not found" }
|
|
484
|
+
};
|
|
485
|
+
/**
|
|
486
|
+
* The lifecycle of a space's own credentials, over whatever stores them.
|
|
487
|
+
*
|
|
488
|
+
* Minting one is `tokens.generateSpaceToken`; everything around it is here, and it is all rule rather than storage:
|
|
489
|
+
* a credential whose claims changed is a **different credential**, so every edit below re-mints and the previous one
|
|
490
|
+
* stops working the instant it returns. Saying that once, in one place, is the point — a self-hoster who has to
|
|
491
|
+
* rediscover it discovers it as a published site that went dark.
|
|
492
|
+
*/
|
|
493
|
+
var createSpaceTokenApi = ({ tokens, adapters }) => {
|
|
494
|
+
/** Never empty: a credential with no origins is one that works nowhere. */
|
|
495
|
+
const withFloor = (domains, defaults) => {
|
|
496
|
+
if (domains.includes("*")) return ["*"];
|
|
497
|
+
const merged = [.../* @__PURE__ */ new Set([...defaults, ...domains])];
|
|
498
|
+
return merged.length > 0 ? merged : ["*"];
|
|
499
|
+
};
|
|
500
|
+
const remint = async (record, context, changes = {}) => {
|
|
501
|
+
const origins = withFloor(changes.origins ?? record.origins, context.defaultDomains);
|
|
502
|
+
const expiresAt = changes.expiresAt === void 0 ? record.expiresAt : changes.expiresAt;
|
|
503
|
+
const token = tokens.generateSpaceToken(context.spaceId, origins, record.scope, { expiresAt });
|
|
504
|
+
await adapters.save(record.id, {
|
|
505
|
+
token,
|
|
506
|
+
origins,
|
|
507
|
+
expiresAt
|
|
508
|
+
});
|
|
509
|
+
return {
|
|
510
|
+
token,
|
|
511
|
+
origins,
|
|
512
|
+
expiresAt
|
|
513
|
+
};
|
|
514
|
+
};
|
|
515
|
+
return {
|
|
516
|
+
/**
|
|
517
|
+
* The space's public credential, rotated in place when it no longer verifies. Rotating on *outdated* and not only
|
|
518
|
+
* on expired is what this endpoint exists for: a site stranded on a credential from a previous token version would
|
|
519
|
+
* otherwise have no way back — nothing else can hand it a working one.
|
|
520
|
+
*/
|
|
521
|
+
async read(context) {
|
|
522
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
523
|
+
if (!record) return notFound;
|
|
524
|
+
if (!tokens.needsRotation(record.token)) return {
|
|
525
|
+
ok: true,
|
|
526
|
+
body: {
|
|
527
|
+
token: record.token,
|
|
528
|
+
domains: record.origins
|
|
529
|
+
}
|
|
530
|
+
};
|
|
531
|
+
const { token, origins } = await remint(record, context);
|
|
532
|
+
return {
|
|
533
|
+
ok: true,
|
|
534
|
+
body: {
|
|
535
|
+
token,
|
|
536
|
+
domains: origins
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
},
|
|
540
|
+
/**
|
|
541
|
+
* Replace the public credential with a fresh one, keeping everything it declared. This is the control that expiry
|
|
542
|
+
* is often mistaken for: a render credential is meant to outlive any deadline, so revoking a leaked one is an act,
|
|
543
|
+
* not a wait.
|
|
544
|
+
*/
|
|
545
|
+
async rotate(context) {
|
|
546
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
547
|
+
if (!record) return notFound;
|
|
548
|
+
const { token, origins } = await remint(record, context);
|
|
549
|
+
return {
|
|
550
|
+
ok: true,
|
|
551
|
+
body: {
|
|
552
|
+
token,
|
|
553
|
+
domains: origins,
|
|
554
|
+
warning: ROTATION_WARNING
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
},
|
|
558
|
+
/**
|
|
559
|
+
* Issue a **host** credential: the space's read access for a SERVER that renders it as its own.
|
|
560
|
+
*
|
|
561
|
+
* A separate credential rather than letting the public one do it, because the two are protected by different
|
|
562
|
+
* things and only one of them can be published. A `render` token is safe in a page precisely because it is held
|
|
563
|
+
* to the origins it declares — a check that only means anything when a browser is the one making the claim. A
|
|
564
|
+
* server has no origin to state, so admitting the public token without one would make a key lifted from anybody's
|
|
565
|
+
* published page enough to serve a byte-identical clone of their site. This one is admitted without an origin
|
|
566
|
+
* because possessing it is itself the proof, which is only true while it stays secret: it is returned once, never
|
|
567
|
+
* embedded, and revocable on its own row.
|
|
568
|
+
*
|
|
569
|
+
* `label` is what the owner will read in the list when deciding which one to revoke — the deployment it was
|
|
570
|
+
* issued to. It is stored where a render token keeps its domains, since a host credential is bound to none.
|
|
571
|
+
*/
|
|
572
|
+
async issueHost(context, label, { expiresAt = null } = {}) {
|
|
573
|
+
if (!adapters.create) return {
|
|
574
|
+
ok: false,
|
|
575
|
+
status: 501,
|
|
576
|
+
body: { error: "This deployment does not issue host tokens" }
|
|
577
|
+
};
|
|
578
|
+
if (typeof label !== "string" || label.trim() === "") return {
|
|
579
|
+
ok: false,
|
|
580
|
+
status: 400,
|
|
581
|
+
body: { error: "label is required — name the deployment this credential is for, so it can be revoked" }
|
|
582
|
+
};
|
|
583
|
+
const name = label.trim();
|
|
584
|
+
const token = tokens.generateSpaceToken(context.spaceId, [name], "host", { expiresAt });
|
|
585
|
+
return {
|
|
586
|
+
ok: true,
|
|
587
|
+
status: 201,
|
|
588
|
+
body: {
|
|
589
|
+
id: (await adapters.create({
|
|
590
|
+
spaceId: context.spaceId,
|
|
591
|
+
token,
|
|
592
|
+
scope: "host",
|
|
593
|
+
origins: [name],
|
|
594
|
+
expiresAt
|
|
595
|
+
})).id,
|
|
596
|
+
token,
|
|
597
|
+
label: name,
|
|
598
|
+
expiresAt,
|
|
599
|
+
warning: HOST_SECRET_WARNING
|
|
600
|
+
}
|
|
601
|
+
};
|
|
602
|
+
},
|
|
603
|
+
async readDomains(context) {
|
|
604
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
605
|
+
return record ? {
|
|
606
|
+
ok: true,
|
|
607
|
+
body: { domains: record.origins }
|
|
608
|
+
} : notFound;
|
|
609
|
+
},
|
|
610
|
+
async setDomains(context, domains) {
|
|
611
|
+
if (!Array.isArray(domains) || domains.some((domain) => typeof domain !== "string")) return {
|
|
612
|
+
ok: false,
|
|
613
|
+
status: 400,
|
|
614
|
+
body: { error: "domains must be an array of strings" }
|
|
615
|
+
};
|
|
616
|
+
const normalized = [];
|
|
617
|
+
const rejected = [];
|
|
618
|
+
for (const domain of domains) {
|
|
619
|
+
const value = normalizeDomain(domain);
|
|
620
|
+
if (value) normalized.push(value);
|
|
621
|
+
else rejected.push(domain);
|
|
622
|
+
}
|
|
623
|
+
if (rejected.length > 0) return {
|
|
624
|
+
ok: false,
|
|
625
|
+
status: 400,
|
|
626
|
+
body: {
|
|
627
|
+
error: "Invalid domains",
|
|
628
|
+
domains: rejected
|
|
629
|
+
}
|
|
630
|
+
};
|
|
631
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
632
|
+
if (!record) return notFound;
|
|
633
|
+
const { token, origins } = await remint(record, context, { origins: normalized });
|
|
634
|
+
await adapters.onDomainsChanged?.(context.spaceId);
|
|
635
|
+
return {
|
|
636
|
+
ok: true,
|
|
637
|
+
body: {
|
|
638
|
+
token,
|
|
639
|
+
domains: origins,
|
|
640
|
+
...origins.includes("*") && { warning: "This token now works on any domain. Anyone who copies it from a page can use it elsewhere." }
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
},
|
|
644
|
+
async readExpiry(context) {
|
|
645
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
646
|
+
return record ? {
|
|
647
|
+
ok: true,
|
|
648
|
+
body: {
|
|
649
|
+
expiresAt: record.expiresAt,
|
|
650
|
+
neverExpires: record.expiresAt === null
|
|
651
|
+
}
|
|
652
|
+
} : notFound;
|
|
653
|
+
},
|
|
654
|
+
/**
|
|
655
|
+
* When the public credential should stop working — or never, which is the default. Both are legitimate: a site
|
|
656
|
+
* deployed once and left alone wants no deadline (an expiry there is a scheduled outage), while a campaign page
|
|
657
|
+
* meant to go quiet, or a credential handed to an agency for a fixed engagement, wants one.
|
|
658
|
+
*/
|
|
659
|
+
async setExpiry(context, expiresInDays) {
|
|
660
|
+
const forever = expiresInDays === null || expiresInDays === void 0;
|
|
661
|
+
if (!forever && (typeof expiresInDays !== "number" || !Number.isFinite(expiresInDays) || expiresInDays <= 0)) return {
|
|
662
|
+
ok: false,
|
|
663
|
+
status: 400,
|
|
664
|
+
body: { error: "expiresInDays must be a positive number, or null to never expire" }
|
|
665
|
+
};
|
|
666
|
+
const record = await adapters.loadDefault(context.spaceId);
|
|
667
|
+
if (!record) return notFound;
|
|
668
|
+
const expiry = forever ? null : now() + Math.round(expiresInDays * DAY_SECONDS);
|
|
669
|
+
const { token, expiresAt } = await remint(record, context, { expiresAt: expiry });
|
|
670
|
+
return {
|
|
671
|
+
ok: true,
|
|
672
|
+
body: {
|
|
673
|
+
token,
|
|
674
|
+
expiresAt,
|
|
675
|
+
neverExpires: expiresAt === null,
|
|
676
|
+
warning: ROTATION_WARNING
|
|
677
|
+
}
|
|
678
|
+
};
|
|
679
|
+
},
|
|
680
|
+
/**
|
|
681
|
+
* The space's credentials, so a leak can be seen and acted on. Never the secrets themselves: an `agent` grant
|
|
682
|
+
* writes and a `host` grant serves the space from somebody else's server, so listing either would turn
|
|
683
|
+
* permission to read into a way to obtain it. The public one is published by construction and has its own
|
|
684
|
+
* endpoint.
|
|
685
|
+
*/
|
|
686
|
+
async list(context) {
|
|
687
|
+
return {
|
|
688
|
+
ok: true,
|
|
689
|
+
body: { tokens: (await adapters.list(context.spaceId)).map(({ token, origins, ...rest }) => {
|
|
690
|
+
return {
|
|
691
|
+
...rest,
|
|
692
|
+
...rest.scope === "render" ? { domains: origins } : { label: origins.join(",") }
|
|
693
|
+
};
|
|
694
|
+
}) }
|
|
695
|
+
};
|
|
696
|
+
},
|
|
697
|
+
/**
|
|
698
|
+
* Revoke one credential. Dropping the record IS the revocation: every grant is looked up as it is verified, so it
|
|
699
|
+
* stops working at once whatever its claims still say.
|
|
700
|
+
*
|
|
701
|
+
* The public credential is deliberately not revocable this way — removing it leaves the published site with no
|
|
702
|
+
* credential at all, and replacing it is what a leak of that one calls for.
|
|
703
|
+
*/
|
|
704
|
+
async revoke(context, tokenId) {
|
|
705
|
+
if (!Number.isFinite(tokenId)) return {
|
|
706
|
+
ok: false,
|
|
707
|
+
status: 400,
|
|
708
|
+
body: { error: "tokenId must be a number" }
|
|
709
|
+
};
|
|
710
|
+
const record = await adapters.find(context.spaceId, tokenId);
|
|
711
|
+
if (!record) return notFound;
|
|
712
|
+
if (record.isDefault) return {
|
|
713
|
+
ok: false,
|
|
714
|
+
status: 400,
|
|
715
|
+
body: {
|
|
716
|
+
error: "The space’s public token cannot be deleted — rotate it instead",
|
|
717
|
+
rotate: `/spaces/${context.spaceId}/token/rotate`
|
|
718
|
+
}
|
|
719
|
+
};
|
|
720
|
+
await adapters.remove(record.id);
|
|
721
|
+
return {
|
|
722
|
+
ok: true,
|
|
723
|
+
body: {
|
|
724
|
+
message: "Token revoked",
|
|
725
|
+
tokenId
|
|
726
|
+
}
|
|
727
|
+
};
|
|
728
|
+
}
|
|
729
|
+
};
|
|
730
|
+
};
|
|
731
|
+
export { ANY_DOMAIN, OFF_BROWSER_SPACE_SCOPES, PREVIEW_COOKIE, PREVIEW_TOKEN_PARAM, RENEWAL_GUARD_SECONDS, SCOPES, SESSION_ACTIVITY_RESOLUTION_SECONDS, SPACE_TOKEN_PARAM, activityDue, appendCookies, authFailureMessage, authorizesDebugging, carrierOf, checkPermission, checkSpaceAccess, clearFlowCookie, clearSessionCookies, corsOrigins, createAuthorizer, createCarriers, createCsrf, createIdentity, createSessionCookies, createSpaceTokenApi, crossSiteRequest, csrfFailureMessage, domainAllowed, frameAncestors, generateToken, hashPassword, hostnameOf, isLocalHost, isPrivateNetworkHost, normalizeDomain, parseSessionHint, presentedOrigin, readCookies, readDraftToken, readFlowCookie, readRefreshToken, readRenewalGuard, readSessionHint, readSessionToken, registrableDomain, requirementFor, resolveDebugAuthorization, sessionCookieParams, sessionHintCookieName, sessionHintValue, sessionReturnTarget, verifyPassword, writeFlowCookie, writeRenewalGuard, writeSessionCookies };
|