GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(server): an HTML preview loads its files from the page's own fold… · patroza/t3code@bed9141

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • apps/server/src/assets
    • AssetAccess.test.ts
    • AssetAccess.ts
  • docs/internals
    • 04_environment-auth.md
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎apps/server/src/assets/AssetAccess.test.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/assets/AssetAccess.test.ts
+60-1Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1172,7 +1172,8 @@ describe("AssetAccess", () => {
11721172
target: path.join(reportsDirectory, ".cache", "hidden.css"),
11731173
allowed: false,
11741174
},
1175-
{ name: "shared.css", target: path.join(root, "shared.css"), allowed: true },
1175+
{ name: "shared.css", target: path.join(root, "shared.css"), allowed: false },
1176+
{ name: "local.css", target: path.join(reportsDirectory, "real.css"), allowed: true },
11761177
];
11771178
for (const { name, target } of dependencies) {
11781179
yield* fs.writeFileString(target, "fixture");
@@ -1199,6 +1200,64 @@ describe("AssetAccess", () => {
11991200
}).pipe(Effect.provide(layerTest)),
12001201
);
12011202

1203+
it.effect.skipIf(!symlinksSupported)(
1204+
"serves an HTML preview's files from the page's own folder only",
1205+
() =>
1206+
Effect.gen(function* () {
1207+
const fs = yield* FileSystem.FileSystem;
1208+
const path = yield* Path.Path;
1209+
const root = yield* fs.makeTempDirectoryScoped();
1210+
const site = path.join(root, "site");
1211+
for (const directory of ["site/img", "src", "templates"]) {
1212+
yield* fs.makeDirectory(path.join(root, directory), { recursive: true });
1213+
}
1214+
for (const name of [
1215+
"site/page.html",
1216+
"site/app.js",
1217+
"site/img/logo.png",
1218+
"src/main.js",
1219+
"templates/page.html",
1220+
]) {
1221+
yield* fs.writeFileString(path.join(root, name), "fixture");
1222+
}
1223+
yield* fs.symlink(path.join(root, "src", "main.js"), path.join(site, "main.js"));
1224+
yield* fs.symlink(path.join(root, "src"), path.join(site, "vendor"));
1225+
yield* fs.symlink(path.join(site, "app.js"), path.join(site, "alias.js"));
1226+
yield* fs.symlink(
1227+
path.join(root, "templates", "page.html"),
1228+
path.join(site, "linked.html"),
1229+
);
1230+
1231+
const tokenFor = Effect.fn(function* (entry: string) {
1232+
const result = yield* issueAssetUrl({
1233+
resource: {
1234+
_tag: "workspace-file",
1235+
threadId: ThreadId.make("thread-1"),
1236+
path: path.join(site, entry),
1237+
},
1238+
workspaceRoot: root,
1239+
});
1240+
const suffix = result.relativeUrl.slice(ASSET_ROUTE_PREFIX.length + 1);
1241+
return suffix.slice(0, suffix.indexOf("/"));
1242+
});
1243+
const token = yield* tokenFor("page.html");
1244+
for (const name of ["page.html", "app.js", "alias.js", "img/logo.png"]) {
1245+
expect(yield* resolveAsset(token, name), name).toMatchObject({ kind: "file" });
1246+
}
1247+
for (const name of ["main.js", "vendor/main.js", "linked.html"]) {
1248+
expect(yield* resolveAsset(token, name), name).toBeNull();
1249+
}
1250+
1251+
// The opened page may itself be a link; the files it loads still come from its folder.
1252+
const linkedToken = yield* tokenFor("linked.html");
1253+
expect(yield* resolveAsset(linkedToken, "linked.html")).toMatchObject({
1254+
path: yield* fs.realPath(path.join(root, "templates", "page.html")),
1255+
});
1256+
expect(yield* resolveAsset(linkedToken, "app.js")).toMatchObject({ kind: "file" });
1257+
expect(yield* resolveAsset(linkedToken, "main.js")).toBeNull();
1258+
}).pipe(Effect.provide(layerTest)),
1259+
);
1260+
12021261
it.effect("issues workspace URLs that resolve the entry file and sibling assets", () =>
12031262
Effect.gen(function* () {
12041263
const fileSystem = yield* FileSystem.FileSystem;
Collapse file

‎apps/server/src/assets/AssetAccess.ts‎

Copy file name to clipboardExpand all lines: apps/server/src/assets/AssetAccess.ts
+9-4Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -332,6 +332,8 @@ const resolveCanonicalWorkspaceFile = Effect.fn("AssetAccess.resolveCanonicalWor
332332
readonly relativePath: string;
333333
/** The HTML entry's folder, relative to the root, when serving one of its dependencies. */
334334
readonly previewBaseRelativePath?: string;
335+
/** The request is for the opened page itself, which may be a link to elsewhere in the root. */
336+
readonly previewEntry?: boolean;
335337
}) {
336338
const fileSystem = yield* FileSystem.FileSystem;
337339
const workspacePaths = yield* WorkspacePaths.WorkspacePaths;
@@ -354,16 +356,17 @@ const resolveCanonicalWorkspaceFile = Effect.fn("AssetAccess.resolveCanonicalWor
354356
if (relative === "" || relative.startsWith("..") || path.isAbsolute(relative)) return null;
355357

356358
if (input.previewBaseRelativePath !== undefined) {
357-
// The opened entry's own folder may be hidden; nothing below it, or reached outside it, may.
359+
// The opened entry's own folder may be hidden; nothing below it may.
358360
const canonicalBase = yield* ProjectFaviconResolver.optionOnNotFound(
359361
fileSystem.realPath(path.join(canonicalRoot.value, input.previewBaseRelativePath)),
360362
);
361363
const belowBase = Option.isSome(canonicalBase)
362364
? path.relative(canonicalBase.value, canonicalFile.value)
363365
: "..";
364-
const dependency =
365-
belowBase.startsWith("..") || path.isAbsolute(belowBase) ? relative : belowBase;
366-
if (!isPreviewDependencyPath(dependency, path)) return null;
366+
const outsideBase = belowBase.startsWith("..") || path.isAbsolute(belowBase);
367+
// Only the opened page may resolve outside its folder; the files it loads may not.
368+
if (outsideBase && input.previewEntry !== true) return null;
369+
if (!isPreviewDependencyPath(outsideBase ? relative : belowBase, path)) return null;
367370
}
368371

369372
const info = yield* ProjectFaviconResolver.optionOnNotFound(
@@ -379,6 +382,7 @@ const resolveCanonicalWorkspaceFileForRequest = (input: {
379382
readonly workspaceRoot: string;
380383
readonly relativePath: string;
381384
readonly previewBaseRelativePath?: string;
385+
readonly previewEntry?: boolean;
382386
}) =>
383387
resolveCanonicalWorkspaceFile(input).pipe(
384388
Effect.tapError((cause) =>
@@ -1153,6 +1157,7 @@ export const resolveAsset = Effect.fn("AssetAccess.resolveAsset")(function* (
11531157
workspaceRoot: claims.workspaceRoot,
11541158
relativePath: joinedRelativePath,
11551159
previewBaseRelativePath: claims.baseRelativePath,
1160+
previewEntry: decodedPath === claims.entryFileName,
11561161
});
11571162
return workspaceFile
11581163
? ({ kind: "file", path: workspaceFile, renderIntent: "file-preview" } satisfies ResolvedAsset)
Collapse file

‎docs/internals/04_environment-auth.md‎

Copy file name to clipboardExpand all lines: docs/internals/04_environment-auth.md
+5-2Lines changed: 5 additions & 2 deletions
  • Display the source diff
  • Display the rich diff
Original file line numberDiff line numberDiff line change
@@ -151,5 +151,8 @@ relative paths and writes remain constrained by
151151

152152
Signed asset URLs are bearer credentials for a single canonical file, rechecked by device/inode
153153
identity on serve ([`AssetAccess.ts`](../../apps/server/src/assets/AssetAccess.ts)). They never
154-
grant access to sibling files, and because `filesystem:read` is checked only at mint time, an issued
155-
URL remains valid until it expires even if the session or grant is revoked.
154+
grant access to sibling files, with one exception: the URL of an HTML page opened from a workspace
155+
also serves the files that page loads (styles, scripts, images, media, fonts and other pages) from
156+
the page's own folder and the folders below it. It serves no hidden file, and no file that a link
157+
in that folder points to outside it. Because `filesystem:read` is checked only at mint time, an
158+
issued URL remains valid until it expires even if the session or grant is revoked.

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.