File tree Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Expand file tree Collapse file tree 1 file changed +5
-5
lines changed Original file line number Diff line number Diff line change @@ -52,13 +52,13 @@ export const getAllDocsCategories = () => {
52
52
} ;
53
53
54
54
export const getMdxBySlug = async ( basePath : string , slug : string ) => {
55
- const mdxPath = path . join ( DATA_PATH , basePath , `${ slug } .mdx` ) ;
55
+ // Construct and resolve the path to prevent path traversal
56
+ const mdxPath = path . resolve ( DATA_PATH , basePath , `${ slug } .mdx` ) ;
57
+ // Ensure the resolved path is within DATA_PATH
58
+ if ( ! mdxPath . startsWith ( DATA_PATH + path . sep ) ) return ;
56
59
if ( ! fs . existsSync ( mdxPath ) ) return ;
57
60
58
- const source = fs . readFileSync (
59
- path . join ( DATA_PATH , basePath , `${ slug } .mdx` ) ,
60
- "utf8" ,
61
- ) ;
61
+ const source = fs . readFileSync ( mdxPath , "utf8" ) ;
62
62
63
63
const { frontmatter, code } = await bundleMDX ( { source } ) ;
64
64
You can’t perform that action at this time.
0 commit comments