Skip to content

Commit

Permalink
secure embedded JS
Browse files Browse the repository at this point in the history
  • Loading branch information
ornicar committed May 12, 2016
1 parent cc412e6 commit bcfc2b4
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/templating/AssetHelper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,9 @@ trait AssetHelper { self: I18nHelper =>
s"""<script src="${static.fold(staticUrl(path), path)}?v=$assetVersion"></script>"""
}

def embedJs(js: String): Html = Html(s"""<script>/* <![CDATA[ */ $js /* ]]> */</script>""")
def embedJs(js: String): Html = Html {
val escaped = js.replace("</script", "<|script")
s"""<script>$escaped</script>"""
}
def embedJs(js: Html): Html = embedJs(js.body)
}

0 comments on commit bcfc2b4

Please sign in to comment.