Constrain project thumbnail responses
This commit is contained in:
@@ -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() })
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user