Skip to content

Commit

Permalink
Fixes #25169 - fix xss on pages with breadcrumbs
Browse files Browse the repository at this point in the history
(cherry picked from commit 3a0c10c)
  • Loading branch information
amirfefer authored and tbrisker committed Nov 5, 2018
1 parent 8b3afc3 commit bd57e02
Show file tree
Hide file tree
Showing 21 changed files with 145 additions and 53 deletions.
10 changes: 5 additions & 5 deletions app/assets/javascripts/host_edit_interfaces.js
Expand Up @@ -317,12 +317,12 @@ $(document).on('change', '.virtual', function () {
function update_fqdn() {
var host_name = $('#host_name').val();
var domain_name = primary_nic_form().find('.interface_domain option:selected').text();

var pathname = window.location.pathname;
var name = fqdn(host_name, domain_name)
if (name.length > 0)
name = "| " + name

$('#hostFQDN').text(name);
if (name.length > 0 && pathname === '/hosts/new') {
name = __("Create Host") + " | " + name
tfm.breadcrumbs.updateTitle(name);
}
}

$(document).on('change', '.interface_mac', function (event) {
Expand Down
5 changes: 0 additions & 5 deletions app/helpers/hosts_helper.rb
Expand Up @@ -67,11 +67,6 @@ def host_taxonomy_select(f, taxonomy)
select_opts, html_opts
end

def new_host_title
t = _("Create Host")
title(t, (t + ' <span id="hostFQDN"></span>').html_safe)
end

def flags_for_nic(nic)
flags = ""
flags += "<i class=\"nic-flag glyphicon glyphicon glyphicon-tag\" title=\"#{_('Primary')}\"></i>" if nic.primary?
Expand Down
2 changes: 1 addition & 1 deletion app/helpers/layout_helper.rb
@@ -1,7 +1,7 @@
module LayoutHelper
def title(page_title, page_header = nil)
content_for(:title, page_title.to_s)
@page_header ||= page_header || @content_for_title || page_title.to_s
@page_header ||= page_header || page_title.to_s
end

def title_actions(*elements)
Expand Down
1 change: 1 addition & 0 deletions app/helpers/operatingsystems_helper.rb
Expand Up @@ -44,6 +44,7 @@ def icon(record, opts = {})
return "" if record.family.blank?
record.family
end
return image_path(family + ".png") if opts[:path]

image_tag(family + ".png", opts) + " "
end
Expand Down
3 changes: 1 addition & 2 deletions app/views/hosts/new.html.erb
@@ -1,3 +1,2 @@
<% new_host_title %>
<% title _("Create Host") %>
<%= render :partial => 'form' %>
2 changes: 1 addition & 1 deletion app/views/hosts/show.html.erb
@@ -1,5 +1,5 @@
<% javascript 'charts', 'hosts' %>
<% title @host.to_label, icon(@host.operatingsystem) + @host.to_label %>
<% title @host.to_label, text: @host.to_label, icon: icon(@host.operatingsystem, path: true) %>
<% host_breadcrumb %>
<%= host_title_actions(@host) %>
<% content_for(:search_bar) {reports_show} %>
Expand Down
1 change: 0 additions & 1 deletion test/integration/host_js_test.rb
Expand Up @@ -596,7 +596,6 @@ class HostJSTest < IntegrationTestWithJavascript
modal.find(:button, "Ok").click

assert table.find('td.fqdn').has_content?('name.' + domain.name)
assert page.find('#hostFQDN').has_content?('| name.' + domain.name)

click_link('host_tab')
assert_equal 'name', page.find('#host_name', :visible => false).value
Expand Down
1 change: 1 addition & 0 deletions webpack/assets/javascripts/bundle.js
Expand Up @@ -36,4 +36,5 @@ window.tfm = Object.assign(window.tfm || {}, {
editor: require('./foreman_editor'),
nav: require('./foreman_navigation'),
medium: require('./foreman_medium'),
breadcrumbs: require('./foreman_breadcrumbs'),
});
6 changes: 6 additions & 0 deletions webpack/assets/javascripts/foreman_breadcrumbs.js
@@ -0,0 +1,6 @@
import store from './react_app/redux';

import { updateBreadcrumbTitle } from './react_app/components/BreadcrumbBar/BreadcrumbBarActions';

export const updateTitle = title =>
store.dispatch(updateBreadcrumbTitle(title));
Expand Up @@ -24,6 +24,20 @@ export const breadcrumbTitleItems = {
],
};


export const breadcrumbsWithReplacementTitle = {
titleReplacement: 'override title',
items: [
{
caption: 'root',
url: '/some-url',
},
{
caption: 'active child',
},
],
};

export const resource = {
resourceUrl: 'some/url',
nameField: 'name',
Expand Down
Expand Up @@ -21,7 +21,9 @@ class BreadcrumbBar extends React.Component {

render() {
const {
data: { breadcrumbItems, isSwitchable, resource },
data: {
breadcrumbItems, isSwitchable, resource,
},
currentPage,
totalPages,
resourceSwitcherItems,
Expand All @@ -35,6 +37,7 @@ class BreadcrumbBar extends React.Component {
removeSearchQuery,
searchDebounceTimeout,
onSwitcherItemClick,
titleReplacement,
} = this.props;

const isTitle = breadcrumbItems.length === 1;
Expand All @@ -50,7 +53,12 @@ class BreadcrumbBar extends React.Component {

return (
<div className="breadcrumb-bar">
<Breadcrumb title items={breadcrumbItems} isTitle={isTitle}>
<Breadcrumb
title
items={breadcrumbItems}
isTitle={isTitle}
titleReplacement={titleReplacement}
>
{isSwitchable && (
<BreadcrumbSwitcher
open={isSwitcherOpen}
Expand Down Expand Up @@ -106,6 +114,7 @@ BreadcrumbBar.propTypes = {
loadSwitcherResourcesByResource: PropTypes.func,
onSearchChange: PropTypes.func,
onSwitcherItemClick: PropTypes.func,
titleReplacement: PropTypes.string,
};

BreadcrumbBar.defaultProps = {
Expand All @@ -126,6 +135,7 @@ BreadcrumbBar.defaultProps = {
onSearchChange: noop,
searchDebounceTimeout: 300,
onSwitcherItemClick: noop,
titleReplacement: null,
};

export default BreadcrumbBar;
Expand Up @@ -8,6 +8,7 @@ import {
BREADCRUMB_BAR_RESOURCES_SUCCESS,
BREADCRUMB_BAR_RESOURCES_FAILURE,
BREADCRUMB_BAR_CLEAR_SEARCH,
BREADCRUMB_BAR_UPDATE_TITLE,
} from './BreadcrumbBarConstants';

export const toggleSwitcher = () => ({
Expand All @@ -25,6 +26,12 @@ export const removeSearchQuery = resource => (dispatch) => {
loadSwitcherResourcesByResource(resource)(dispatch);
};

export const updateBreadcrumbTitle = title =>
({
type: BREADCRUMB_BAR_UPDATE_TITLE,
payload: title,
});

export const loadSwitcherResourcesByResource = (resource, { page = 1, searchQuery = '' } = {}) => (dispatch) => {
const { resourceUrl, nameField, switcherItemUrl } = resource;
const options = { page, searchQuery };
Expand Down
Expand Up @@ -4,4 +4,5 @@ export const BREADCRUMB_BAR_RESOURCES_REQUEST = 'BREADCRUMB_BAR_RESOURCES_REQUES
export const BREADCRUMB_BAR_RESOURCES_SUCCESS = 'BREADCRUMB_BAR_RESOURCES_SUCCESS';
export const BREADCRUMB_BAR_RESOURCES_FAILURE = 'BREADCRUMB_BAR_RESOURCES_FAILURE';
export const BREADCRUMB_BAR_CLEAR_SEARCH = 'BREADCRUMB_BAR_DELETE_SEARCH';
export const BREADCRUMB_BAR_UPDATE_TITLE = 'BREADCRUMB_BAR_UPDATE_TITLE';

Expand Up @@ -7,6 +7,7 @@ import {
BREADCRUMB_BAR_RESOURCES_SUCCESS,
BREADCRUMB_BAR_RESOURCES_FAILURE,
BREADCRUMB_BAR_CLEAR_SEARCH,
BREADCRUMB_BAR_UPDATE_TITLE,
} from './BreadcrumbBarConstants';

const initialState = Immutable({
Expand All @@ -18,6 +19,7 @@ const initialState = Immutable({
currentPage: null,
searchQuery: '',
pages: null,
titleReplacement: null,
});

export default (state = initialState, action) => {
Expand All @@ -27,6 +29,9 @@ export default (state = initialState, action) => {
case BREADCRUMB_BAR_CLEAR_SEARCH:
return state.set('searchQuery', '');

case BREADCRUMB_BAR_UPDATE_TITLE:
return state.set('titleReplacement', payload);

case BREADCRUMB_BAR_RESOURCES_REQUEST:
return state
.set('resourceSwitcherItems', [])
Expand Down
Expand Up @@ -22,6 +22,7 @@ exports[`BreadcrumbBar rendering renders breadcrumb-bar 1`] = `
]
}
title={true}
titleReplacement={null}
/>
<hr
className="breadcrumb-line"
Expand Down Expand Up @@ -51,6 +52,7 @@ exports[`BreadcrumbBar rendering renders switchable breadcrumb-bar 1`] = `
]
}
title={true}
titleReplacement={null}
>
<BreadcrumbSwitcher
currentPage={null}
Expand Down
Expand Up @@ -10,6 +10,7 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": null,
"searchQuery": "",
"titleReplacement": null,
}
`;

Expand All @@ -23,6 +24,7 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
}
`;

Expand All @@ -36,6 +38,7 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": "some/url",
"searchQuery": undefined,
"titleReplacement": null,
}
`;

Expand All @@ -49,6 +52,7 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": "some/url",
"searchQuery": "some search",
"titleReplacement": null,
}
`;

Expand Down Expand Up @@ -90,6 +94,7 @@ Object {
],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
}
`;

Expand All @@ -103,6 +108,7 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": null,
"searchQuery": "",
"titleReplacement": null,
}
`;

Expand All @@ -116,5 +122,6 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": null,
"searchQuery": "",
"titleReplacement": null,
}
`;
Expand Up @@ -11,6 +11,7 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": null,
"searchQuery": "",
"titleReplacement": null,
},
}
`;
Expand Down Expand Up @@ -72,6 +73,7 @@ Object {
],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
},
},
}
Expand Down Expand Up @@ -134,6 +136,7 @@ Object {
],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
},
},
}
Expand Down Expand Up @@ -196,6 +199,7 @@ Object {
],
"resourceUrl": "some/url",
"searchQuery": "text",
"titleReplacement": null,
},
},
}
Expand Down Expand Up @@ -258,6 +262,7 @@ Object {
],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
},
},
}
Expand Down Expand Up @@ -298,6 +303,7 @@ Object {
],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
},
},
}
Expand Down Expand Up @@ -329,6 +335,7 @@ Object {
"resourceSwitcherItems": Array [],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
},
},
}
Expand Down Expand Up @@ -391,6 +398,7 @@ Object {
],
"resourceUrl": "some/url",
"searchQuery": "",
"titleReplacement": null,
},
},
}
Expand Down

0 comments on commit bd57e02

Please sign in to comment.