Commit e40eba87 authored by Peter Hegman's avatar Peter Hegman Committed by GitLab Release Tools Bot

Sanitize admin email "Recipient Group" dropdown options

Dropdown is found at `admin/email`. Passes dropdown options through
`sanitizeItem`.  To prevent errors `sanitizeItem` is updated to check
if `name` and `namespace` keys exist before sanitizing.
parent ec39a640
......@@ -45,8 +45,19 @@ export const updateExistingFrequentItem = (frequentItem, item) => {
};
};
export const sanitizeItem = item => ({
...item,
name: sanitize(item.name.toString(), { allowedTags: [] }),
namespace: sanitize(item.namespace.toString(), { allowedTags: [] }),
});
export const sanitizeItem = item => {
// Only sanitize if the key exists on the item
const maybeSanitize = key => {
if (!Object.prototype.hasOwnProperty.call(item, key)) {
return {};
}
return { [key]: sanitize(item[key].toString(), { allowedTags: [] }) };
};
return {
...item,
...maybeSanitize('name'),
...maybeSanitize('namespace'),
};
};
---
title: Fix XSS vulnerability in `admin/email` "Recipient Group" dropdown
merge_request:
author:
type: security
import $ from 'jquery';
import Api from '~/api';
import { sprintf, __ } from '~/locale';
import { sanitizeItem } from '~/frequent_items/utils';
const formatResult = selectedItem => {
if (selectedItem.path_with_namespace) {
......@@ -38,7 +39,7 @@ const AdminEmailSelect = () => {
const all = {
id: 'all',
};
const data = [all].concat(groups, projects.data);
const data = [all].concat(groups, projects.data).map(sanitizeItem);
return query.callback({
results: data,
});
......
......@@ -108,5 +108,23 @@ describe('Frequent Items utils spec', () => {
expect(sanitizeItem(input)).toEqual({ name: 'test', namespace: 'test', id: 1 });
});
it("skips `name` key if it doesn't exist on the item", () => {
const input = {
namespace: '<br>test',
id: 1,
};
expect(sanitizeItem(input)).toEqual({ namespace: 'test', id: 1 });
});
it("skips `namespace` key if it doesn't exist on the item", () => {
const input = {
name: '<br><b>test</b>',
id: 1,
};
expect(sanitizeItem(input)).toEqual({ name: 'test', id: 1 });
});
});
});
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