Navigation
  • SEARCH HERE
  • SOLUTIONS
    • Information Security Solutions
      • Enterprise Application Security Solutions in Asia
      • Network & Infrastructure Security Solutions
      • Zero Trust Security
      • Security Information and Event Management
      • Remote Monitoring & Management (RMM)
      • File Integrity Management
      • Systems Administration Tools
      • Data Loss Prevention
      • Data / Password Recovery
      • IT Management Solution Offering | Distributor in Asia
      • Identity and Access Management Solution Offering | Distributor in Asia
      • Employee Activity Monitoring (EAM)
      • Digital Forensic Investigation
    • Software Development Solutions
      • Integrated Development Environments
      • Development Components
        • UI Tools
        • Networking Components
        • Office Components
        • Barcode Components
        • Communication Components
      • Imaging Solutions
      • Software Localization
      • Release Automation & Management
      • eLearning Authoring Solutions
      • Charting Solutions
      • PDF Solutions
      • Reporting Solutions
      • Testing & QA
      • Text Retrieval / Enterprise Search
      • Database
  • Services
    • Live Solution Walkthroughs
    • Implementation Services
    • Best Practices Consulting
    • Pre-Sales and Post-Sales Services
  • What's New
    • Our Event
    • Our Blogs
    • Special Offers
  • About
    • About LOGON Software Asia
    • Our Partnership
  • Publishers - Join our network
  • Resellers - Expand your portfolio
  • Procurement Managers
Site logo
  • Solutions
    • Information Security Solutions
      • Identity and Access Management
        • Privileged Access Management (PAM)
        • Multi-Factor Authentication (MFA)
        • Identification Verification (IV)
        • Self-Service Password Reset (SSPR)
      • Network & Infrastructure Security
        • DDoS Mitigation and Protection
        • Digital Forensic Investigation
        • Malware Detection & Analysis
        • Network Monitoring Software
        • Email Security
        • Log Monitoring
      • Endpoint & Device Security
        • Patch Management
        • Remote Monitoring & Management (RMM)
        • Employee Activity Monitoring (EAM)
        • Mobile Device Management (MDM)
      • IT Management
        • IT Service Management
        • IT Asset Management
        • Software Asset Management
        • Hardware Asset Management
        • Software License Management
        • Systems Administration Tools
      • Application Security
        • Development Security | Shift Left AppSec | SAST, SCA, IAST
        • Runtime Protection Solutions | DAST, RASP, WAF, Container Security
        • Strategic Management Solutions | ASPM, MAST, VAPT
      • Data Security
        • Data / Password Recovery
        • File Integrity Management
        • Data Loss Prevention
      • Cloud Security
        • Cloud Security Posture Management
        • Cloud Work Protection
      • External Attack Surface Management
        • Cyber Threat Intelligence
        • Third Party Risk Management
      • Security Operations & Incident Management
        • Security Information and Event Management
        • Security Orchestration, Automation and Response (SOAR)
      • Zero Trust Security
    • Software Development Solutions
      • Integrated Development Environments
      • Imaging Solutions
      • UI Tools
      • Charting Solutions
      • Developer Tools
      • Database
      • Networking Components
      • Office Components
      • Barcode Components
      • Release Automation & Management
      • Software Localization
      • Communication Components
      • Automated Testing
      • eLearning Authoring Solutions
      • Reporting Solutions
      • Text Retrieval / Enterprise Search
      • Testing & QA
  • Services
        • Live Walkthrough Sessions

          Experience the full feature of our key solutions through live platform

          View All Sessions >
        • Implementation Services
        • Pre-Sales and Post-Sales Services
        • Best Practices Consulting
  • Partners
    • Our Partners
    • Partner with LOGON Today!
      • Vendors - Join Our Network
      • Resellers - Expand Your Portfolio
      • Procurement Managers
  • Resources
        • ABOUT US

        • About Us
        • Our Locations
        • Careers@LOGON - We are hiring !
        • DISCOVER

        • Our BlogsNEW BLOGS
        • Our EventsJOIN UPCOMING EVENTS
        • LOGON to CyberSecurity PodcastNEW EPISODES
        • GET HELP

        • Contact Us
        • Help Desk
        • Request a Demo
        • Request a Quote
        • COMPLIANCE

        • 🇭🇰 Hong Kong PDPO
        • 🇮🇳 India DPDP Act
        • 🇸🇬 Singapore PDPA
        • 🇹🇭 Thailand PDPA
  • More results...

