Skip to content

Commit

Permalink
PSW-28 Fix potential XSS exploit on WOPI API (#4925)
Browse files Browse the repository at this point in the history
  • Loading branch information
dyedwiper authored Apr 15, 2024
1 parent 382839a commit 9dfe1b4
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion src/services/wopi/hooks/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable no-multi-spaces */

const { authenticate } = require('@feathersjs/authentication');
const { isProvider, iff } = require('feathers-hooks-common');
const { NotFound, BadRequest, Conflict } = require('../../../errors');
const { FileModel } = require('../../fileStorage/model');
const { mapPayload } = require('../../../hooks');
Expand Down Expand Up @@ -92,6 +93,14 @@ const setLockResponseHeader = (hook) => {
return hook;
};

const setContentDispositionHeader = (context) => {
// Setting this header should prevent HTML files from being openend in the browser, because that could be exploited by sending a direct link to a malicious file.
// Since this endpoint is not intended to be used by a browser, we can safely set the header for all responses.
context.http.headers = { 'Content-Disposition': 'attachment' };

return context;
};

exports.before = {
all: [wopiAuthentication, mapPayload],
find: [],
Expand All @@ -104,7 +113,7 @@ exports.before = {

exports.after = {
all: [],
find: [],
find: [iff(isProvider('rest'), setContentDispositionHeader)],
get: [],
create: [setLockResponseHeader],
update: [],
Expand Down

0 comments on commit 9dfe1b4

Please sign in to comment.