Skip to content

Commit

Permalink
Add another security fix
Browse files Browse the repository at this point in the history
  • Loading branch information
tmcconechy committed Jun 4, 2019
1 parent fba5379 commit 9b57aaa
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 1 deletion.
67 changes: 67 additions & 0 deletions app/views/components/modal/test-xss.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<div class="row">
<div class="twelve columns">

<button class="btn-secondary" type="button" id="add-context">Show Modal</button><br/><br/>

<!-- Modal Example -->
<div id="modal-add-context" class="hidden">
<div class="field">
<label for="subject">Problem</label>
<input type="text" id="subject" name="subject" />
</div>

<div class="field">
<label for="location" class="label">Location</label>
<select id="location" name="location" class="dropdown">
<option value="N">North</option>
<option value="S">South</option>
<option value="E">East</option>
<option value="W">West</option>
</select>
</div>

<div class="field">
<label for="notes-max">Notes (maxlength)</label>
<textarea id="notes-max" class="textarea" maxlength="90" name="notes-max">Line One</textarea>
</div>
</div>

</div>
</div>

<script>
var modals = {
'add-context': {
'title': '<' + 'script' + '>window.alert()<' + '/script>',
'id': 'my-id',
'content': $('#modal-add-context')
}
},

setModal = function (opt) {
opt = $.extend({
buttons: [{
text: 'Cancel',
// id: 'modal-button-1',
click: function(e, modal) {
modal.close();
}
}, {
text: 'Save',
// id: 'modal-button-2',
click: function(e, modal) {
modal.close();
},
validate: false,
isDefault: true
}]
}, opt);

$('body').modal(opt);
};

$('#add-context').on('click', function () {
setModal(modals[this.id]);
});

</script>
3 changes: 2 additions & 1 deletion src/components/modal/modal.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import * as debug from '../../utils/debug';
import { warnAboutDeprecation } from '../../utils/deprecated';
import { utils } from '../../utils/utils';
import { xssUtils } from '../../utils/xss';
import { Locale } from '../../../src/components/locale/locale';

// jQuery components
Expand Down Expand Up @@ -176,7 +177,7 @@ Modal.prototype = {

this.element = $(`${'<div class="modal">' +
'<div class="modal-content" style="max-width: '}${this.settings.maxWidth ? this.settings.maxWidth : ''}px${'">' +
'<div class="modal-header"><h1 class="modal-title">'}${this.settings.title}</h1></div>` +
'<div class="modal-header"><h1 class="modal-title">'}${xssUtils.stripTags(this.settings.title, '<div><span><a><small><img><svg><i><b><use><br><strong><em>')}</h1></div>` +
'<div class="modal-body-wrapper">' +
'<div class="modal-body"></div>' +
'</div>' +
Expand Down

0 comments on commit 9b57aaa

Please sign in to comment.