Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PM-198 Fix reflected XSS #7024

Merged
merged 3 commits into from
Jan 8, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,8 @@
"url-parse": "^1.4.1",
"uuid": "^3.3.2",
"valid-url": "^1.0.9",
"xml2json": "^0.11.2"
"xml2json": "^0.11.2",
"xss": "^1.0.15"
},
"devDependencies": {
"@commitlint/cli": "^8.3.5",
Expand Down
6 changes: 4 additions & 2 deletions src/server/services/mmLeaderboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Server-side functions necessary for effective integration with MMLeaderboard
*/
import { services } from 'topcoder-react-lib';
import xss from 'xss';

const { api, submissions } = services;

Expand All @@ -17,13 +18,14 @@ export default class MMLService {
*/
async getLeaderboard(req, res, next) {
try {
const sanitizedId = xss(req.params.id);
const m2mToken = await api.getTcM2mToken();
const subSrv = submissions.getService(m2mToken);
const reviewIds = await subSrv.getScanReviewIds();
const v5api = api.getApiV5(m2mToken);
const subs = await v5api.get(`/submissions?challengeId=${req.params.id}&page=1&perPage=500`);
const subs = await v5api.get(`/submissions?challengeId=${sanitizedId}&page=1&perPage=500`);
return res.send({
id: req.params.id,
id: sanitizedId,
subs: await subs.json(),
reviewIds,
});
Expand Down
10 changes: 8 additions & 2 deletions src/server/services/recruitCRM.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import qs from 'qs';
import _ from 'lodash';
import { logger, services } from 'topcoder-react-lib';
import Joi from 'joi';
import xss from 'xss';
import { sendEmailDirect } from './sendGrid';
// import GSheetService from './gSheet';

Expand Down Expand Up @@ -186,7 +187,12 @@ export default class RecruitCRMService {
*/
async getJob(req, res, next) {
try {
const response = await fetch(`${this.private.baseUrl}/v1/jobs/${req.params.id}`, {
const sanitizedId = xss(req.params.id);

if (!/^[a-zA-Z0-9-_]{8,20}$/.test(sanitizedId)) {
return res.status(400).json({ error: 'Invalid job ID format.' });
}
const response = await fetch(`${this.private.baseUrl}/v1/jobs/${sanitizedId}`, {
method: 'GET',
headers: {
'Content-Type': req.headers['content-type'],
Expand All @@ -201,7 +207,7 @@ export default class RecruitCRMService {
const error = {
error: true,
status: response.status,
url: `${this.private.baseUrl}/v1/jobs/${req.params.id}`,
url: `${this.private.baseUrl}/v1/jobs/${sanitizedId}`,
errObj: await response.json(),
};
logger.error(error);
Expand Down
Loading