@backmatter/core 0.0.59 → 0.0.60
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/preview-session.ts +5 -0
- package/src/preview.ts +0 -22
package/package.json
CHANGED
package/src/preview-session.ts
CHANGED
|
@@ -53,6 +53,11 @@ export type PreviewCookiePayload = {
|
|
|
53
53
|
export function isSafeRedirectPath(path: string): boolean {
|
|
54
54
|
if (!path.startsWith("/") || path.startsWith("//")) return false;
|
|
55
55
|
if (path.includes("://")) return false;
|
|
56
|
+
// Browsers read `\` as `/` and drop tabs and newlines, so `/\evil.example` is another host.
|
|
57
|
+
for (const char of path) {
|
|
58
|
+
const code = char.charCodeAt(0);
|
|
59
|
+
if (char === "\\" || code < 0x20 || code === 0x7f) return false;
|
|
60
|
+
}
|
|
56
61
|
return true;
|
|
57
62
|
}
|
|
58
63
|
|
package/src/preview.ts
CHANGED
|
@@ -166,28 +166,6 @@ export async function setHostSitePreview(origin = ""): Promise<boolean> {
|
|
|
166
166
|
}
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
-
export type CmsSessionUser = { id: string; email: string; name: string };
|
|
170
|
-
|
|
171
|
-
/** Cookie session on the CMS API. Fail closed: empty URL, 401, errors → null. */
|
|
172
|
-
export async function fetchCmsSession(
|
|
173
|
-
apiUrl: string,
|
|
174
|
-
): Promise<CmsSessionUser | null> {
|
|
175
|
-
const base = baseUrl(apiUrl.trim());
|
|
176
|
-
if (!base) return null;
|
|
177
|
-
try {
|
|
178
|
-
const res = await fetch(`${base}/me`, {
|
|
179
|
-
credentials: "include",
|
|
180
|
-
cache: "no-store",
|
|
181
|
-
});
|
|
182
|
-
if (!res.ok) return null;
|
|
183
|
-
const data = (await res.json()) as { user?: CmsSessionUser };
|
|
184
|
-
if (!data.user?.id) return null;
|
|
185
|
-
return data.user;
|
|
186
|
-
} catch {
|
|
187
|
-
return null;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
|
|
191
169
|
function previewParams(options: PreviewClientOptions, ref: PreviewDocRef) {
|
|
192
170
|
const params = new URLSearchParams({ token: options.previewToken });
|
|
193
171
|
if (ref.branch) params.set("branch", ref.branch);
|