Skip to content

Commit 880ea16

Browse files
committed
fix(jquery-form): avoid XSS
Applies the suggested fix that is sitting in an unmerged PR on the upstream repo: jquery-form/form#586
1 parent ee97e74 commit 880ea16

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

third-party/projects/jquery-form/jquery.form.js

+15-2
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,15 @@ $.fn.ajaxSubmit = function(options) {
190190
var oldSuccess = options.success || function(){};
191191
callbacks.push(function(data) {
192192
var fn = options.replaceTarget ? 'replaceWith' : 'html';
193+
194+
// Validate `data` through `HTML encoding` when passed
195+
// `data` is passed to `html()`, as suggested in
196+
// https://github.com/jquery-form/form/issues/464
197+
198+
data = options.replaceTarget
199+
? data
200+
: $.parseHTML($('<div>').text(data).html());
201+
193202
$(options.target)[fn](data).each(oldSuccess, arguments);
194203
});
195204
}
@@ -801,8 +810,12 @@ $.fn.ajaxSubmit = function(options) {
801810
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
802811
};
803812
var parseJSON = $.parseJSON || function(s) {
804-
/*jslint evil:true */
805-
return window['eval']('(' + s + ')');
813+
// Throw an error instead of making a new function using
814+
// unsanitized inputs to avoid XSS attacks.
815+
816+
window.console.error('jquery.parseJSON is undefined');
817+
818+
return null;
806819
};
807820

808821
var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4

0 commit comments

Comments
 (0)