mirror of
https://gerrit.wikimedia.org/r/mediawiki/extensions/Popups
synced 2024-11-23 15:16:50 +00:00
Run mw.html.escape on page extract and title
Add tests for XSS attack
Bug: T69180
Change-Id: I0c423b1046257a0ddacec1315bafcbf1f94b9958
(cherry picked from commit a98b009b49
)
This commit is contained in:
parent
e86b00ac61
commit
9ae6a61eef
|
@ -147,6 +147,8 @@
|
|||
* @return {String}
|
||||
*/
|
||||
article.getProcessedHtml = function ( extract, title ) {
|
||||
extract = mw.html.escape( extract );
|
||||
title = mw.html.escape( title );
|
||||
title = title.replace( /([.?*+^$[\]\\(){}|-])/g, '\\$1' ); // Escape RegExp elements
|
||||
var regExp = new RegExp( '(^|\\s)(' + title + ')(\\s|$)', 'ig' );
|
||||
// Make title bold in the extract text
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
QUnit.module( 'ext.popups' );
|
||||
QUnit.test( 'render.article.getProcessedHtml', function ( assert ) {
|
||||
QUnit.expect( 6 );
|
||||
QUnit.expect( 7 );
|
||||
|
||||
function test ( extract, title, expected ) {
|
||||
assert.equal(
|
||||
|
@ -41,6 +41,11 @@
|
|||
'<b>Brackets</b> ) are funny ( when not used properly'
|
||||
);
|
||||
|
||||
test(
|
||||
'Epic XSS <script>alert("XSS")</script> is epic', 'Epic XSS',
|
||||
'<b>Epic XSS</b> <script>alert</script> is epic'
|
||||
);
|
||||
|
||||
} );
|
||||
|
||||
} ) ( jQuery, mediaWiki );
|
||||
|
|
Loading…
Reference in a new issue