From a68edd11861555119cf97a412405dffe8526437d Mon Sep 17 00:00:00 2001
From: Mark Carver <mark.carver@me.com>
Date: Wed, 12 Sep 2018 15:56:14 -0500
Subject: [PATCH] Issue #2999163 by markcarver, Gomez_in_the_South: XSS
 vulnerability in modal.js

Signed-off-by: Mark Carver <mark.carver@me.com>
---
 js/modal.js | 12 ++++++++++--
 1 file changed, 10 insertions(+), 2 deletions(-)

diff --git a/js/modal.js b/js/modal.js
index 5bcce17..d7dabcf 100644
--- a/js/modal.js
+++ b/js/modal.js
@@ -5,6 +5,13 @@
 (function ($, Drupal, Bootstrap, Attributes) {
   'use strict';
 
+  /**
+   * Document jQuery object.
+   *
+   * @type {jQuery}
+   */
+  var $document = $(document);
+
   /**
    * Only process this once.
    */
@@ -131,12 +138,13 @@
       // Replace the data API so that it calls $.fn.modal rather than Plugin.
       // This allows sub-themes to replace the jQuery Plugin if they like with
       // out having to redo all this boilerplate.
-      $(document)
+      $document
         .off('click.bs.modal.data-api')
         .on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
           var $this   = $(this);
           var href    = $this.attr('href');
-          var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))); // strip for ie7
+          var target  = $this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, '')); // strip for ie7
+          var $target = $document.find(target);
           var option  = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data());
 
           if ($this.is('a')) e.preventDefault();
-- 
2.15.1

