Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SEC-1051: added CSP policy to headers in nginx config #167

Merged
merged 1 commit into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions nginx.conf
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ http {
add_header Strict-Transport-Security "max-age=31536000; includeSubdomains" always;
add_header X-Content-Type-Options "nosniff" always;
add_header 'Referrer-Policy' 'strict-origin';
# 'sha256-ruKmkK0iwJgE/F4xuzLY3V2OuzVOOJISav7NURhCKsM=' hugo discuss template (https://github.com/gohugoio/hugo/blob/master/tpl/tplimpl/embedded/templates/disqus.html)
aleksandrychev marked this conversation as resolved.
Show resolved Hide resolved
add_header Content-Security-Policy "default-src 'none'; style-src 'self' 'unsafe-inline' cdn.jsdelivr.net; connect-src 'self' *.disqus.com *.disquscdn.com *.google-analytics.com; script-src 'self' 'sha256-ruKmkK0iwJgE/F4xuzLY3V2OuzVOOJISav7NURhCKsM=' *.disqus.com *.disquscdn.com *.googletagmanager.com; object-src 'self'; img-src 'self' data: https:; font-src 'self' https:; frame-src 'self' www.google.com www.youtube.com; manifest-src 'self'; base-uri 'self'; form-action 'self'; frame-ancestors 'self'; upgrade-insecure-requests;";

#add_header Feature-Policy "speaker self;fullscreen self;";
## Block common exploits
## https://www.howtoforge.com/nginx-how-to-block-exploits-sql-injections-file-injections-spam-user-agents-etc
Expand Down
17 changes: 17 additions & 0 deletions static/js/cookie-consent-listener.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
let gaInitialized = false;
document.addEventListener('cookieconsent_allowed', () => {
console.log('allowed');
if (gaInitialized === true) return;
const script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-TW89K2P8L4';
document.head.appendChild(script);
script.addEventListener('load', function () {
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-TW89K2P8L4');
gaInitialized = true;
});
});
19 changes: 1 addition & 18 deletions themes/cfbs-theme/layouts/partials/header.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,24 +24,7 @@
<meta name="twitter:description" content="{{ if isset .Params "preview_description" }}{{ index .Params "preview_description" }}{{ else }}{{ .Params.Description }}{{ end }}" />
<meta name="twitter:image" content="{{ if isset .Params "preview_image_url" }}{{ index .Params "preview_image_url" }}{{ else }}https://build.cfengine.com/module.png{{ end }}" />

<script>
let gaInitialized = false;
document.addEventListener('cookieconsent_allowed', () => {
if (gaInitialized === true) return;
const script = document.createElement('script');
script.src = 'https://www.googletagmanager.com/gtag/js?id=G-TW89K2P8L4';
document.head.appendChild(script);
script.addEventListener('load', function () {
window.dataLayer = window.dataLayer || [];
function gtag() {
dataLayer.push(arguments);
}
gtag('js', new Date());
gtag('config', 'G-TW89K2P8L4');
gaInitialized = true;
});
});
</script>
<script src="{{ "js/cookie-consent-listener.js" | relURL }}"></script>
</head>
<body>

Expand Down
Loading