Skip to content

Commit b7b6218

Browse files
committed
Fix possible line-ending issues for init note
By uploading a malicous note currently it is possible to prevent this note from being edited. This happens when using Windows line endings. With this commit we remove all `\r` characters from the notes and this way prevent this problem. Signed-off-by: Sheogorath <sheogorath@shivering-isles.com>
1 parent 7c7cc28 commit b7b6218

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

lib/response.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,8 @@ function responseHackMD (res, note) {
145145

146146
function newNote (req, res, next) {
147147
var owner = null
148+
var body = req.body ? req.body : ''
149+
body = body.replace(/[\r]/g, '')
148150
if (req.isAuthenticated()) {
149151
owner = req.user.id
150152
} else if (!config.allowAnonymous) {
@@ -153,7 +155,7 @@ function newNote (req, res, next) {
153155
models.Note.create({
154156
ownerId: owner,
155157
alias: req.alias ? req.alias : null,
156-
content: req.body ? req.body : ''
158+
content: body
157159
}).then(function (note) {
158160
return res.redirect(config.serverURL + '/' + models.Note.encodeNoteId(note.id))
159161
}).catch(function (err) {

0 commit comments

Comments
 (0)