In a Shiny app, how do I implement a frame-breaking script to prevent clickjacking in legacy browsers (e.g., IE6 or IE8)?
----------- Quote from Reference below this line ----------
Best-for-now Legacy Browser Frame Breaking Script
One way to defend against clickjacking is to include a "frame-breaker" script in each page that should not be framed. The following methodology will prevent a webpage from being framed even in legacy browsers, that do not support the X-Frame-Options-Header.
In the document HEAD element, add the following:
First apply an ID to the style element itself:
<style id="antiClickjack">body{display:none !important;}</style>
And then delete that style by its ID immediately after in the script:
<script type="text/javascript">
if (self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
}
</script>
This way, everything can be in the document HEAD and you only need one method/taglib in your API.
----------------------------------------------------------------------------
I tried the following in my ui.R, but it didn't work:
tags$style(id = "antiClickjack", HTML("body{display:none !important;}"))
fn <- "loupe.js"
fnpath <- list.files(pattern = fn, full.names = TRUE, recursive = TRUE)
includeScript(fnpath, type = "text/javascript")
Where loupe.js is as suggested in the article:
if (self === top) {
var antiClickjack = document.getElementById("antiClickjack");
antiClickjack.parentNode.removeChild(antiClickjack);
} else {
top.location = self.location;
}
Don't really understand all of the code, so any help would be welcome.