View large
Blog, Reflectiz Blog

8 Best Content Security Policies for 2022 | Reflectiz

8 Best Content Security Policies for 2022

**This article is originally published by our partner, Reflectiz. Click here to view the original article.

From small startups to massive conglomerates, every organization faces the risk of cyberattacks. Although security measures have improved, hackers continuously find new methods to bypass them. One of the most common ways hackers access a site or network is by taking advantage of weak content security policies and injecting their malicious code into it through existing content.

Statistics suggest that close to 40% of cyberattacks targeting large US and European companies in 2019 used cross-scripting, a form of attack that exploits content security vulnerabilities. Organizations have turned to strict content security policy measures to help mitigate the problem in the past. But cybercriminals are quickly outpacing this solution.

 

What Is Content Security Policy (CSP), and How Does It Work?

Content Security Policy (CSP) is a computer security standard that has been in use since 2004. This veteran technique aims to combat code injection attacks such as cross-site scripting (XSS) and clickjacking, which target website areas where users can add content (such as checkout pages).

While CSP can help protect against these attacks, it requires adding a CSP HTTP header into the webpage and assigning specific values to control the resources users add to it, including pictures, videos, and forms. Delineating specific values to all incoming content makes it harder for attackers to inject code into your websites through user uploads.

CSPs allow you to restrict the content your users can upload to the site through directives in the HTTP response header or via specific page-level directives through HTML meta tags. To be effective, a CSP needs to be well planned. CSPs are directives that guide which resources (images, fonts, multimedia, and especially scripts) the user must add to ensure that their browsing environment remains secure.

 

 

8 Most Commonly Used CSPs

CSPs can vary, and what makes one policy better than another can depend on your site’s specific needs. We’ve collected our top eight recommendations for 2022 for you to pick and choose what may work best with your existing CSP, your other cybersecurity policies, and, most importantly, your organization’s unique needs.

 

1: Basic CSP Policy

This basic policy limits the resources used in the default directives to resources from the originating domain and prevents inline scripts/styles execution. That’s how this policy contains cross-site framing and cross-site form submission. In other words: These restrictions reduce your site’s attack surface, making it more secure. This policy can be applied to most modern browsers.

The most basic policy assumes:

  • There aren’t any form submissions to external websites
  • Other websites aren’t needed to frame the website
  • The same domain hosts all resources as the document
  • There aren’t any inlines or evals for scripts and style resources

The basic policy:

Content-Security-Policy: default-src ‘self’; frame-ancestors ‘self’; form-action ‘self’;

This can be made more secure by applying:

Content-Security-Policy: default-src ‘none’; script-src ‘self’; connect-src ‘self’; img-src ‘self’; style-src ‘self’; frame-ancestors ‘self’; form-action ‘self’;

This only allows the content of the same origin to be added.

 

2: Basic CSP Policy – upgrade-insecure-requests

This directive is for developers migrating from HTTP to HTTPS. It ensures that all of a site’s insecure URLs served over HTTP are treated as though they have been replaced with secure URLs (served over HTTPS). This policy is designed for websites with many insecure legacy URLs, which must now be converted to secure URLs.

Content-Security-Policy: upgrade-insecure-requests;

 

 3: Basic CSP Policy to Prevent Framing Attacks

Framing attacks such as clickjacking and cross-site leaks rely on leveraging vulnerabilities in the site to slip in third-party outsider content. For example, clickjacking hides the malicious code and tricks users into clicking an element disguised as another. Implementing a CSP policy to prevent these attacks can be done with the following directives:

  • To forbid all framing of your content:
    Content-Security-Policy: frame-ancestors ‘none’;
  • To allow framing for the site itself:
    Content-Security-Policy: frame-ancestors’ self’;
  • To allow framing from trusted domains:
    Content-Security-Policy: frame-ancestors trusted.com;

