Constructs strict Content-Security-Policy header after scanning all HTML files in a directory
Project description
Description
csp-scan is a Python script for constructing strict content-security-policy headers based on content of HTML files in a source directory. It looks for used sources and hrefs in HTML elements for most CSP directives and outputs the header content.
Includes a warning system for unencrypted HTTP connections.
Installation
pip3 install csp-scan
Usage
cd my-frontend-src
csp-scan
Options
-d, --default-src
Value for default src directive. Default: self
-r, --report-uri
Report URI to post violations to.
-l, --literal-src
Include whole src paths in the CSP.
Contribution / forking
Contributions welcome!
Context
Directive class is initiated with a name of the directive (e.g. script-src, style-src...). Uses regex to locate specific attribute in a HTML element, given an optional pre-condition or file format.
File definitions.py creates directive objects and defines their conditions through add_search_instruction method. If you want to add a directive or modify a search condition, do it there.
style_src.add_search_instruction(
tag = "link",
attribute = "href",
format = ".css"
)
This instruction will find and classify this source as style-src:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css"/>
But not this:
<link href="https://somecdn/js/somejsfile.js"/>
style_src.add_search_instruction(
tag = "link",
attribute = "href",
condition = ("rel", "stylesheet")
)
This instruction will find and classify this source as style-src:
<link
href="https://fonts.googleapis.com/css2?family=Montserrat:wght@100;400;500;600;700&display=swap"
rel="stylesheet"
/>
But not this:
<link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.6.0/css/font-awesome.min.css"/>
style_src.add_search_instruction(
tag = "link",
attribute = "href"
)
This instruction would find and classify all of the above examples.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file csp-scan-1.0.0.tar.gz.
File metadata
- Download URL: csp-scan-1.0.0.tar.gz
- Upload date:
- Size: 5.2 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
36a9bcfb8fce095ecbc2107099b85ba0902d10eabaf56274c97a6bf4a0088951
|
|
| MD5 |
e5fb41782f10aafe9b200f1b830f9045
|
|
| BLAKE2b-256 |
e8fa89b05ce3193173bc05cd1d225edd2c13d9d7af0dd6baf21d54b1e8105af8
|
File details
Details for the file csp_scan-1.0.0-py3-none-any.whl.
File metadata
- Download URL: csp_scan-1.0.0-py3-none-any.whl
- Upload date:
- Size: 6.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
5cea722fd526e4e7ef9ab574ba41382ba37b997d45264bbb1c74c2cc627689f6
|
|
| MD5 |
cd3792dddcfb7a3a588dd23937319218
|
|
| BLAKE2b-256 |
ee3e933c0b8c2073a24cc3b5e71bc88f25dadb5e058b84f155e383e6747b5d60
|