New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix some XSS in v3 #23687

Merged
merged 1 commit into from Sep 14, 2017
File filter...
Filter file types
Jump to file or symbol
Failed to load files and symbols.
+23 −7
Diff settings

Always

Just for now

Fix XSS in Alert, Carousel, Collapse, Dropdown and Modal

  • Loading branch information...
Johann-S committed Aug 26, 2017
commit d9be1da55bf0f94a81e8a2c9acf5574fb801306e
Copy path View file
@@ -31,7 +31,8 @@
selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
}

var $parent = $(selector === '#' ? [] : selector)
selector = selector === '#' ? [] : selector
var $parent = $(document).find(selector)

if (e) e.preventDefault()

Copy path View file
@@ -206,10 +206,17 @@
// =================

var clickHandler = function (e) {
var href
var $this = $(this)
var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) // strip for ie7
var href = $this.attr('href')
if (href) {
href = href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7
}

var target = $this.attr('data-target') || href
var $target = $(document).find(target)

if (!$target.hasClass('carousel')) return

var options = $.extend({}, $target.data(), $this.data())
var slideIndex = $this.attr('data-slide-to')
if (slideIndex) options.interval = false
Copy path View file
@@ -160,7 +160,7 @@
var target = $trigger.attr('data-target')
|| (href = $trigger.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') // strip for ie7

return $(target)
return $(document).find(target)
}


Copy path View file
@@ -29,7 +29,7 @@
selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
}

var $parent = selector && $(selector)
var $parent = selector && $(document).find(selector)

return $parent && $parent.length ? $parent : $this.parent()
}
Copy path View file
@@ -322,7 +322,10 @@
$(document).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()
Copy path View file
@@ -66,7 +66,9 @@ <h4 class="panel-title">
</div>
</div>
</div>

<button class="btn" data-toggle="collapse" data-target="<img src=x onerror=alert(0)>">
Collapse with an XSS
</button>
</div>

<!-- JavaScript Includes -->
Copy path View file
@@ -162,6 +162,9 @@ <h4 class="modal-title" id="myModalLabel2">Modal Heading</h4>
Tall body content to force the page to have a scrollbar.
</div>

<button class="btn btn-primary btn-lg" data-toggle="modal" data-target="&#x3C;div class=&#x22;modal fade the-bad&#x22; tabindex=&#x22;-1&#x22; role=&#x22;dialog&#x22;&#x3E;&#x3C;div class=&#x22;modal-dialog&#x22; role=&#x22;document&#x22;&#x3E;&#x3C;div class=&#x22;modal-content&#x22;&#x3E;&#x3C;div class=&#x22;modal-header&#x22;&#x3E;&#x3C;button type=&#x22;button&#x22; class=&#x22;close&#x22; data-dismiss=&#x22;modal&#x22; aria-label=&#x22;Close&#x22;&#x3E;&#x3C;span aria-hidden=&#x22;true&#x22;&#x3E;&#x26;times;&#x3C;/span&#x3E;&#x3C;/button&#x3E;&#x3C;h4 class=&#x22;modal-title&#x22;&#x3E;The Bad Modal&#x3C;/h4&#x3E;&#x3C;/div&#x3E;&#x3C;div class=&#x22;modal-body&#x22;&#x3E;This modal&#x27;s HTTML source code is declared inline, inside the data-target attribute of it&#x27;s show-button&#x3C;/div&#x3E;&#x3C;/div&#x3E;&#x3C;/div&#x3E;&#x3C;/div&#x3E;">
Launch XSS modal
</button>
</div>

<!-- JavaScript Includes -->
ProTip! Use n and p to navigate between commits in a pull request.