Forbidding all frame-ancestors prevents any page framing, making attacks such as clickjacking impossible. Like all CSP directives, this directive can be customized to allow specific origins, such as framing from self or the same origin.

 

4: Strict Policy

A strict content security policy is based on nonces or hashes. Using a strict CSP prevents hackers from using HTML injection flaws to force the browser to execute the malicious script. The policy is especially effective against classical stored, reflected, and various DOM XSS attacks.

While all these are XSS attacks, there are slight variations. DOM-based XSS processes data that originates from an untrusted source by writing the data to a possibly dangerous sink within the DOM. Reflected XSS occurs when a site or application receives data in an HTTP request, including data within the immediate response in an insecure way. Finally, stored XSS injects code into the server, where user input is usually stored. This type of attack can only be leveled against sites that store user data, such as message boards. Strict content security policies can prevent all these attacks.

A strict policy can be applied at the following two levels:

  • Moderate Strict Policy:
    script-src ‘nonce-r4nd0m’ ‘strict-dynamic’;
    object-src ‘none’; base-uri ‘none’;
  • Locked Down Strict Policy:
    script-src ‘nonce-r4nd0m’;
    object-src ‘none’; base-uri ‘none’;

 

5: Refactoring Inline Code

When the default default-src or script-src directives are active, the security policy disables any JavaScript code placed inline in the HTML by default. For example:

<script>
var num = "20"
<script>

The inline code is moved to a separate JavaScript file and the page’s code becomes:

<script src="app.js">
</script>

The app.js now contains the var num = “20” code.

The inline code restriction also applies to inline event handlers, making the following construct blocked under the CSP:

<button id="button1" onclick="doSomething()">

This must be replaced by addEventListener calls:

document.getElementById("button1").addEventListener('click', doSomething);


6: CSP with Fetch Directives

Fetch directives control the locations from which specific resources can be loaded, telling the browser which sources to trust. When it comes to CSPs, fetch directives allow you to control the location from which resources can be loaded from, preventing foreign and malicious resources from infiltrating your site.

Directives such as script-src give developers the ability to allow trusted sources of script to execute on the page, font-src delineates the source of web fonts, and child-src allows developers to control nested browsing contexts and worker execution contexts. In addition, the directives allow developers to limit the source of content that can access the site, preventing attackers from adding malicious code. A directive is always needed, so if one isn’t added to the CSP header, the system will automatically fall back on the default-src.

 

7: CSP with Document Directives

Document directives inform the browser which properties of the document the content security policies apply to. For example, by restricting URLs that can be used as the document’s element:

Content-Security-Policy: base-uri <source>;
Content-Security-Policy: base-uri <source> <source>;

Or by enabling a sandbox for the requested resource:

Content-Security-Policy: sandbox;
Content-Security-Policy: sandbox <value>;

 

8: CSP with Navigation Directives 

Navigation directives restrict the URLs to which a document can navigate or submit forms. In turn, navigation directive policies control what location users can navigate or submit forms to. Navigation directives don’t revert to default-src directives and instead include directives such as:

  • Restricting URLs forms can be submitted to:
    Content-Security-Policy: form-action <source>;
    Content-Security-Policy: form-action <source> <source>;
  • The URL a document can initiate navigation to:
    Content-Security-Policy: navigate-to <source>;
    Content-Security-Policy: navigate-to <source> <source>;

 

Taking Your Security Policies to the Next Level

Each CSP has its pros and cons. Knowing which CSP will work best for your organization may require some trial and error, which is why CSP testing is an indispensable part of the process. As CSPs play a critical role in controlling content sources and page behavior, a single error may make your page entirely inaccessible to visitors. Testing your CSP before implementation enables you to see if it meets your organization’s needs (and avoid costly or embarrassing errors).

Despite their benefits, CSPs are not the right solution for everyone. While CSPs can help prevent malicious code injection, attack methods have evolved beyond the limited protection CSPs can offer. Although CSPs are generally effective, it’s best not to rely on a CSP as a standalone solution. Instead, combine it with other security measures such as SRI, discovery tools, and validation tests.


Securing Your Online Presence

