Skip to content
This repository has been archived by the owner on Jul 28, 2018. It is now read-only.

Commit

Permalink
Merge pull request #196 from reed/xss-defense
Browse files Browse the repository at this point in the history
Defend against same origin XSS
  • Loading branch information
reed committed Mar 16, 2013
2 parents f7295ca + a21165e commit 61e92f5
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions lib/assets/javascripts/turbolinks.js.coffee
Expand Up @@ -29,9 +29,7 @@ fetchReplacement = (url) ->
xhr.setRequestHeader 'X-XHR-Referer', referer

xhr.onload = =>
doc = createDocument xhr.responseText

if assetsChanged doc
if invalidContent(xhr) or assetsChanged (doc = createDocument xhr.responseText)
document.location.reload()
else
changePage extractTitleAndBody(doc)...
Expand Down Expand Up @@ -140,6 +138,9 @@ triggerEvent = (name) ->
document.dispatchEvent event


invalidContent = (xhr) ->
!xhr.getResponseHeader('Content-Type').match /^(?:text\/html|application\/xhtml\+xml|application\/xml)(?:;|$)/

extractTrackAssets = (doc) ->
(node.src || node.href) for node in doc.head.childNodes when node.getAttribute?('data-turbolinks-track')?

Expand Down Expand Up @@ -220,7 +221,8 @@ anchoredLink = (link) ->
(link.href is location.href + '#')

nonHtmlLink = (link) ->
link.href.match(/\.[a-z]+(\?.*)?$/g) and not link.href.match(/\.html?(\?.*)?$/g)
url = removeHash link
url.match(/\.[a-z]+(\?.*)?$/g) and not url.match(/\.html?(\?.*)?$/g)

noTurbolink = (link) ->
until ignore or link is document
Expand Down

0 comments on commit 61e92f5

Please sign in to comment.