Skip to content

Commit

Permalink
[SECURITY CVE-2015-1866] Escape Ember.Select option label contents.
Browse files Browse the repository at this point in the history
(cherry picked from commit 29703251a3d36ff972753985aa23f4e6bf2cf24e)
(cherry picked from commit 3368489)
  • Loading branch information
rwjblue committed Apr 14, 2015
1 parent 41542c6 commit 5a4667b
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 15 deletions.
1 change: 1 addition & 0 deletions packages/ember-htmlbars/lib/templates/select-option.hbs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{{~view.label~}}

This comment has been minimized.

Copy link
@mmun

mmun Apr 14, 2015

Member

~ so fancy ~

16 changes: 1 addition & 15 deletions packages/ember-views/lib/views/select.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,26 +21,12 @@ import { computed } from "ember-metal/computed";
import { A as emberA } from "ember-runtime/system/native_array";
import { observer } from "ember-metal/mixin";
import { defineProperty } from "ember-metal/properties";
import run from "ember-metal/run_loop";

import htmlbarsTemplate from "ember-htmlbars/templates/select";
import selectOptionDefaultTemplate from "ember-htmlbars/templates/select-option";

var defaultTemplate = htmlbarsTemplate;

var selectOptionDefaultTemplate = {
isHTMLBars: true,
revision: 'Ember@VERSION_STRING_PLACEHOLDER',
render(context, env, contextualElement) {
var lazyValue = context.getStream('view.label');

lazyValue.subscribe(context._wrapAsScheduled(function() {
run.scheduleOnce('render', context, 'rerender');
}));

return lazyValue.value();
}
};

var SelectOption = View.extend({
instrumentDisplay: 'Ember.SelectOption',

Expand Down
39 changes: 39 additions & 0 deletions packages/ember-views/tests/views/select_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import run from "ember-metal/run_loop";
import jQuery from "ember-views/system/jquery";
import { map } from "ember-metal/enumerable_utils";
import EventDispatcher from "ember-views/system/event_dispatcher";
import SafeString from 'htmlbars-util/safe-string';

var trim = jQuery.trim;

Expand Down Expand Up @@ -133,6 +134,44 @@ QUnit.test("can specify the property path for an option's label and value", func
deepEqual(map(select.$('option').toArray(), function(el) { return jQuery(el).attr('value'); }), ["1", "2"], "Options should have values");
});

QUnit.test("XSS: does not escape label value when it is a SafeString", function() {
select.set('content', Ember.A([
{ id: 1, firstName: new SafeString('<p>Yehuda</p>') },
{ id: 2, firstName: new SafeString('<p>Tom</p>') }
]));

select.set('optionLabelPath', 'content.firstName');
select.set('optionValuePath', 'content.id');

append();

equal(select.$('option').length, 2, "Should have two options");
equal(select.$('option[value=1] b').length, 1, "Should have child elements");

// IE 8 adds whitespace
equal(trim(select.$().text()), "YehudaTom", "Options should have content");
deepEqual(map(select.$('option').toArray(), function(el) { return jQuery(el).attr('value'); }), ["1", "2"], "Options should have values");
});

QUnit.test("XSS: escapes label value content", function() {
select.set('content', Ember.A([
{ id: 1, firstName: '<p>Yehuda</p>' },
{ id: 2, firstName: '<p>Tom</p>' }
]));

select.set('optionLabelPath', 'content.firstName');
select.set('optionValuePath', 'content.id');

append();

equal(select.$('option').length, 2, "Should have two options");
equal(select.$('option[value=1] b').length, 0, "Should have no child elements");

// IE 8 adds whitespace
equal(trim(select.$().text()), "<p>Yehuda</p><p>Tom</p>", "Options should have content");
deepEqual(map(select.$('option').toArray(), function(el) { return jQuery(el).attr('value'); }), ["1", "2"], "Options should have values");
});

QUnit.test("can retrieve the current selected option when multiple=false", function() {
var yehuda = { id: 1, firstName: 'Yehuda' };
var tom = { id: 2, firstName: 'Tom' };
Expand Down

0 comments on commit 5a4667b

Please sign in to comment.