.. include:: /includes.rst.txt .. comments - headings # with overline, for parts * with overline, for chapters = for sections - for subsections ^ for subsubsections " for paragraphs * for H5 + for H6 .. index:: Content Security Policy .. _content_security_policy: Content Security Policy (CSP) ============================= A **Content Security Policies** (CSP) is a mechanism that a web application uses to protect against cross-site scripting (XSS) attacks. Web browsers check all web content against the application's policy, and block content that violates the policy. This makes it harder for an attacker to inject malicious content into the application. .. note:: For more information regarding how this policy is implemented and enforced visit, https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Security-Policy. .. _Default CSP: TopBraid EDG default content security policy -------------------------------------------- By default, TopBraid EDG uses a strict content security policy. :: script-src 'strict-dynamic' 'nonce-{{nonce}}' 'unsafe-inline' https: http:; base-uri 'self'; object-src 'none'; frame-ancestors 'self' .. tip:: The ``{{nonce}}`` placeholder is replaced with a unique value per request, and the ``'unsafe-inline' https: http:`` part is a fallback for legacy browsers. The policy restricts JavaScript execution and the ability to load the application in frames. Impact on JavaScript customizations ----------------------------------- Some JavaScript features are disabled or restricted under a strict policy. EDG customizations that use JavaScript can be impacted by this. Most notably: * The HMTL `` In HTML template files (e.g., when :ref:`customizing the login form `): .. code-block:: HTML * The event handler HTML attributes (``onclick``, etc.) are disabled. Instead, use JavaScript to attach the event handler to the element, for example .. code-block:: javascript element.addEventHandler('click', function() { ... }) In SWP, this can be achieved by nesting this inside the HTML element: .. code-block:: javascript * ``javascript:...`` URLs are disabled. The common idiom for a link that triggers JavaScript code does not work: .. code-block:: HTML Instead, a button styled as a link can be used: .. code-block:: HTML