Constrain project thumbnail responses

This commit is contained in:
Benjamin Oezcan
2026-11-29 23:49:29 +01:00
parent e1d88575fb
commit c4328c5449
2 changed files with 16 additions and 1 deletions

View File

@@ -209,7 +209,8 @@ function findThumbnail(name, projectPath) {
const override = readStatusFile(projectPath).thumbnail
if (override) {
const candidate = path.resolve(projectPath, override)
if (candidate.startsWith(projectPath + path.sep) && fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
if (Object.hasOwn(IMAGE_EXT, path.extname(candidate).toLowerCase()) &&
candidate.startsWith(projectPath + path.sep) && fs.existsSync(candidate) && fs.statSync(candidate).isFile()) {
file = candidate
}
}
@@ -776,6 +777,9 @@ app.get('/api/projects/:name/thumb', (req, res) => {
const file = findThumbnail(req.params.name, projectPath)
if (!file) return res.status(404).end()
res.setHeader('Cache-Control', 'public, max-age=300')
// A project SVG can also be opened directly as a document.
res.setHeader('Content-Security-Policy', "sandbox; default-src 'none'")
res.setHeader('X-Content-Type-Options', 'nosniff')
res.sendFile(file, (err) => { if (err && !res.headersSent) res.status(404).end() })
})