Skip to content

Commit f292277

Browse files
authored
Merge pull request #398 from liferay/wincent/jquery-form-xss
fix(jquery-form): avoid XSS
2 parents c941de6 + a4dd6b1 commit f292277

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

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

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,9 @@
1010
*/
1111
/*global ActiveXObject */
1212

13-
// AMD support
1413
(function (factory) {
1514
"use strict";
16-
if (typeof define === 'function' && define.amd) {
17-
// using AMD; register as anon module
18-
define(['jquery'], factory);
19-
} else {
20-
// no AMD; invoke directly
21-
factory( (typeof(jQuery) != 'undefined') ? jQuery : window.Zepto );
22-
}
15+
factory(window.$ || window.Zepto);
2316
}
2417

2518
(function($) {
@@ -190,6 +183,15 @@ $.fn.ajaxSubmit = function(options) {
190183
var oldSuccess = options.success || function(){};
191184
callbacks.push(function(data) {
192185
var fn = options.replaceTarget ? 'replaceWith' : 'html';
186+
187+
// Validate `data` through `HTML encoding` when passed
188+
// `data` is passed to `html()`, as suggested in
189+
// https://github.com/jquery-form/form/issues/464
190+
191+
data = options.replaceTarget
192+
? data
193+
: $.parseHTML($('<div>').text(data).html());
194+
193195
$(options.target)[fn](data).each(oldSuccess, arguments);
194196
});
195197
}
@@ -801,8 +803,12 @@ $.fn.ajaxSubmit = function(options) {
801803
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
802804
};
803805
var parseJSON = $.parseJSON || function(s) {
804-
/*jslint evil:true */
805-
return window['eval']('(' + s + ')');
806+
// Throw an error instead of making a new function using
807+
// unsanitized inputs to avoid XSS attacks.
808+
809+
window.console.error('jquery.parseJSON is undefined');
810+
811+
return null;
806812
};
807813

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

0 commit comments

Comments
 (0)