Skip to content

Commit

Permalink
Merge pull request #1790 from galaxian85/bugfix/pandoc-security-issue
Browse files Browse the repository at this point in the history
  • Loading branch information
jackycute authored Mar 9, 2023
2 parents 342ff2b + 5d72fae commit b09a472
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/note/noteActions.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,17 @@ async function actionPandoc (req, res, note) {
var path = config.tmpPath + '/' + Date.now()
content = content.replace(/\]\(\//g, '](' + url + '/')

// TODO: check export type
const { exportType } = req.query
const contentType = outputFormats[exportType]

try {
// TODO: timeout rejection
if (!contentType) {
return res.sendStatus(400)
}

await pandoc.convertToFile(content, 'markdown', exportType, path, [
'--metadata', `title=${title}`
'--metadata', `title=${title}`, '--sandbox'
])

var stream = fs.createReadStream(path)
Expand All @@ -149,7 +152,7 @@ async function actionPandoc (req, res, note) {
// Ideally this should strip them
res.setHeader('Content-disposition', `attachment; filename="${filename}.${exportType}"`)
res.setHeader('Cache-Control', 'private')
res.setHeader('Content-Type', `${outputFormats[exportType]}; charset=UTF-8`)
res.setHeader('Content-Type', `${contentType}; charset=UTF-8`)
res.setHeader('X-Robots-Tag', 'noindex, nofollow') // prevent crawling
stream.pipe(res)
} catch (err) {
Expand Down

0 comments on commit b09a472

Please sign in to comment.