Renamed server roles by osi they work on

This commit is contained in:
2025-07-10 12:33:46 +02:00
parent c94d623f8f
commit 96268e7161
120 changed files with 167 additions and 167 deletions

View File

@@ -0,0 +1,24 @@
# 🌐 iFrame Notifier for Nginx
This Ansible role injects a small JavaScript snippet into your HTML responses that enables parent pages to get notified whenever the iframes location changes and forces external links to open in a new tab.
---
## Features
- **Location Change Notification**
Uses `postMessage` to inform the parent window of any URL changes inside the iframe (including pushState/popState events) for seamless SPA support.
- **External Link Handling**
Automatically sets `target="_blank"` and `rel="noopener"` on links pointing outside your primary domain to improve security and user experience.
- **Easy CSP Integration**
Calculates a CSP hash for the injected script so you can safely allow it via your Content Security Policy.
---
## Author
Developed by **Kevin Veen-Birkenbach**
[https://www.veen.world](https://www.veen.world) 🎉

View File

@@ -0,0 +1,28 @@
---
galaxy_info:
author: "Kevin Veen-Birkenbach"
description: "Injects a JS snippet into HTML to notify parent windows of iframe location changes and force external links to new tabs."
company: |
Kevin Veen-Birkenbach
Consulting & Coaching Solutions
https://www.veen.world
license: "CyMaIS NonCommercial License (CNCL)"
repository: https://s.veen.world/cymais
issue_tracker_url: https://s.veen.world/cymaisissues
documentation: https://s.veen.world/cymais
license_url: "https://s.veen.world/cncl"
min_ansible_version: "2.9"
platforms:
- name: Archlinux
versions:
- rolling
galaxy_tags:
- nginx
- iframe
- javascript
- csp
- security
- postMessage
dependencies:
- srv-web-7-4-core

View File

@@ -0,0 +1,12 @@
- name: "Load iFrame handler JS template for '{{ application_id }}'"
set_fact:
iframe_code: "{{ lookup('template','iframe-handler.js.j2') }}"
- name: "Collapse iFrame code into one-liner for '{{ application_id }}'"
set_fact:
iframe_code_one_liner: "{{ iframe_code | to_one_liner }}"
- name: "Append iFrame CSP hash for '{{ application_id }}'"
set_fact:
applications: "{{ applications | append_csp_hash(application_id, iframe_code_one_liner) }}"
changed_when: false

View File

@@ -0,0 +1 @@
<script>{{ iframe_code_one_liner | replace("'", "\\'") }}</script>

View File

@@ -0,0 +1,46 @@
(function() {
var primary = "{{ primary_domain }}";
var allowedOrigin = "https://{{ domains | get_domain('portfolio') }}";
function notifyParent() {
try {
window.parent.postMessage({
type: "iframeLocationChange",
href: window.location.href
}, allowedOrigin);
} catch (e) {}
}
function forceExternalLinks() {
Array.prototype.forEach.call(document.querySelectorAll("a[href]"), function(a) {
try {
var url = new URL(a.href, location);
if (!url.hostname.endsWith(primary)) {
a.target = "_blank";
a.rel = "noopener";
}
} catch (e) {}
});
}
window.addEventListener("load", function() {
notifyParent();
forceExternalLinks();
});
window.addEventListener("popstate", function() {
notifyParent();
forceExternalLinks();
});
// SPA support
var _pushState = history.pushState;
history.pushState = function() {
_pushState.apply(history, arguments);
notifyParent();
forceExternalLinks();
};
})();
{% if enable_debug | bool %}
console.log("[iframe-sync] Sender for iframe messages is active.");
{% endif %}