File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -14,6 +14,7 @@ const Logger = require('./Logger');
1414const analyzer = require ( './analyzer' ) ;
1515
1616const projectRoot = path . resolve ( __dirname , '..' ) ;
17+ const assetsRoot = path . join ( projectRoot , 'public' ) ;
1718
1819module . exports = {
1920 startServer,
@@ -169,7 +170,13 @@ async function generateReport(bundleStats, opts) {
169170}
170171
171172function getAssetContent ( filename ) {
172- return fs . readFileSync ( `${ projectRoot } /public/${ filename } ` , 'utf8' ) ;
173+ const assetPath = path . join ( assetsRoot , filename ) ;
174+
175+ if ( ! assetPath . startsWith ( assetsRoot ) ) {
176+ throw new Error ( `"${ filename } " is outside of the assets root` ) ;
177+ }
178+
179+ return fs . readFileSync ( assetPath , 'utf8' ) ;
173180}
174181
175182/**
Original file line number Diff line number Diff line change 44 < %- escapeScript (assetContent (filename)) % >
55 < / script>
66< % } else { % >
7- < script src= " / <%= filename %>" >< / script>
7+ < script src= " <%= filename %>" >< / script>
88< % } %>
You can’t perform that action at this time.
0 commit comments