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

feat(#1869): Allow script-src and connect-src configuration #1870

Merged
merged 1 commit into from
Jun 11, 2023
Merged

feat(#1869): Allow script-src and connect-src configuration #1870

merged 1 commit into from
Jun 11, 2023

Conversation

timo-reymann
Copy link
Contributor

@timo-reymann timo-reymann commented Jun 6, 2023

Fixes #1869
Fixes #259

As discussed in LycheeOrg/Lychee#1896, this enables modification of the Content Security Policy, allowing users to integrate Trackers as Matomo, Google Analytics, etc. as well as loading JavaScript from external sources.

This is compatible with previous versions and the setting doesn't need to be set explicitly with an env var.

The following example JavaScript works with the new settings (Matomo tracker):

var _paq = window._paq = window._paq || [];
_paq.push(['trackPageView']);
_paq.push(['enableLinkTracking']);
(function() {
  var u="https://analytics.example.com/";
  _paq.push(['setTrackerUrl', u+'matomo.php']);
  _paq.push(['setSiteId', '<site-id>']);
  var d=document, g=d.createElement('script'), s=d.getElementsByTagName('script')[0];
  g.async=true; 
  g.src=u+'matomo.js'; 
  s.parentNode.insertBefore(g,s);
})();

navigation.addEventListener("navigate", function(e) {
  _paq.push(['setDocumentTitle', document.title]);
  _paq.push(['trackPageView']);
});

Assuming the following env vars are set:

SECURITY_HEADER_SCRIPT_SRC_ALLOW=https://analytics.example.com/matomo.js
SECURITY_HEADER_CSP_CONNECT_SRC=https://analytics.example.com/matomo.js

Also supports multiple values separated by spaces.

Copy link
Member

@ildyria ildyria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

Copy link
Member

@ildyria ildyria left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM.

@codecov
Copy link

codecov bot commented Jun 8, 2023

Codecov Report

Merging #1870 (b11b5eb) into master (1a0b831) will decrease coverage by 0.48%.
The diff coverage is n/a.

Additional details and impacted files

@ildyria ildyria merged commit 607c763 into LycheeOrg:master Jun 11, 2023
@ildyria ildyria added this to the 4.9.3 milestone Jun 12, 2023
@timo-reymann timo-reymann deleted the 1869-allow-dynamic-configuration-of-secure-headers branch June 30, 2023 10:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Enhancement] Allow dynamic configuration of secure headers [Enhancement] Counters for Number of Views
2 participants