Skip to content

Commit 58e0530

Browse files
use xss to prevent cross-site scripting on challenge name/description
1 parent 7fa2075 commit 58e0530

File tree

3 files changed

+21
-7
lines changed

3 files changed

+21
-7
lines changed

package-lock.json

+15-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
"topcoder-bus-api-wrapper": "topcoder-platform/tc-bus-api-wrapper.git",
5656
"uuid": "^3.3.2",
5757
"winston": "^3.1.0",
58-
"xss": "^1.0.6",
58+
"xss": "^1.0.8",
5959
"yamljs": "^0.3.0"
6060
},
6161
"standard": {

src/services/ChallengeService.js

+5
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ const _ = require('lodash')
66
const Joi = require('joi')
77
const uuid = require('uuid/v4')
88
const config = require('config')
9+
const xss = require('xss')
910
const helper = require('../common/helper')
1011
const logger = require('../common/logger')
1112
const errors = require('../common/errors')
@@ -746,6 +747,8 @@ async function populatePhases (phases, startDate, timelineTemplateId) {
746747
* @returns {Object} the created challenge
747748
*/
748749
async function createChallenge (currentUser, challenge, userToken) {
750+
challenge.name = xss(challenge.name)
751+
challenge.description = xss(challenge.description)
749752
if (challenge.status === constants.challengeStatuses.Active) {
750753
throw new errors.BadRequestError('You cannot create an Active challenge. Please create a Draft challenge and then change the status to Active.')
751754
}
@@ -1566,6 +1569,8 @@ function sanitizeChallenge (challenge) {
15661569
'attachmentIds',
15671570
'groups'
15681571
])
1572+
sanitized.name = xss(sanitized.name)
1573+
sanitized.description = xss(sanitized.description)
15691574
if (challenge.legacy) {
15701575
sanitized.legacy = _.pick(challenge.legacy, [
15711576
'track',

0 commit comments

Comments
 (0)