Skip to content

Commit 1ce3623

Browse files
committed
Update astro.config.mjs
1 parent c9a0eaf commit 1ce3623

File tree

1 file changed

+19
-3
lines changed

1 file changed

+19
-3
lines changed

docs/astro.config.mjs

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,30 @@ import { defineConfig } from "astro/config";
22
import starlight from "@astrojs/starlight";
33
import { ExpressiveCodeTheme } from "@astrojs/starlight/expressive-code";
44
import fs from "node:fs";
5+
import path from "node:path";
56
import starlightImageZoom from "starlight-image-zoom";
67

8+
// Define allowed paths relative to project root
9+
const ALLOWED_PATHS = ["src/themes/expressive-code"];
10+
711
function readFileSyncSafe(url) {
8-
if (url.protocol === "file:") {
9-
return fs.readFileSync(url, "utf-8");
10-
} else {
12+
if (url.protocol !== "file:") {
1113
throw new Error("Invalid URL protocol");
1214
}
15+
16+
// Convert URL to filesystem path and normalize
17+
const filePath = path.normalize(url.pathname);
18+
19+
// Ensure path is within allowed directories
20+
const isAllowed = ALLOWED_PATHS.some((allowedPath) =>
21+
filePath.includes(path.normalize(allowedPath))
22+
);
23+
24+
if (!isAllowed) {
25+
throw new Error("Access to this directory is not allowed");
26+
}
27+
28+
return fs.readFileSync(url, "utf-8");
1329
}
1430

1531
const jsoncStringLight = readFileSyncSafe(

0 commit comments

Comments
 (0)