Skip to content

Commit fb2ef82

Browse files
committed
fix(attachments): file type security fix
1 parent 9c2c49a commit fb2ef82

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/client/containers/Tickets/IssuePartial.jsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,10 +99,12 @@ class IssuePartial extends React.Component {
9999
const attachmentFile = e.target.files[0]
100100
formData.append('ticketId', this.ticketId)
101101
formData.append('attachment', attachmentFile)
102+
const token = document.querySelector('meta[name="csrf-token"]').getAttribute('content')
102103
axios
103104
.post(`/tickets/uploadattachment`, formData, {
104105
headers: {
105-
'Content-Type': 'multipart/form-data'
106+
'Content-Type': 'multipart/form-data',
107+
'CSRF-TOKEN': token
106108
}
107109
})
108110
.then(() => {

src/controllers/tickets.js

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,9 +704,33 @@ ticketsController.uploadAttachment = function (req, res) {
704704
let sanitizedFilename = filename.replace(/[^a-z0-9.]/gi, '_').toLowerCase()
705705

706706
const ext = path.extname(sanitizedFilename)
707+
const allowedExts = [
708+
'.png',
709+
'.jpg',
710+
'.jpeg',
711+
'.tif',
712+
'.gif',
713+
'.doc',
714+
'.docx',
715+
'.xlsx',
716+
'.xls',
717+
'.pdf',
718+
'.zip',
719+
'.rar',
720+
'.7z',
721+
'.mp3',
722+
'.wav',
723+
'.txt',
724+
'.mp4',
725+
'.avi',
726+
'.mpeg',
727+
'.eps',
728+
'.ai',
729+
'.psd'
730+
]
707731
const badExts = ['.html', '.htm', '.js', '.svg']
708732

709-
if (badExts.includes(ext)) {
733+
if (!allowedExts.includes(ext)) {
710734
error = {
711735
status: 400,
712736
message: 'Invalid File Type'

src/routes/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -203,7 +203,12 @@ function mainRoutes (router, middleware, controllers) {
203203
router.get('/tickets/print/:uid', middleware.redirectToLogin, middleware.loadCommonData, controllers.tickets.print)
204204
router.get('/tickets/:id', middleware.redirectToLogin, middleware.loadCommonData, controllers.tickets.single)
205205
// router.post('/tickets/postcomment', middleware.redirectToLogin, controllers.tickets.postcomment);
206-
router.post('/tickets/uploadattachment', middleware.redirectToLogin, controllers.tickets.uploadAttachment)
206+
router.post(
207+
'/tickets/uploadattachment',
208+
middleware.redirectToLogin,
209+
middleware.csrfCheck,
210+
controllers.tickets.uploadAttachment
211+
)
207212
router.post('/tickets/uploadmdeimage', middleware.redirectToLogin, controllers.tickets.uploadImageMDE)
208213

209214
// Messages

0 commit comments

Comments
 (0)