mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-10-26 16:46:12 +01:00
fix: escape flag reason
This commit is contained in:
@@ -454,7 +454,7 @@ Flags.getReports = async function (flagId) {
|
|||||||
const [reports, uids] = payload.reduce((memo, cur) => {
|
const [reports, uids] = payload.reduce((memo, cur) => {
|
||||||
const value = cur.value.split(';');
|
const value = cur.value.split(';');
|
||||||
memo[1].push(value.shift());
|
memo[1].push(value.shift());
|
||||||
cur.value = value.join(';');
|
cur.value = validator.escape(String(value.join(';')));
|
||||||
memo[0].push(cur);
|
memo[0].push(cur);
|
||||||
|
|
||||||
return memo;
|
return memo;
|
||||||
|
|||||||
@@ -696,16 +696,16 @@ describe('Flags', () => {
|
|||||||
describe('(websockets)', () => {
|
describe('(websockets)', () => {
|
||||||
const SocketFlags = require('../src/socket.io/flags.js');
|
const SocketFlags = require('../src/socket.io/flags.js');
|
||||||
let pid;
|
let pid;
|
||||||
|
let tid;
|
||||||
before((done) => {
|
before((done) => {
|
||||||
Topics.post({
|
Topics.post({
|
||||||
cid: 1,
|
cid: 1,
|
||||||
uid: 1,
|
uid: 1,
|
||||||
title: 'Another topic',
|
title: 'Another topic',
|
||||||
content: 'This is flaggable content',
|
content: 'This is flaggable content',
|
||||||
}, (err, topic) => {
|
}, (err, result) => {
|
||||||
pid = topic.postData.pid;
|
pid = result.postData.pid;
|
||||||
|
tid = result.topicData.tid;
|
||||||
done(err);
|
done(err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -727,6 +727,23 @@ describe('Flags', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should escape flag reason', async () => {
|
||||||
|
const postData = await Topics.reply({
|
||||||
|
tid: tid,
|
||||||
|
uid: 1,
|
||||||
|
content: 'This is flaggable content',
|
||||||
|
});
|
||||||
|
|
||||||
|
const flagId = await SocketFlags.create({ uid: 2 }, {
|
||||||
|
type: 'post',
|
||||||
|
id: postData.pid,
|
||||||
|
reason: '"<script>alert(\'ok\');</script>',
|
||||||
|
});
|
||||||
|
|
||||||
|
const flagData = await Flags.get(flagId);
|
||||||
|
assert.strictEqual(flagData.reports[0].value, '"<script>alert('ok');</script>');
|
||||||
|
});
|
||||||
|
|
||||||
it('should not allow flagging post in private category', async () => {
|
it('should not allow flagging post in private category', async () => {
|
||||||
const category = await Categories.create({ name: 'private category' });
|
const category = await Categories.create({ name: 'private category' });
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user