Keep your online businesses safe by mitigating security and privacy risks resulting from next generation third-party threats on your website, without adding a single line of code.

Solution Highlight

Free Reflectiz Information Kit

Get first-hand information and use cases to discover how Reflectiz can protect your website from advanced third party based attacks

Download Now

Scan Log4J/Log4Shell vulnerabilities

Start a free scan for log4j/log4shell vulnerabilities caused by digital applications connected to your website and get full website mapping in just 10 minutes.

Get Free Scan
Contact Us Today

FOLLOW US ON

  • LinkedIn
  • Facebook
  • Instagram
  • Twitter
  • YouTube
Read Next:
Application Security BlogArtificial IntelligenceBlogLOGON Blog
AI-Augmented Penetration Testing: Meeting the Scale Challenge
Application Security BlogArtificial IntelligenceBlogIT Management BlogLOGON Blog
The First Autonomous AI Cyber Attack is Here: Is Your Enterprise Ready?
Application Security BlogBlogLOGON Blog
Shift Left, Verify Right: The Blueprint for Modern Application Security Across Asia

Privacy Policy Company Overview

COMPANY

Our Location Career with LOGON Our Partners

SERVICES

Training Services Implementation Services Pre-Sales and Post-Sales Services Best Practices Consulting

GET IN TOUCH

Phone:
Hong Kong: +852 2512 8491
India: +91 70220 22744 / +91 63668 26133
Email: [email protected] ©2025 LOGON International Ltd. All rights reserved
logon logo WHITE

Search engine

Use this form to find things you need on this site

More results...

Fill in the form below
  • This field is for validation purposes and should be left unchanged.
  • This field is hidden when viewing the form
  • This field is hidden when viewing the form

Watch On-demand Webinar

  • This field is for validation purposes and should be left unchanged.

Get Your Free UserLock Trial

  • This field is for validation purposes and should be left unchanged.

Download Your Free Trial 10-Day Trial Today

  • Downloading and evaluating Smart Package Studio is quick and easy
  • Includes a short introductory guide that suggests smart features to try
  • Access the full functionality of Smart Package Studio during the trial
  • This field is for validation purposes and should be left unchanged.

Request for Priority Support with our support team

  • This field is for validation purposes and should be left unchanged.
  • Drop files here or
    Max. file size: 30 MB.

    Get Free Assessment of your Web Asset

    Request a free non-intrusive security assessment of your website. Get a report with an overview of client-side security risks.

    • This field is for validation purposes and should be left unchanged.
    • This field is hidden when viewing the form

    Recommend a Topic

    • This field is for validation purposes and should be left unchanged.

    Partner with Us on the next episode

    • This field is for validation purposes and should be left unchanged.

    Watch On-demand Webinar

    • This field is for validation purposes and should be left unchanged.
    Start PreCrime Network for Free

    Oops! We could not locate your form.

    Book a Free Demo Today

    Get Your Free Trial

    Oops! We could not locate your form.

    Get Your Free Trial
    • This field is for validation purposes and should be left unchanged.
    • This field is hidden when viewing the form
    • This field is hidden when viewing the form
    Request for Training Quote

    Oops! We could not locate your form.

    Request for Training Quote

    Oops! We could not locate your form.

    Request for Training Quote

    Oops! We could not locate your form.

    Request for Training Quote
    • This field is for validation purposes and should be left unchanged.
    • Please enter a number from 1 to 20.
    • This field is hidden when viewing the form
    Request for Training Quote
    • This field is for validation purposes and should be left unchanged.
    • Please enter a number from 1 to 20.
    • This field is hidden when viewing the form
    Request for Training Quote
    • Please enter a number from 1 to 20.
    • DD slash MM slash YYYY
    Request for Training Quote
    • This field is for validation purposes and should be left unchanged.
    • Please enter a number from 1 to 20.
    • DD slash MM slash YYYY
    Request for Training Quote
    • This field is for validation purposes and should be left unchanged.
    • Please enter a number from 1 to 20.
    • DD slash MM slash YYYY
    Request for Training Quote
    • This field is for validation purposes and should be left unchanged.
    • Please enter a number from 1 to 20.
    • This field is hidden when viewing the form