File tree Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Expand file tree Collapse file tree 1 file changed +19
-3
lines changed Original file line number Diff line number Diff line change @@ -2,14 +2,30 @@ import { defineConfig } from "astro/config";
22import starlight from "@astrojs/starlight" ;
33import { ExpressiveCodeTheme } from "@astrojs/starlight/expressive-code" ;
44import fs from "node:fs" ;
5+ import path from "node:path" ;
56import starlightImageZoom from "starlight-image-zoom" ;
67
8+ // Define allowed paths relative to project root
9+ const ALLOWED_PATHS = [ "src/themes/expressive-code" ] ;
10+
711function 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
1531const jsoncStringLight = readFileSyncSafe (
You can’t perform that action at this time.
0 commit comments