Skip to content

Commit

Permalink
1.5 : Added parent domain whitelist
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomazPom committed Jul 28, 2019
1 parent bb2d66e commit d0b5c34
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 162 deletions.
88 changes: 44 additions & 44 deletions background.js
Original file line number Diff line number Diff line change
@@ -1,56 +1,56 @@
var defaultRgx = ["http://*/*", "https://*/*"].join('\n')
var regexpesarray = [];
function updateRegexpes(save)
{
browser.storage.local.get("regstr", function(res) {
var regstr = (res.regstr || defaultRgx);

regexpesarray = [];
var regexpesarray = regstr.split("\n")
console.log(regexpesarray)
var defaultRgx_fancestor = ["http://*", "https://*"].join('\n')

browser.webRequest.onHeadersReceived.removeListener(setHeader)
browser.webRequest.onHeadersReceived.addListener(setHeader,
{urls : regexpesarray},
["blocking", "responseHeaders"]
);
});
function updateRegexpes()
{
browser.storage.local.get("regstr_fancestor", function(res) {
regstr_fancestor = (res.regstr_fancestor || defaultRgx_fancestor).split("\n").join(" ");
});
browser.storage.local.get("regstr", function(res) {
var regstr = (res.regstr || defaultRgx);
var regexpesarray = regstr.split("\n");
browser.webRequest.onHeadersReceived.removeListener(setHeader)
browser.webRequest.onHeadersReceived.addListener(
setHeader,
{urls : regexpesarray},
["blocking", "responseHeaders"]
);
});
}
function setHeader(e) {
for (var header of e.responseHeaders) {
if (header.name.toLowerCase() === "x-frame-options") {
header.value = "ALLOW";
}
else if(header.name.toLowerCase() === "content-security-policy")
{
header.value = header.value.replace(/frame-ancestors[^;]*;?/, "frame-ancestors http://* https://*;")
}
}
var myHeader = {
name: "x-frame-options",
value: "ALLOW"
};
e.responseHeaders.push(myHeader);
return {responseHeaders: e.responseHeaders};
var headersdelete = ["x-frame-options","content-security-policy"]
e.responseHeaders= e.responseHeaders.filter(x=>!headersdelete.includes(x.name.toLowerCase()))
e.responseHeaders.push({
name: "x-frame-options",
value: "ALLOW"
});
e.responseHeaders.push({
name: "content-security-policy",
value: "frame-ancestors "+regstr_fancestor+";"
});
return {responseHeaders: e.responseHeaders};
}
// Listen for onHeaderReceived for the target page.
// Set "blocking" and "responseHeaders".
updateRegexpes();
console.log("Loaded")
var portFromCS;
function connected(p) {
portFromCS = p;
//portFromCS.postMessage({greeting: "hi there content script!"});
portFromCS.onMessage.addListener(function(m) {
if(m.updateRegexpes)
{

browser.storage.local.set({"regstr":m.updateRegexpes}, function(res) {
updateRegexpes();
});


}
});
portFromCS = p;
portFromCS.onMessage.addListener(function(m) {
if(m.updateRegexpes)
{
browser.storage.local.set(
{
"regstr":m.updateRegexpes,
},
()=>{
browser.storage.local.set(
{
"regstr_fancestor":m.updateRegexpes_fancestor
},updateRegexpes);
}
);
}
});
}
browser.runtime.onConnect.addListener(connected);
2 changes: 1 addition & 1 deletion manifest.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"manifest_version": 2,
"name": "Ignore X-Frame-Options",
"version": "1.4.1",
"version": "1.5",
"description": "Allows all sites to be loaded in iframes, despite X-Frame-Options header settings.",
"homepage_url": "https://github.com/ThomazPom/Moz-Ext-Ignore-X-Frame-Options",
"icons": {
Expand Down
126 changes: 15 additions & 111 deletions popup.html
Original file line number Diff line number Diff line change
Expand Up @@ -15,87 +15,7 @@
}


html,
body,
div,
span,
applet,
object,
iframe,
h1,
h2,
h3,
h4,
h5,
h6,
p,
blockquote,
pre,
a,
abbr,
acronym,
address,
big,
cite,
code,
del,
dfn,
em,
img,
ins,
kbd,
q,
s,
samp,
small,
strike,
strong,
sub,
sup,
tt,
var,
b,
u,
i,
center,
dl,
dt,
dd,
ol,
ul,
li,
fieldset,
form,
label,
legend,
table,
caption,
tbody,
tfoot,
thead,
tr,
th,
td,
article,
aside,
canvas,
details,
embed,
figure,
figcaption,
footer,
header,
hgroup,
menu,
nav,
output,
ruby,
section,
summary,
time,
mark,
audio,
video {
html, body, div, span, applet, object, iframe, h1, h2, h3, h4, h5, h6, p, blockquote, pre, a, abbr, acronym, address, big, cite, code, del, dfn, em, img, ins, kbd, q, s, samp, small, strike, strong, sub, sup, tt, var, b, u, i, center, dl, dt, dd, ol, ul, li, fieldset, form, label, legend, table, caption, tbody, tfoot, thead, tr, th, td, article, aside, canvas, details, embed, figure, figcaption, footer, header, hgroup, menu, nav, output, ruby, section, summary, time, mark, audio, video {
margin: 0;
padding: 0;
border: 0;
Expand All @@ -104,38 +24,23 @@
vertical-align: baseline;
}

article,
aside,
details,
figcaption,
figure,
footer,
header,
hgroup,
menu,
nav,
section {
article, aside, details, figcaption, figure, footer, header, hgroup, menu, nav, section {
display: block;
}

body {
line-height: 1;
}

ol,
ul {
ol, ul {
list-style: none;
}

blockquote,
q {
blockquote, q {
quotes: none;
}

blockquote:before,
blockquote:after,
q:before,
q:after {
blockquote:before, blockquote:after, q:before, q:after {
content: '';
content: none;
}
Expand All @@ -145,8 +50,7 @@
border-spacing: 0;
}

body,
html {
body, html {
height: 100%;
}

Expand Down Expand Up @@ -200,8 +104,7 @@
text-shadow: 0px 1px 1px #888;
}

.btn span.icon,
.btn span.title {
.btn span.icon, .btn span.title {
display: block;
position: relative;
line-height: 50px;
Expand Down Expand Up @@ -240,8 +143,7 @@
background-color: #00cdae;
}

.btn span.arrow-left,
.btn span.arrow-right {
.btn span.arrow-left, .btn span.arrow-right {
position: absolute;
width: 0;
height: 0;
Expand Down Expand Up @@ -281,8 +183,7 @@
border-left: 10px solid #00cdae;
}

.btn span.slant-left,
.btn span.slant-right {
.btn span.slant-left, .btn span.slant-right {
position: absolute;
width: 0;
height: 0;
Expand Down Expand Up @@ -322,8 +223,7 @@
border-right: 10px solid #00967f;
}

.btn:active,
.btn.active {
.btn:active, .btn.active {
height: 51px;
}

Expand Down Expand Up @@ -359,7 +259,7 @@
text-align: center;
display: block;
}
.listextarea
.listextarea, .listextarea_fancestor
{
width: 85%;
margin-left: 5%;
Expand Down Expand Up @@ -396,6 +296,10 @@
<p class="label" id="warning" style="background-color: red"></p>
<textarea class="listextarea"></textarea>
</div>
<div class="content">
<span class="label">Websites allowed to frame them</span>
<textarea class="listextarea_fancestor"></textarea>
</div>

<script type="text/javascript" src="popup.js"></script>
</script>
Expand Down
22 changes: 16 additions & 6 deletions popup.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,28 @@
// content-script.js
var defaultRgx = ["http://*/*", "https://*/*"].join('\n')
var defaultRgx_fancestor = ["http://*", "https://*"].join('\n')

var myPort = browser.runtime.connect({name:"port-from-cs"});
myPort.onMessage.addListener(function(m) {
document.querySelector("#warning").innerText=m.message


browser.storage.local.get("regstr_fancestor", function(res) {
var regstr_fancestor = (res.regstr_fancestor || defaultRgx_fancestor);
document.querySelector(".listextarea_fancestor").value=regstr_fancestor;
});
browser.storage.local.get("regstr", function(res) {
regstr = (res.regstr || defaultRgx);
var regstr = (res.regstr || defaultRgx);
document.querySelector(".listextarea").value=regstr;
});
window.onload= function()
{
txarea = document.querySelector(".listextarea");
txarea.onkeyup = txarea.onchange = function(){
txarea_fancestor = document.querySelector(".listextarea_fancestor");
txarea.onkeyup = txarea.onchange = txarea_fancestor.onkeyup = txarea_fancestor.onchange
= function(){
regstr = txarea.value.trim()
myPort.postMessage({updateRegexpes: regstr});
regstr_fancestor = txarea_fancestor.value.trim()
myPort.postMessage({
updateRegexpes: regstr,
updateRegexpes_fancestor:regstr_fancestor
});
}
}
1 change: 1 addition & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ The extension allows you to load remote content in iframes even if the server di
- 1.2 : [Added regexp based whitelist](https://github.com/ThomazPom/Moz-Ext-Ignore-X-Frame-Options/issues/1)
- 1.3 : Minor fixes
- 1.4 : Added frame-ancestor support
- 1.5 : Added parent domain whitelist (https://github.com/ThomazPom/Moz-Ext-Ignore-X-Frame-Options/issues/4)

# Downloads
- [Download with firefox](https://addons.mozilla.org/fr/firefox/addon/ignore-x-frame-options-header/)
Expand Down

0 comments on commit d0b5c34

Please sign in to comment.