Commit 701207ef authored by GitLab Release Tools Bot's avatar GitLab Release Tools Bot

Merge branch 'security-mr-reviewer-xss' into 'master'

Escapes MR approval rule names correctly

See merge request gitlab-org/security/gitlab!1760
parents 5af8042d a3af82b0
......@@ -842,7 +842,7 @@ UsersSelect.prototype.renderApprovalRules = function (elsClassName, approvalRule
const [rule] = approvalRules;
const countText = sprintf(__('(+%{count} rules)'), { count });
const renderApprovalRulesCount = count > 1 ? `<span class="ml-1">${countText}</span>` : '';
const ruleName = rule.rule_type === 'code_owner' ? __('Code Owner') : rule.name;
const ruleName = rule.rule_type === 'code_owner' ? __('Code Owner') : escape(rule.name);
return `<div class="gl-display-flex gl-font-sm">
<span class="gl-text-truncate" title="${ruleName}">${ruleName}</span>
......
import { escape } from 'lodash';
import UsersSelect from '~/users_select/index';
import {
createInputsModelExpectation,
createUnassignedExpectation,
......@@ -91,5 +93,19 @@ describe('~/users_select/index', () => {
expect(findDropdownItemsModel()).toEqual(expectation);
});
});
describe('renderApprovalRules', () => {
const ruleNames = ['simple-name', '"\'<>&', '"><script>alert(1)<script>'];
it.each(ruleNames)('escapes rule name correctly for %s', (name) => {
const escapedName = escape(name);
expect(
UsersSelect.prototype.renderApprovalRules('reviewer', [{ name }]),
).toMatchInterpolatedText(
`<div class="gl-display-flex gl-font-sm"> <span class="gl-text-truncate" title="${escapedName}">${escapedName}</span> </div>`,
);
});
});
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment