Skip to content

Commit c587c57

Browse files
committed
fix: DOM text reinterpreted as HTML High
1 parent 3e6af23 commit c587c57

2 files changed

Lines changed: 12 additions & 5 deletions

File tree

‎jQuery.leanModal2.js‎

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,10 @@
8686
// FUNCTION: Fade out the overlay and a passed identifier.
8787
function leanModal_Close(modal_id) {
8888
$('#js-leanmodal-overlay').removeClass('js-leanmodal-active').addClass('js-leanmodal-inactive')
89-
$(modal_id).removeClass('js-leanmodal-active').addClass('js-leanmodal-inactive')
89+
$(document.querySelector(modal_id)).removeClass('js-leanmodal-active').addClass('js-leanmodal-inactive')
9090
$('#js-leanmodal-overlay').unbind('click')
9191
$(document).off('keyup')
92-
$(modal_id).appendTo('body')
92+
$(document.querySelector(modal_id)).appendTo('body')
9393
}
9494

9595
//// Everything is Linked
@@ -117,6 +117,13 @@
117117
return false
118118
} // IFHREF
119119

120+
//// Validate the Modal Identifier
121+
// Ensure modal_id is a CSS selector (starts with # or .)
122+
// to prevent DOM-based XSS via jQuery HTML interpretation.
123+
if ( !/^[#.][^\s]/.test(modal_id) ) {
124+
return false
125+
}
126+
120127
//// Close with closeButton
121128
// If `closeButton` is set,
122129
// use it to call the close command.
@@ -158,13 +165,13 @@
158165
//// Modal Positioning
159166
// Position the modal centrally inside the overlay using flexbox.
160167
if ( options.modalCenter ) {
161-
$(modal_id).appendTo('#js-leanmodal-overlay')
168+
$(document.querySelector(modal_id)).appendTo('#js-leanmodal-overlay')
162169
}
163170

164171
//// Curtain Up
165172
// Fade in the modal and overlay.
166173
$('#js-leanmodal-overlay').removeClass('js-leanmodal-inactive').addClass('js-leanmodal-active')
167-
$(modal_id).removeClass('js-leanmodal-inactive').addClass('js-leanmodal-active')
174+
$(document.querySelector(modal_id)).removeClass('js-leanmodal-inactive').addClass('js-leanmodal-active')
168175
//// Default Prevention
169176
// Prevent whatever the default was (probably scrolling).
170177
e.preventDefault()

‎jQuery.leanModal2.min.js‎

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)