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

Fixes #25169 - fix xss on pages with breadcrumbs #6132

Merged
merged 1 commit into from
Nov 5, 2018

Conversation

amirfefer
Copy link
Member

@amirfefer amirfefer commented Oct 10, 2018

breadcrumbs replaced the title on pages by using @page_header variable.
in two places, @page_header contains html such as image for the operating system in details host page, and span with id (#hostFQDN) in order to manipulate the title with jquery.

In this PR, I removed dangerouslySetInnerHTML from the breadcrumb component, which caused this issue, while keeping the same behavior that I mentioned above.
I haven't found any other extracted html in @page_header except these two in foreman core and plugins.

@theforeman-bot
Copy link
Member

Issues: #25169

@ares
Copy link
Member

ares commented Oct 11, 2018

one integration test seemed to fail on all rubies, rerunning tests to be sure, but is probably related
[test foreman]


Capybara::ElementNotFound: Unable to find css "#hostFQDN"
    test/integration/host_js_test.rb:602:in `block (3 levels) in <class:HostJSTest>' (Capybara::ElementNotFound)
/usr/local/rvm/gems/ruby-2.4.3@test_develop_pr_core-0/gems/capybara-3.9.0/lib/capybara/node/finders.rb:297    

Copy link
Contributor

@sharvit sharvit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amirfefer, left some comments about the React/Redux part

@@ -0,0 +1,6 @@
import store from './react_app/redux';

import * as BreadcrumbsAction from './react_app/components/BreadcrumbBar/BreadcrumbBarActions';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick, import { updateBreadcrumbTitle } from '...';

title
items={breadcrumbItems}
isTitle={isTitle}
titleAddition={this.props.titleAddition}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  1. Can you put it with all the other props in the const { ... } = this.props?

  2. Can you add propType and defaultProp?

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

export const updateBreadcrumbTitle = title => (dispatch) => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the dispatch in this case, this should be enough:

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

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

case BREADCRUMB_BAR_UPDATE_TITLE:
return state.set('titleAddition', payload);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't we want some titleAddition value to be in the initialState?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't it enough have a default value defined in the Proptype?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case it will achieve the same results, but I wouldn't say it is enough, they are playing different roles.

Different defaultProps when not passing a value vs the actual initial state of the application.

/>
title="root"
>
root false
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The false is here accidentally?

@amirfefer
Copy link
Member Author

amirfefer commented Oct 11, 2018

@sharvit thanks for the review !
could you have another look ?

@ares - the integration test failure occurs due to the the legacy manipulation on the title, so i'm rewrite it.

@coveralls
Copy link

Coverage Status

Coverage decreased (-0.1%) to 75.396% when pulling 04be4a3 on amirfefer:25169 into 7011d23 on theforeman:develop.

@coveralls
Copy link

coveralls commented Oct 11, 2018

Coverage Status

Coverage decreased (-0.1%) to 75.557% when pulling f51a47c on amirfefer:25169 into 882d451 on theforeman:develop.

@@ -0,0 +1,3 @@
#hostFQDN {
vertical-align: 0px

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unexpected unit length-zero-no-unit
Expected a trailing semicolon declaration-block-trailing-semicolon

@amirfefer
Copy link
Member Author

@ares integration test has been fixed :)

@ares
Copy link
Member

ares commented Oct 11, 2018

Ok, I can confirm test failure is now unrelated. Normally we try to keep security fixes minimal, because of backporting. But if there's no better way of handling the title in interfaces form, I guess that's fine. I'll be testing this shortly and waiting for @sharvit for code ack.

sharvit
sharvit previously approved these changes Oct 14, 2018
Copy link
Contributor

@sharvit sharvit left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks @amirfefer 👍

{' '}
{text || caption}
{' '}
{ active && <span id='hostFQDN' > {titleAddition} </span>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

'hostFQDN' id seems too resource specific for this generic component.

I didn't do any testing, but besides that the design looks fine to me.

Copy link
Member Author

@amirfefer amirfefer Oct 23, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you're right, I chose it because the integration test catches this id. I'll change the id to something more generic here and in the test.

@tbrisker
Copy link
Member

ping @amirfefer @tstrachota @sharvit - what is the status here?

Copy link
Member

@tstrachota tstrachota left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I did some testing and found one regression on the host edit page. I'm sorry for that @amirfefer

{' '}
{text || caption}
{' '}
{ active && <span id='title-addition' > {titleAddition} </span>}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I found out this is causing issues when I change fqdn of a primary interface on an existing host:
screenshot from 2018-10-24 15-18-24

How about removing the addition and replacing the whole caption on BREADCRUMB_BAR_UPDATE_TITLE ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we have two options I can think of:

  1. replace the entire title when fqdn is changed
  2. add this title's addition only on new host page (keeping today's behavior )

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer 1. It means copying some strings into js code but in general I find it more re-usable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to do two things - 1. change the entire title instead of adding to it (so if needed we can do that elsewhere easily, where it might not make sense to only add text) 2. only do this on new hosts since it's confusing if you are editing an existing one - you expect the old name to be there rather than the new

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tbrisker I agree. Changing it on the edit page would be confusing.

@amirfefer
Copy link
Member Author

thanks @tbrisker ! I've removed the readOnly prop, and changed the legacy js function.

@@ -62,7 +62,7 @@ def layout_data

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
Copy link
Member Author

@amirfefer amirfefer Nov 1, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@content_for_title doesn't exist

@@ -599,7 +599,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)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moved to jest

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just a tiny comment inline

@@ -44,7 +44,9 @@ def icon(record, opts = {})
return "" if record.family.blank?
record.family
end

if opts[:path]
return image_path(family + ".png")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nitpick:

return image_path(family + ".png") if opts[:path]

is a more common idiom in ruby

@amirfefer
Copy link
Member Author

thanks @tbrisker :)

@mmoll
Copy link
Contributor

mmoll commented Nov 2, 2018

test failure unrelated 💚

@mmoll mmoll added this to the 1.18.3 milestone Nov 2, 2018
@amirfefer
Copy link
Member Author

@tbrisker could you have another look please?

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missed one change from earlier version

<% new_host_title %>

<% title _("Create Host") %>
<%= breadcrumbs(read_only_title: false) %>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

leftover read_only_title

@amirfefer
Copy link
Member Author

thanks for noticing :)

Copy link
Member

@tbrisker tbrisker left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @amirfefer !

@tbrisker tbrisker merged commit 3a0c10c into theforeman:develop Nov 5, 2018
@tbrisker
Copy link
Member

tbrisker commented Nov 5, 2018

🍒 :
1.20 - a768857
1.19 - bd57e02
1.18 - 8a2077e

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants