Skip to content

Commit ed99c32

Browse files
committed
Use relative links for serving internal assets
1 parent 3ce1b8c commit ed99c32

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

src/viewer.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ const Logger = require('./Logger');
1414
const analyzer = require('./analyzer');
1515

1616
const projectRoot = path.resolve(__dirname, '..');
17+
const assetsRoot = path.join(projectRoot, 'public');
1718

1819
module.exports = {
1920
startServer,
@@ -169,7 +170,13 @@ async function generateReport(bundleStats, opts) {
169170
}
170171

171172
function 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
/**

views/script.ejs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@
44
<%- escapeScript(assetContent(filename)) %>
55
</script>
66
<% } else { %>
7-
<script src="/<%= filename %>"></script>
7+
<script src="<%= filename %>"></script>
88
<% } %>

0 commit comments

Comments
 (0)