You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
A library to make parsing and generating CSP policies a little easier.
5
+
6
+
Read more about Content Security Policies: [https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP](https://developer.mozilla.org/en-US/docs/Web/HTTP/CSP)
7
+
8
+
9
+
## Using this library
10
+
11
+
Parsing a CSP string:
12
+
13
+
```python
14
+
policy = CSP("default-src 'self';")
15
+
```
16
+
returns a CSP object with a `default_src` attribute with value `["'self'"]`.
17
+
18
+
Generating a CSP string:
19
+
20
+
```python
21
+
policy = CSP()
22
+
policy.default_src = ["'self'"]
23
+
policy.image_src = ["*"]
24
+
policy.media_src = ["example.org", "example.net"]
25
+
generated_policy = policy.generate()
26
+
```
27
+
returns a string with the value `default-src 'self'; img-src *; media-src example.org example.net;`.
0 commit comments