Skip to main content

Content security ( CSP )

Updated 1 min readMarkdown
Part of seriesWeb security
Content security ( CSP )

Content Security Policy ( CSP )

CSP is a layer that helps to prevent certain types of attacks including Cross-Site Scripting ( XSS ) and data injection attacks. These types of attacks are used to deface websites and steal data.

CSP is designed to be fully backward compatible.

How to use

Basically, there are two ways to use the CSP, First way is to set Content-Security-Policy in HTTP Header and the second way is to set element in HTML <head>.

Header Example:

<?php
    header("Content-Security-Policy: default-src 'self'");
?>

HTML Example:

<meta http-equiv="Content-Security-Policy"
      content="default-src 'self'; img-src https://*; child-src 'none';">

About the author

  • Security Engineer, DevSecOps

No comments yet. Be the first to comment.

Web security

Part 1 of 1

I will post my details learning of basic.