@tryghost/app-sdk 0.1.0-alpha.7 → 0.1.0-alpha.9
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/README.md +104 -13
- package/build/backend.js +2 -1
- package/build/backend.js.map +1 -1
- package/build/bin.d.ts +1 -0
- package/build/bin.js +140 -0
- package/build/bin.js.map +1 -0
- package/build/chunks/{manifest-DX1GTozy.js → body-CshsXE1J.js} +3 -75
- package/build/chunks/body-CshsXE1J.js.map +1 -0
- package/build/chunks/check-3oU5pDJc.js +208 -0
- package/build/chunks/check-3oU5pDJc.js.map +1 -0
- package/build/chunks/manifest-iOwbzAil.js +77 -0
- package/build/chunks/manifest-iOwbzAil.js.map +1 -0
- package/build/chunks/sign-DygdzQYY.js +928 -0
- package/build/chunks/sign-DygdzQYY.js.map +1 -0
- package/build/index.js +1 -1
- package/build/tooling.js +3 -1129
- package/build/vite.d.ts +29 -0
- package/build/vite.js +228 -0
- package/build/vite.js.map +1 -0
- package/dist/app-sdk.js +1 -1
- package/package.json +18 -2
- package/build/chunks/manifest-DX1GTozy.js.map +0 -1
- package/build/tooling.js.map +0 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
import { C as parseManifest, E as verifySignedManifest, S as tooLargeMessage, T as readSignedManifest, _ as ANSWER_MAX_BYTES, b as TIMEOUT_MS, v as MANIFEST_MAX_BYTES, w as parseManifestUrl, x as storedSize, y as SIGNED_MANIFEST_MAX_BYTES } from "./sign-DygdzQYY.js";
|
|
2
|
+
import { a as parseJsonText, i as ignoreError, n as UNKNOWN_GHOST_URL, r as formatErrors } from "./manifest-iOwbzAil.js";
|
|
3
|
+
import { a as createChallenge, i as challengeUrl, o as verifyChallengeAnswer, t as readBytes } from "./body-CshsXE1J.js";
|
|
4
|
+
//#region src/tooling/check.ts
|
|
5
|
+
var MESSAGES = {
|
|
6
|
+
APP_MANIFEST_URL_INVALID: "The app manifest URL is not valid.",
|
|
7
|
+
APP_MANIFEST_UNREACHABLE: "Could not load the app’s manifest.",
|
|
8
|
+
APP_MANIFEST_REDIRECTED: "The app’s manifest redirects to another host.",
|
|
9
|
+
APP_MANIFEST_TOO_LARGE: `The app’s manifest is larger than ${MANIFEST_MAX_BYTES / 1024} KB.`,
|
|
10
|
+
APP_MANIFEST_NOT_JSON: "The app’s manifest is not JSON.",
|
|
11
|
+
APP_MANIFEST_UNSIGNED: "The app’s manifest is not signed.",
|
|
12
|
+
APP_MANIFEST_URL_MISMATCH: "The app’s manifest is for another address.",
|
|
13
|
+
APP_MANIFEST_INVALID: "The app manifest is not valid.",
|
|
14
|
+
APP_MANIFEST_SIGNATURE_INVALID: "The app’s manifest signature is not valid.",
|
|
15
|
+
APP_CHALLENGE_UNREACHABLE: "Could not reach the app to confirm it comes from its developer.",
|
|
16
|
+
APP_CHALLENGE_FAILED: "Ghost couldn’t confirm the app comes from its developer."
|
|
17
|
+
};
|
|
18
|
+
/** Thrown by any step, and turned into a failed `CheckResult` by `checkApp`. */
|
|
19
|
+
var Failure = class extends Error {
|
|
20
|
+
code;
|
|
21
|
+
detail;
|
|
22
|
+
errors;
|
|
23
|
+
constructor(code, detail, errors) {
|
|
24
|
+
super(MESSAGES[code]);
|
|
25
|
+
this.code = code;
|
|
26
|
+
this.detail = detail;
|
|
27
|
+
this.errors = errors;
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Checks an app as Ghost does before installing it, and resolves with the code Ghost would
|
|
32
|
+
* refuse it with, or the manifest Ghost would install.
|
|
33
|
+
*/
|
|
34
|
+
async function checkApp(manifestUrl, { fetch: fetchFn = globalThis.fetch } = {}) {
|
|
35
|
+
try {
|
|
36
|
+
return await runChecks(manifestUrl, fetchFn);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
if (!(error instanceof Failure)) throw error;
|
|
39
|
+
return {
|
|
40
|
+
success: false,
|
|
41
|
+
code: error.code,
|
|
42
|
+
message: error.message,
|
|
43
|
+
detail: error.detail,
|
|
44
|
+
...error.errors ? { errors: error.errors } : {}
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
async function runChecks(input, fetchFn) {
|
|
49
|
+
const manifestUrl = readManifestUrl(input);
|
|
50
|
+
const signed = readSigned(await fetchManifest(manifestUrl, fetchFn), manifestUrl);
|
|
51
|
+
const manifest = parse(signed.payload, manifestUrl);
|
|
52
|
+
await verifySignature(signed.signed, manifest);
|
|
53
|
+
checkStoredSize(manifest, manifestUrl);
|
|
54
|
+
await challenge(new URL(manifestUrl).origin, manifest.backend_key, fetchFn);
|
|
55
|
+
return {
|
|
56
|
+
success: true,
|
|
57
|
+
manifestUrl,
|
|
58
|
+
manifest
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
function readManifestUrl(input) {
|
|
62
|
+
const address = parseManifestUrl(input, {
|
|
63
|
+
ghostUrls: [UNKNOWN_GHOST_URL],
|
|
64
|
+
allowLocalhost: true
|
|
65
|
+
});
|
|
66
|
+
if (!address.success) throw new Failure("APP_MANIFEST_URL_INVALID", address.error);
|
|
67
|
+
return address.manifestUrl;
|
|
68
|
+
}
|
|
69
|
+
/** The signed manifest's bytes, following redirects on the same host, as Ghost does. */
|
|
70
|
+
async function fetchManifest(manifestUrl, fetchFn) {
|
|
71
|
+
const signal = AbortSignal.timeout(TIMEOUT_MS);
|
|
72
|
+
let current = new URL(manifestUrl);
|
|
73
|
+
for (let redirects = 0;; redirects++) {
|
|
74
|
+
const answer = await fetchOnce(fetchFn, current, {
|
|
75
|
+
init: {
|
|
76
|
+
headers: { accept: "application/json" },
|
|
77
|
+
signal
|
|
78
|
+
},
|
|
79
|
+
maxBytes: SIGNED_MANIFEST_MAX_BYTES,
|
|
80
|
+
code: "APP_MANIFEST_UNREACHABLE",
|
|
81
|
+
wantsBody: isSuccess
|
|
82
|
+
});
|
|
83
|
+
if (REDIRECT_STATUSES.has(answer.status) && answer.location !== null) {
|
|
84
|
+
current = followRedirect(manifestUrl, current, answer.status, answer.location, redirects);
|
|
85
|
+
continue;
|
|
86
|
+
}
|
|
87
|
+
if (!isSuccess(answer.status)) throw new Failure("APP_MANIFEST_UNREACHABLE", `${current.href} answered with HTTP ${answer.status}`);
|
|
88
|
+
if (!answer.body) throw new Failure("APP_MANIFEST_TOO_LARGE", manifestUrl);
|
|
89
|
+
return answer.body;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
var REDIRECT_STATUSES = /* @__PURE__ */ new Set([
|
|
93
|
+
301,
|
|
94
|
+
302,
|
|
95
|
+
303,
|
|
96
|
+
307,
|
|
97
|
+
308
|
|
98
|
+
]);
|
|
99
|
+
/** The URL a redirect leads to, if Ghost would follow it. */
|
|
100
|
+
function followRedirect(manifestUrl, current, status, location, redirects) {
|
|
101
|
+
const target = URL.parse(Buffer.from(location, "binary").toString("utf8"), current);
|
|
102
|
+
if (!target) throw new Failure("APP_MANIFEST_UNREACHABLE", `${manifestUrl} answered with HTTP ${status} and a Location that is not a URL`);
|
|
103
|
+
if (!staysOnHost(current, target)) throw new Failure("APP_MANIFEST_REDIRECTED", `${manifestUrl} redirects to ${target.host}`);
|
|
104
|
+
if (redirects === 3) throw new Failure("APP_MANIFEST_UNREACHABLE", `${manifestUrl} redirects more than 3 times`);
|
|
105
|
+
target.username = "";
|
|
106
|
+
target.password = "";
|
|
107
|
+
return target;
|
|
108
|
+
}
|
|
109
|
+
/** Ghost follows a redirect on the same origin, or from HTTP to HTTPS on the same host. */
|
|
110
|
+
function staysOnHost(from, to) {
|
|
111
|
+
if (to.origin === from.origin) return true;
|
|
112
|
+
return from.protocol === "http:" && to.protocol === "https:" && to.hostname === from.hostname && from.port === "" && to.port === "";
|
|
113
|
+
}
|
|
114
|
+
function readSigned(body, manifestUrl) {
|
|
115
|
+
const signed = readSignedManifest(parseJson(decode(body), manifestUrl));
|
|
116
|
+
if (!signed.success) throw new Failure("APP_MANIFEST_UNSIGNED", signed.error);
|
|
117
|
+
return signed;
|
|
118
|
+
}
|
|
119
|
+
function parse(payload, manifestUrl) {
|
|
120
|
+
const parsed = parseManifest(parseJson(payload, manifestUrl), {
|
|
121
|
+
manifestUrl,
|
|
122
|
+
ghostUrls: [UNKNOWN_GHOST_URL],
|
|
123
|
+
allowLocalhost: true
|
|
124
|
+
});
|
|
125
|
+
if (parsed.success) return parsed.manifest;
|
|
126
|
+
const detail = formatErrors(parsed.errors, "; ");
|
|
127
|
+
if (parsed.reason === "manifest_url_mismatch") throw new Failure("APP_MANIFEST_URL_MISMATCH", detail);
|
|
128
|
+
throw new Failure("APP_MANIFEST_INVALID", detail, parsed.errors);
|
|
129
|
+
}
|
|
130
|
+
async function verifySignature(signed, manifest) {
|
|
131
|
+
const verified = await verifySignedManifest(signed, manifest.identity_key);
|
|
132
|
+
if (!verified.success) throw new Failure("APP_MANIFEST_SIGNATURE_INVALID", verified.error);
|
|
133
|
+
}
|
|
134
|
+
function checkStoredSize(manifest, manifestUrl) {
|
|
135
|
+
if (storedSize(manifest) > 65536) throw new Failure("APP_MANIFEST_TOO_LARGE", `${manifestUrl}: ${tooLargeMessage()}`);
|
|
136
|
+
}
|
|
137
|
+
/** Sends Ghost's challenge to the app's origin, and verifies the answer with the backend key. */
|
|
138
|
+
async function challenge(origin, backendKey, fetchFn) {
|
|
139
|
+
const sent = createChallenge(origin);
|
|
140
|
+
const answer = await fetchOnce(fetchFn, challengeUrl(origin), {
|
|
141
|
+
init: {
|
|
142
|
+
method: "POST",
|
|
143
|
+
body: sent,
|
|
144
|
+
headers: {
|
|
145
|
+
accept: "application/json",
|
|
146
|
+
"content-type": "application/json"
|
|
147
|
+
},
|
|
148
|
+
signal: AbortSignal.timeout(TIMEOUT_MS)
|
|
149
|
+
},
|
|
150
|
+
maxBytes: ANSWER_MAX_BYTES,
|
|
151
|
+
code: "APP_CHALLENGE_UNREACHABLE",
|
|
152
|
+
wantsBody: () => true
|
|
153
|
+
});
|
|
154
|
+
const text = answer.body && decode(answer.body);
|
|
155
|
+
if (!isSuccess(answer.status)) throw new Failure("APP_CHALLENGE_UNREACHABLE", describeRefusal(origin, answer.status, text));
|
|
156
|
+
if (text === void 0) throw new Failure("APP_CHALLENGE_FAILED", `${origin}: The answer is larger than ${ANSWER_MAX_BYTES / 1024} KB`);
|
|
157
|
+
const verified = await verifyChallengeAnswer(sent, text, backendKey);
|
|
158
|
+
if (!verified.success) throw new Failure("APP_CHALLENGE_FAILED", `${origin}: ${verified.error}`);
|
|
159
|
+
}
|
|
160
|
+
function describeRefusal(origin, status, text) {
|
|
161
|
+
return `${origin} answered the challenge with HTTP ${status}${isRedirect(status) ? " (Ghost follows no redirect for a challenge)" : ""}${text && text.length < 500 ? `: ${text.trim()}` : ""}`;
|
|
162
|
+
}
|
|
163
|
+
/** Requests a URL as Ghost does, following no redirect, and reads the body only if it's wanted. */
|
|
164
|
+
async function fetchOnce(fetchFn, url, { init, maxBytes, code, wantsBody }) {
|
|
165
|
+
try {
|
|
166
|
+
const response = await fetchFn(url, {
|
|
167
|
+
...init,
|
|
168
|
+
redirect: "manual"
|
|
169
|
+
});
|
|
170
|
+
const answer = {
|
|
171
|
+
status: response.status,
|
|
172
|
+
location: response.headers.get("location")
|
|
173
|
+
};
|
|
174
|
+
if (!wantsBody(response.status)) {
|
|
175
|
+
response.body?.cancel().catch(ignoreError);
|
|
176
|
+
return {
|
|
177
|
+
...answer,
|
|
178
|
+
body: void 0
|
|
179
|
+
};
|
|
180
|
+
}
|
|
181
|
+
return {
|
|
182
|
+
...answer,
|
|
183
|
+
body: await readBytes(response, maxBytes)
|
|
184
|
+
};
|
|
185
|
+
} catch (error) {
|
|
186
|
+
throw new Failure(code, `${String(url)}: ${describeFetchError(error)}`);
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
/** A failed fetch's message, with the reason Node hides in its `cause`, such as ECONNREFUSED. */
|
|
190
|
+
function describeFetchError(error) {
|
|
191
|
+
const { message, cause } = typeof error === "object" && error !== null ? error : {};
|
|
192
|
+
const reason = cause?.code ?? cause?.message;
|
|
193
|
+
return reason ? `${message} (${reason})` : String(message ?? error);
|
|
194
|
+
}
|
|
195
|
+
function parseJson(text, manifestUrl) {
|
|
196
|
+
try {
|
|
197
|
+
return parseJsonText(text);
|
|
198
|
+
} catch {
|
|
199
|
+
throw new Failure("APP_MANIFEST_NOT_JSON", manifestUrl);
|
|
200
|
+
}
|
|
201
|
+
}
|
|
202
|
+
var decode = (bytes) => new TextDecoder("utf-8", { ignoreBOM: true }).decode(bytes);
|
|
203
|
+
var isRedirect = (status) => status >= 300 && status < 400;
|
|
204
|
+
var isSuccess = (status) => status >= 200 && status < 300;
|
|
205
|
+
//#endregion
|
|
206
|
+
export { checkApp as t };
|
|
207
|
+
|
|
208
|
+
//# sourceMappingURL=check-3oU5pDJc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"check-3oU5pDJc.js","names":[],"sources":["../../src/tooling/check.ts"],"sourcesContent":["import {\n challengeUrl,\n createChallenge,\n readSignedManifest,\n verifyChallengeAnswer,\n verifySignedManifest,\n} from '@tryghost/app-contracts/identity';\nimport { parseManifest, parseManifestUrl } from '@tryghost/app-contracts/manifest';\n\nimport { readBytes } from '../shared/body.ts';\nimport { ignoreError } from '../shared/ignore.ts';\nimport { UNKNOWN_GHOST_URL, formatErrors } from '../shared/manifest.ts';\nimport { parseJsonText } from '../shared/parse.ts';\nimport type { PublicKeyJwk } from './keys.ts';\nimport {\n ANSWER_MAX_BYTES,\n MANIFEST_MAX_BYTES,\n MAX_REDIRECTS,\n SIGNED_MANIFEST_MAX_BYTES,\n TIMEOUT_MS,\n storedSize,\n tooLargeMessage,\n} from './limits.ts';\nimport type { AppManifest, ManifestError } from './types.ts';\n\n/** The codes Ghost refuses an app with, which `checkApp` reports the same problems with. */\nexport type CheckCode =\n | 'APP_MANIFEST_URL_INVALID'\n | 'APP_MANIFEST_UNREACHABLE'\n | 'APP_MANIFEST_REDIRECTED'\n | 'APP_MANIFEST_TOO_LARGE'\n | 'APP_MANIFEST_NOT_JSON'\n | 'APP_MANIFEST_UNSIGNED'\n | 'APP_MANIFEST_URL_MISMATCH'\n | 'APP_MANIFEST_INVALID'\n | 'APP_MANIFEST_SIGNATURE_INVALID'\n | 'APP_CHALLENGE_UNREACHABLE'\n | 'APP_CHALLENGE_FAILED';\n\n/** What `checkApp` resolves with: the manifest Ghost would install, or why Ghost would refuse. */\nexport type CheckResult =\n | {\n success: true;\n manifestUrl: string;\n /** The manifest as Ghost parses it, with every path resolved. */\n manifest: AppManifest;\n }\n | {\n success: false;\n code: CheckCode;\n /** Ghost's own message for the code. */\n message: string;\n /** What exactly was wrong. Unlike Ghost, it says why a request failed. */\n detail: string;\n /** For `APP_MANIFEST_INVALID`, each problem by the path to its field. */\n errors?: ManifestError[];\n };\n\nexport interface CheckOptions {\n /** The fetch to make requests with. Node's own, by default. */\n fetch?: typeof fetch;\n}\n\ntype Fetch = typeof fetch;\n\n// Ghost's own message for each code.\nconst MESSAGES: Record<CheckCode, string> = {\n APP_MANIFEST_URL_INVALID: 'The app manifest URL is not valid.',\n APP_MANIFEST_UNREACHABLE: 'Could not load the app’s manifest.',\n APP_MANIFEST_REDIRECTED: 'The app’s manifest redirects to another host.',\n APP_MANIFEST_TOO_LARGE: `The app’s manifest is larger than ${MANIFEST_MAX_BYTES / 1024} KB.`,\n APP_MANIFEST_NOT_JSON: 'The app’s manifest is not JSON.',\n APP_MANIFEST_UNSIGNED: 'The app’s manifest is not signed.',\n APP_MANIFEST_URL_MISMATCH: 'The app’s manifest is for another address.',\n APP_MANIFEST_INVALID: 'The app manifest is not valid.',\n APP_MANIFEST_SIGNATURE_INVALID: 'The app’s manifest signature is not valid.',\n APP_CHALLENGE_UNREACHABLE: 'Could not reach the app to confirm it comes from its developer.',\n APP_CHALLENGE_FAILED: 'Ghost couldn’t confirm the app comes from its developer.',\n};\n\n/** Thrown by any step, and turned into a failed `CheckResult` by `checkApp`. */\nclass Failure extends Error {\n constructor(\n readonly code: CheckCode,\n readonly detail: string,\n readonly errors?: ManifestError[],\n ) {\n super(MESSAGES[code]);\n }\n}\n\n/**\n * Checks an app as Ghost does before installing it, and resolves with the code Ghost would\n * refuse it with, or the manifest Ghost would install.\n */\nexport async function checkApp(\n manifestUrl: string,\n { fetch: fetchFn = globalThis.fetch }: CheckOptions = {},\n): Promise<CheckResult> {\n try {\n return await runChecks(manifestUrl, fetchFn);\n } catch (error) {\n if (!(error instanceof Failure)) {\n throw error;\n }\n return {\n success: false,\n code: error.code,\n message: error.message,\n detail: error.detail,\n ...(error.errors ? { errors: error.errors } : {}),\n };\n }\n}\n\n// The steps run in the order Ghost runs them, so the first failure is the one Ghost would report.\n// Some things only a site knows can't be checked: Ghost's own hosts, the identity key the site\n// installed the app with, and backend keys a newer manifest replaced.\nasync function runChecks(input: string, fetchFn: Fetch): Promise<CheckResult> {\n const manifestUrl = readManifestUrl(input);\n const body = await fetchManifest(manifestUrl, fetchFn);\n const signed = readSigned(body, manifestUrl);\n const manifest = parse(signed.payload, manifestUrl);\n await verifySignature(signed.signed, manifest);\n checkStoredSize(manifest, manifestUrl);\n // Sent even to localhost, which Ghost in development skips, so a backend is checked before\n // it's deployed.\n await challenge(new URL(manifestUrl).origin, manifest.backend_key, fetchFn);\n return { success: true, manifestUrl, manifest };\n}\n\nfunction readManifestUrl(input: string): string {\n // The site's own URL is a name no site has, as only a site knows its own hosts.\n const address = parseManifestUrl(input, { ghostUrls: [UNKNOWN_GHOST_URL], allowLocalhost: true });\n if (!address.success) {\n throw new Failure('APP_MANIFEST_URL_INVALID', address.error);\n }\n return address.manifestUrl;\n}\n\n/** The signed manifest's bytes, following redirects on the same host, as Ghost does. */\nasync function fetchManifest(manifestUrl: string, fetchFn: Fetch): Promise<Uint8Array> {\n // One deadline for the whole read, redirects included, as in Ghost, so a slow app can't stall\n // it several times over.\n const signal = AbortSignal.timeout(TIMEOUT_MS);\n let current = new URL(manifestUrl);\n for (let redirects = 0; ; redirects++) {\n const answer = await fetchOnce(fetchFn, current, {\n init: { headers: { accept: 'application/json' }, signal },\n maxBytes: SIGNED_MANIFEST_MAX_BYTES,\n code: 'APP_MANIFEST_UNREACHABLE',\n // A redirect's or an error's body is dropped unread, as Ghost drops it.\n wantsBody: isSuccess,\n });\n // Ghost's HTTP client follows only these, and treats any other status as an answer.\n if (REDIRECT_STATUSES.has(answer.status) && answer.location !== null) {\n current = followRedirect(manifestUrl, current, answer.status, answer.location, redirects);\n continue;\n }\n if (!isSuccess(answer.status)) {\n throw new Failure(\n 'APP_MANIFEST_UNREACHABLE',\n `${current.href} answered with HTTP ${answer.status}`,\n );\n }\n if (!answer.body) {\n throw new Failure('APP_MANIFEST_TOO_LARGE', manifestUrl);\n }\n return answer.body;\n }\n}\n\nconst REDIRECT_STATUSES: ReadonlySet<number> = new Set([301, 302, 303, 307, 308]);\n\n/** The URL a redirect leads to, if Ghost would follow it. */\nfunction followRedirect(\n manifestUrl: string,\n current: URL,\n status: number,\n location: string,\n redirects: number,\n): URL {\n // Headers arrive as latin1, and Ghost reads the Location as UTF-8, as got and browsers do.\n const target = URL.parse(Buffer.from(location, 'binary').toString('utf8'), current);\n if (!target) {\n throw new Failure(\n 'APP_MANIFEST_UNREACHABLE',\n `${manifestUrl} answered with HTTP ${status} and a Location that is not a URL`,\n );\n }\n if (!staysOnHost(current, target)) {\n throw new Failure('APP_MANIFEST_REDIRECTED', `${manifestUrl} redirects to ${target.host}`);\n }\n if (redirects === MAX_REDIRECTS) {\n throw new Failure(\n 'APP_MANIFEST_UNREACHABLE',\n `${manifestUrl} redirects more than ${MAX_REDIRECTS} times`,\n );\n }\n // Ghost drops credentials from a Location, as browsers do, and fetch would refuse them.\n target.username = '';\n target.password = '';\n return target;\n}\n\n/** Ghost follows a redirect on the same origin, or from HTTP to HTTPS on the same host. */\nfunction staysOnHost(from: URL, to: URL): boolean {\n if (to.origin === from.origin) {\n return true;\n }\n return (\n from.protocol === 'http:' &&\n to.protocol === 'https:' &&\n to.hostname === from.hostname &&\n from.port === '' &&\n to.port === ''\n );\n}\n\nfunction readSigned(body: Uint8Array, manifestUrl: string) {\n const signed = readSignedManifest(parseJson(decode(body), manifestUrl));\n if (!signed.success) {\n throw new Failure('APP_MANIFEST_UNSIGNED', signed.error);\n }\n return signed;\n}\n\nfunction parse(payload: string, manifestUrl: string): AppManifest {\n const parsed = parseManifest(parseJson(payload, manifestUrl), {\n manifestUrl,\n ghostUrls: [UNKNOWN_GHOST_URL],\n allowLocalhost: true,\n });\n if (parsed.success) {\n return parsed.manifest;\n }\n const detail = formatErrors(parsed.errors, '; ');\n // A manifest signed for another address has its own code, as it's the usual mistake.\n if (parsed.reason === 'manifest_url_mismatch') {\n throw new Failure('APP_MANIFEST_URL_MISMATCH', detail);\n }\n throw new Failure('APP_MANIFEST_INVALID', detail, parsed.errors);\n}\n\nasync function verifySignature(\n signed: Parameters<typeof verifySignedManifest>[0],\n manifest: AppManifest,\n) {\n // With the identity key the manifest names: a site installing the app pins it from here.\n const verified = await verifySignedManifest(signed, manifest.identity_key);\n if (!verified.success) {\n throw new Failure('APP_MANIFEST_SIGNATURE_INVALID', verified.error);\n }\n}\n\nfunction checkStoredSize(manifest: AppManifest, manifestUrl: string) {\n // Ghost measures what it stores, with the paths resolved, after verifying the signature.\n if (storedSize(manifest) > MANIFEST_MAX_BYTES) {\n throw new Failure('APP_MANIFEST_TOO_LARGE', `${manifestUrl}: ${tooLargeMessage()}`);\n }\n}\n\n/** Sends Ghost's challenge to the app's origin, and verifies the answer with the backend key. */\nasync function challenge(origin: string, backendKey: PublicKeyJwk, fetchFn: Fetch) {\n const sent = createChallenge(origin);\n const answer = await fetchOnce(fetchFn, challengeUrl(origin), {\n init: {\n method: 'POST',\n body: sent,\n headers: { accept: 'application/json', 'content-type': 'application/json' },\n signal: AbortSignal.timeout(TIMEOUT_MS),\n },\n maxBytes: ANSWER_MAX_BYTES,\n code: 'APP_CHALLENGE_UNREACHABLE',\n // Read whatever the status, for the backend's explanation of a refusal.\n wantsBody: () => true,\n });\n const text = answer.body && decode(answer.body);\n if (!isSuccess(answer.status)) {\n throw new Failure('APP_CHALLENGE_UNREACHABLE', describeRefusal(origin, answer.status, text));\n }\n if (text === undefined) {\n throw new Failure(\n 'APP_CHALLENGE_FAILED',\n `${origin}: The answer is larger than ${ANSWER_MAX_BYTES / 1024} KB`,\n );\n }\n const verified = await verifyChallengeAnswer(sent, text, backendKey);\n if (!verified.success) {\n throw new Failure('APP_CHALLENGE_FAILED', `${origin}: ${verified.error}`);\n }\n}\n\nfunction describeRefusal(origin: string, status: number, text: string | undefined): string {\n // Ghost sends the challenge to one exact address, so a redirect means the app is set up wrong.\n const redirect = isRedirect(status) ? ' (Ghost follows no redirect for a challenge)' : '';\n // The backend's own explanation, such as handleChallenge's, if it's short enough to show.\n const said = text && text.length < 500 ? `: ${text.trim()}` : '';\n return `${origin} answered the challenge with HTTP ${status}${redirect}${said}`;\n}\n\ninterface Answer {\n status: number;\n location: string | null;\n /** Up to the limit; `undefined` past it, or when it wasn't wanted. */\n body: Uint8Array | undefined;\n}\n\n/** Requests a URL as Ghost does, following no redirect, and reads the body only if it's wanted. */\nasync function fetchOnce(\n fetchFn: Fetch,\n url: URL | string,\n {\n init,\n maxBytes,\n code,\n wantsBody,\n }: {\n init: RequestInit & { signal: AbortSignal };\n maxBytes: number;\n /** The code a failed request, or a body that breaks while it's read, fails with. */\n code: CheckCode;\n wantsBody: (status: number) => boolean;\n },\n): Promise<Answer> {\n try {\n const response = await fetchFn(url, { ...init, redirect: 'manual' });\n const answer = { status: response.status, location: response.headers.get('location') };\n if (!wantsBody(response.status)) {\n // Dropped unread, so a body that stalls or breaks doesn't matter.\n response.body?.cancel().catch(ignoreError);\n return { ...answer, body: undefined };\n }\n return { ...answer, body: await readBytes(response, maxBytes) };\n } catch (error) {\n throw new Failure(code, `${String(url)}: ${describeFetchError(error)}`);\n }\n}\n\n/** A failed fetch's message, with the reason Node hides in its `cause`, such as ECONNREFUSED. */\nfunction describeFetchError(error: unknown): string {\n // A fetch may reject with anything, `null` and `undefined` included.\n const { message, cause } = (typeof error === 'object' && error !== null ? error : {}) as {\n message?: string;\n cause?: { code?: string; message?: string };\n };\n const reason = cause?.code ?? cause?.message;\n return reason ? `${message} (${reason})` : String(message ?? error);\n}\n\nfunction parseJson(text: string, manifestUrl: string): unknown {\n try {\n return parseJsonText(text);\n } catch {\n throw new Failure('APP_MANIFEST_NOT_JSON', manifestUrl);\n }\n}\n\n// Decoded as UTF-8, which is what JSON should use, whatever charset the app names, as in Ghost.\n// Kept with any byte order mark, as Ghost's `Buffer#toString` keeps it: a manifest may start with\n// one, which its JSON parse allows, and an answer to the challenge may not.\nconst decode = (bytes: Uint8Array) => new TextDecoder('utf-8', { ignoreBOM: true }).decode(bytes);\n\nconst isRedirect = (status: number) => status >= 300 && status < 400;\nconst isSuccess = (status: number) => status >= 200 && status < 300;\n"],"mappings":";;;;AAkEA,IAAM,WAAsC;CAC1C,0BAA0B;CAC1B,0BAA0B;CAC1B,yBAAyB;CACzB,wBAAwB,qCAAqC,qBAAqB,KAAK;CACvF,uBAAuB;CACvB,uBAAuB;CACvB,2BAA2B;CAC3B,sBAAsB;CACtB,gCAAgC;CAChC,2BAA2B;CAC3B,sBAAsB;AACxB;;AAGA,IAAM,UAAN,cAAsB,MAAM;CAEf;CACA;CACA;CAHX,YACE,MACA,QACA,QACA;EACA,MAAM,SAAS,KAAK;EAJX,KAAA,OAAA;EACA,KAAA,SAAA;EACA,KAAA,SAAA;CAGX;AACF;;;;;AAMA,eAAsB,SACpB,aACA,EAAE,OAAO,UAAU,WAAW,UAAwB,CAAC,GACjC;CACtB,IAAI;EACF,OAAO,MAAM,UAAU,aAAa,OAAO;CAC7C,SAAS,OAAO;EACd,IAAI,EAAE,iBAAiB,UACrB,MAAM;EAER,OAAO;GACL,SAAS;GACT,MAAM,MAAM;GACZ,SAAS,MAAM;GACf,QAAQ,MAAM;GACd,GAAI,MAAM,SAAS,EAAE,QAAQ,MAAM,OAAO,IAAI,CAAC;EACjD;CACF;AACF;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AAG;GAAM,UAAU;EAAS,CAAC;EACnE,MAAM,SAAS;GAAE,QAAQ,SAAS;GAAQ,UAAU,SAAS,QAAQ,IAAI,UAAU;EAAE;EACrF,IAAI,CAAC,UAAU,SAAS,MAAM,GAAG;GAE/B,SAAS,MAAM,OAAO,CAAC,CAAC,MAAM,WAAW;GACzC,OAAO;IAAE,GAAG;IAAQ,MAAM,KAAA;GAAU;EACtC;EACA,OAAO;GAAE,GAAG;GAAQ,MAAM,MAAM,UAAU,UAAU,QAAQ;EAAE;CAChE,SAAS,OAAO;EACd,MAAM,IAAI,QAAQ,MAAM,GAAG,OAAO,GAAG,EAAE,IAAI,mBAAmB,KAAK,GAAG;CACxE;AACF;;AAGA,SAAS,mBAAmB,OAAwB;CAElD,MAAM,EAAE,SAAS,UAAW,OAAO,UAAU,YAAY,UAAU,OAAO,QAAQ,CAAC;CAInF,MAAM,SAAS,OAAO,QAAQ,OAAO;CACrC,OAAO,SAAS,GAAG,QAAQ,IAAI,OAAO,KAAK,OAAO,WAAW,KAAK;AACpE;AAEA,SAAS,UAAU,MAAc,aAA8B;CAC7D,IAAI;EACF,OAAO,cAAc,IAAI;CAC3B,QAAQ;EACN,MAAM,IAAI,QAAQ,yBAAyB,WAAW;CACxD;AACF;AAKA,IAAM,UAAU,UAAsB,IAAI,YAAY,SAAS,EAAE,WAAW,KAAK,CAAC,CAAC,CAAC,OAAO,KAAK;AAEhG,IAAM,cAAc,WAAmB,UAAU,OAAO,SAAS;AACjE,IAAM,aAAa,WAAmB,UAAU,OAAO,SAAS"}
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
import { base64url } from "jose";
|
|
2
|
+
//#region ../app-contracts/build/identity/keys.js
|
|
3
|
+
function decodeUtf8(bytes) {
|
|
4
|
+
return new TextDecoder("utf-8", {
|
|
5
|
+
fatal: true,
|
|
6
|
+
ignoreBOM: true
|
|
7
|
+
}).decode(bytes);
|
|
8
|
+
}
|
|
9
|
+
function decodeText(encoded) {
|
|
10
|
+
try {
|
|
11
|
+
return decodeUtf8(base64url.decode(encoded));
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function decodeJson(encoded) {
|
|
17
|
+
const text = decodeText(encoded);
|
|
18
|
+
if (text === void 0) return;
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(text);
|
|
21
|
+
} catch {
|
|
22
|
+
return;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
//#endregion
|
|
26
|
+
//#region ../app-contracts/build/identity/jws.js
|
|
27
|
+
/** The only algorithm either key signs with. */
|
|
28
|
+
var ALGORITHM = "Ed25519";
|
|
29
|
+
/**
|
|
30
|
+
* Reads a JWS protected header that must be exactly `shape`, which is a strict object. Any
|
|
31
|
+
* other member could change what the signature covers, as `b64: false` does, or name
|
|
32
|
+
* another key, so the header is checked before the signature and again when verifying.
|
|
33
|
+
*/
|
|
34
|
+
function readExactHeader(encoded, shape) {
|
|
35
|
+
const parsed = shape.safeParse(decodeJson(encoded));
|
|
36
|
+
return parsed.success ? parsed.data : void 0;
|
|
37
|
+
}
|
|
38
|
+
//#endregion
|
|
39
|
+
//#region src/shared/parse.ts
|
|
40
|
+
var UNSAFE_IN_POLICY = /[\s;,'"*]/;
|
|
41
|
+
/**
|
|
42
|
+
* An HTTP or HTTPS origin, or `undefined` for anything more or less. The URL parser lets `;` and
|
|
43
|
+
* `,` into a host, so the origin must also read back as itself, and hold nothing that would end
|
|
44
|
+
* a source in a Content-Security-Policy.
|
|
45
|
+
*/
|
|
46
|
+
function parseOrigin(entry) {
|
|
47
|
+
const url = URL.parse(entry);
|
|
48
|
+
const origin = url?.origin;
|
|
49
|
+
if (!url || !origin || url.protocol !== "https:" && url.protocol !== "http:" || url.href !== `${origin}/` || URL.parse(origin)?.origin !== origin || UNSAFE_IN_POLICY.test(entry) || UNSAFE_IN_POLICY.test(origin)) return;
|
|
50
|
+
return origin;
|
|
51
|
+
}
|
|
52
|
+
/** JSON text as Ghost reads it: a byte order mark is valid at its start, but JSON.parse refuses it. */
|
|
53
|
+
function parseJsonText(text) {
|
|
54
|
+
return JSON.parse(text.charCodeAt(0) === 65279 ? text.slice(1) : text);
|
|
55
|
+
}
|
|
56
|
+
//#endregion
|
|
57
|
+
//#region src/shared/ignore.ts
|
|
58
|
+
/** For an error that changes nothing, such as one from cancelling what's no longer wanted. */
|
|
59
|
+
var ignoreError = () => void 0;
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region src/shared/manifest.ts
|
|
62
|
+
/** Where an app serves its signed manifest by convention, and where the SDK's tooling signs it for. */
|
|
63
|
+
var MANIFEST_PATH = "/ghost-app.json";
|
|
64
|
+
/**
|
|
65
|
+
* Stands in for the site's own URL when checking a manifest as Ghost would, which nothing but
|
|
66
|
+
* the site knows: a name that's never any site's, so the rest of the rules apply as Ghost
|
|
67
|
+
* applies them.
|
|
68
|
+
*/
|
|
69
|
+
var UNKNOWN_GHOST_URL = "https://ghost.invalid/";
|
|
70
|
+
/** A manifest's problems, one per line, as `path: message`. */
|
|
71
|
+
function formatErrors(errors, separator = "\n") {
|
|
72
|
+
return errors.map(({ path, message }) => path ? `${path}: ${message}` : message).join(separator);
|
|
73
|
+
}
|
|
74
|
+
//#endregion
|
|
75
|
+
export { parseJsonText as a, readExactHeader as c, ignoreError as i, decodeText as l, UNKNOWN_GHOST_URL as n, parseOrigin as o, formatErrors as r, ALGORITHM as s, MANIFEST_PATH as t, decodeUtf8 as u };
|
|
76
|
+
|
|
77
|
+
//# sourceMappingURL=manifest-iOwbzAil.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-iOwbzAil.js","names":[],"sources":["../../../app-contracts/build/identity/keys.js","../../../app-contracts/build/identity/jws.js","../../src/shared/parse.ts","../../src/shared/ignore.ts","../../src/shared/manifest.ts"],"sourcesContent":["import { base64url, calculateJwkThumbprint } from 'jose';\n/**\n * A key's RFC 7638 thumbprint: the same for a key however its JWK is written, so it is\n * what Ghost stores to recognise a key again.\n */\nexport function thumbprintOf(key) {\n return calculateJwkThumbprint({ kty: key.kty, crv: key.crv, x: key.x }, 'sha256');\n}\nexport function decodeUtf8(bytes) {\n return new TextDecoder('utf-8', { fatal: true, ignoreBOM: true }).decode(bytes);\n}\nexport function decodeText(encoded) {\n try {\n return decodeUtf8(base64url.decode(encoded));\n }\n catch {\n return undefined;\n }\n}\nexport function decodeJson(encoded) {\n const text = decodeText(encoded);\n if (text === undefined) {\n return undefined;\n }\n try {\n return JSON.parse(text);\n }\n catch {\n return undefined;\n }\n}\n//# sourceMappingURL=keys.js.map","import { decodeJson } from './keys.js';\n/** The only algorithm either key signs with. */\nexport const ALGORITHM = 'Ed25519';\n/**\n * Reads a JWS protected header that must be exactly `shape`, which is a strict object. Any\n * other member could change what the signature covers, as `b64: false` does, or name\n * another key, so the header is checked before the signature and again when verifying.\n */\nexport function readExactHeader(encoded, shape) {\n const parsed = shape.safeParse(decodeJson(encoded));\n return parsed.success ? parsed.data : undefined;\n}\n//# sourceMappingURL=jws.js.map","// Characters that end a source in a policy, a directive or a whole policy, and the wildcard.\nconst UNSAFE_IN_POLICY = /[\\s;,'\"*]/;\n\n/**\n * An HTTP or HTTPS origin, or `undefined` for anything more or less. The URL parser lets `;` and\n * `,` into a host, so the origin must also read back as itself, and hold nothing that would end\n * a source in a Content-Security-Policy.\n */\nexport function parseOrigin(entry: string): string | undefined {\n const url = URL.parse(entry);\n const origin = url?.origin;\n if (\n !url ||\n !origin ||\n (url.protocol !== 'https:' && url.protocol !== 'http:') ||\n url.href !== `${origin}/` ||\n URL.parse(origin)?.origin !== origin ||\n UNSAFE_IN_POLICY.test(entry) ||\n UNSAFE_IN_POLICY.test(origin)\n ) {\n return undefined;\n }\n return origin;\n}\n\n/** JSON text as Ghost reads it: a byte order mark is valid at its start, but JSON.parse refuses it. */\nexport function parseJsonText(text: string): unknown {\n return JSON.parse(text.charCodeAt(0) === 0xfeff ? text.slice(1) : text);\n}\n","/** For an error that changes nothing, such as one from cancelling what's no longer wanted. */\nexport const ignoreError = (): undefined => undefined;\n","// What the backend, the tooling and the Vite plugin agree on about the signed manifest. Free of\n// Node and of the contracts' validation, as the backend runs on any platform.\n\n/** Where an app serves its signed manifest by convention, and where the SDK's tooling signs it for. */\nexport const MANIFEST_PATH = '/ghost-app.json';\n\n/** A signed manifest: flattened JWS JSON, as `ghost-app sign` or the Vite plugin writes it. */\nexport interface SignedManifest {\n protected: string;\n payload: string;\n signature: string;\n}\n\n/** One problem with a manifest. */\nexport interface ManifestError {\n /** Where in the manifest the problem is, such as `surfaces[0].url`. Empty for the whole. */\n path: string;\n message: string;\n}\n\n/**\n * Stands in for the site's own URL when checking a manifest as Ghost would, which nothing but\n * the site knows: a name that's never any site's, so the rest of the rules apply as Ghost\n * applies them.\n */\nexport const UNKNOWN_GHOST_URL = 'https://ghost.invalid/';\n\n/** A manifest's problems, one per line, as `path: message`. */\nexport function formatErrors(errors: readonly ManifestError[], separator = '\\n'): string {\n return errors\n .map(({ path, message }) => (path ? `${path}: ${message}` : message))\n .join(separator);\n}\n"],"mappings":";;AAQA,SAAgB,WAAW,OAAO;CAC9B,OAAO,IAAI,YAAY,SAAS;EAAE,OAAO;EAAM,WAAW;CAAK,CAAC,CAAC,CAAC,OAAO,KAAK;AAClF;AACA,SAAgB,WAAW,SAAS;CAChC,IAAI;EACA,OAAO,WAAW,UAAU,OAAO,OAAO,CAAC;CAC/C,QACM;EACF;CACJ;AACJ;AACA,SAAgB,WAAW,SAAS;CAChC,MAAM,OAAO,WAAW,OAAO;CAC/B,IAAI,SAAS,KAAA,GACT;CAEJ,IAAI;EACA,OAAO,KAAK,MAAM,IAAI;CAC1B,QACM;EACF;CACJ;AACJ;;;;AC5BA,IAAa,YAAY;;;;;;AAMzB,SAAgB,gBAAgB,SAAS,OAAO;CAC5C,MAAM,SAAS,MAAM,UAAU,WAAW,OAAO,CAAC;CAClD,OAAO,OAAO,UAAU,OAAO,OAAO,KAAA;AAC1C;;;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