|
86 | 86 | // FUNCTION: Fade out the overlay and a passed identifier. |
87 | 87 | function leanModal_Close(modal_id) { |
88 | 88 | $('#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') |
90 | 90 | $('#js-leanmodal-overlay').unbind('click') |
91 | 91 | $(document).off('keyup') |
92 | | - $(modal_id).appendTo('body') |
| 92 | + $(document.querySelector(modal_id)).appendTo('body') |
93 | 93 | } |
94 | 94 |
|
95 | 95 | //// Everything is Linked |
|
117 | 117 | return false |
118 | 118 | } // IFHREF |
119 | 119 |
|
| 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 | + |
120 | 127 | //// Close with closeButton |
121 | 128 | // If `closeButton` is set, |
122 | 129 | // use it to call the close command. |
|
158 | 165 | //// Modal Positioning |
159 | 166 | // Position the modal centrally inside the overlay using flexbox. |
160 | 167 | if ( options.modalCenter ) { |
161 | | - $(modal_id).appendTo('#js-leanmodal-overlay') |
| 168 | + $(document.querySelector(modal_id)).appendTo('#js-leanmodal-overlay') |
162 | 169 | } |
163 | 170 |
|
164 | 171 | //// Curtain Up |
165 | 172 | // Fade in the modal and overlay. |
166 | 173 | $('#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') |
168 | 175 | //// Default Prevention |
169 | 176 | // Prevent whatever the default was (probably scrolling). |
170 | 177 | e.preventDefault() |
|
0 commit comments