Skip to the content
Documentation
Help Start
Reading in:
  • German: 9,059 of 9,059 pages
About the help in other languages
All help pages

Content Security Policy for your code

Write templates and scripts that run under Exponential's Content Security Policy - no inline scripts, handlers or styles; page scripts as files, data-* attributes and JSON data blocks; adding sources; reading the CSP…

Download as PDF

Address: https://doc.exponential.earth/exphelp/viewer/help/creators/app-creators/content-security-policy.md

On this page

Content Security Policy for your code

This page is for application creators whose templates and scripts must work under a Content Security Policy. The administration runs under one and blocks inline code once enforced; public sites can turn it on (Content Security Policy).

Contents

  1. The shipped policy
  2. What that forbids
  3. How to write it instead
  4. Sources from other hosts
  5. Checking your pages

The shipped policy

site.ini [ContentSecurityPolicy]: Mode=auto (report-only on administration siteaccesses, off on others), Directives[] with default-src 'self', script-src 'self', style-src 'self', img-src 'self' data: blob:, object-src 'none', frame-ancestors 'self' and more. With Nonce=enabled the administration's policy carries a per-request nonce.

What that forbids

ForbiddenWhy
<script> with code in templatesscript-src 'self' allows script files only
onclick=, onload= ... attributesinline handlers
javascript: linksinline code
<style> elements, style="" attributesstyle-src 'self' allows stylesheet files only
eval(), new Function()no unsafe-eval
scripts and fonts from other hostsnot in the policy unless added

How to write it instead

Instead ofWrite
inline page scripta file design/<design>/javascript/..., printed with {ezscript( array( 'page/expdemo_list.js' ) )}
values for a scriptdata-* attributes washed for HTML, or JSON: data-conf="{json_encode( hash( ... ) )|wash}"
a configuration object<script type="application/json" id="..."> read by a script file (data, not code)
onclicka class or data-* attribute and addEventListener in the script file
style="width: 40%"a class, or a CSS custom property set from a stylesheet class
admin confirm and toggle buttonsthe shared data-a4-* actions of a4_actions.js (data-a4-confirm, data-a4-toggle-checkboxes ...)

In admin designs, styles also follow the admin rules: shared components and tokens, module CSS in stylesheets/modules/ (admin4 styling).

Sources from other hosts

# extension/expdemo/settings/site.ini.append.php
[ContentSecurityPolicy]
AdditionalSources[]=script-src https://maps.example.org
AdditionalSources[]=connect-src https://api.example.org

AdditionalSources[] is a list, so extensions and siteaccesses each add their hosts.

Checking your pages

  • Open each page with the browser console: violations are reported there.
  • Reports reach csp/report and are written to var/log/csp.log.
  • The kernel's tests/tests/design/AdminContentSecurityPolicyTest.php checks templates of the admin design chains, including active extensions' templates; an extension with inline code shows up there.

Become an Exponential Partner

Partners share their information, provide funding, contribute back and develop the products with us, and that is how Exponential grows. A partner website and dashboard are planned for mid-2027: please become a partner today to speed up our growth rate and land new features faster.

Something wrong on this page? Report an error

Documentation license

This documentation is free documentation, licensed under the GNU Free Documentation License 1.3 or later.

Exponential Copyright © 1998-2026 Exponential Foundation and 7x