Skip to content
This repository was archived by the owner on Apr 12, 2025. It is now read-only.

Commit 36e0f30

Browse files
committed
Merge branch 'add_user_agent' into 'master'
Add user agent See merge request ix.ai/csp!14
2 parents 4d9feca + 544acf0 commit 36e0f30

File tree

9 files changed

+109
-34
lines changed

9 files changed

+109
-34
lines changed

.gitlab-ci.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
variables:
33
DOCKERHUB_REPO_NAME: csp
44
GITHUB_REPO_NAME: ix-ai/csp
5+
ENABLE_AMD64: 'true'
56
ENABLE_ARM64: 'true'
67
ENABLE_ARMv7: 'true'
78
ENABLE_ARMv6: 'true'

.pylintrc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ confidence=
6363
disable=logging-fstring-interpolation,
6464
# too-few-public-methods,
6565
invalid-name,
66-
no-self-use,
66+
# no-self-use,
6767

6868
# Enable the message, report, category or checker with the given id(s). You can
6969
# either give multiple identifier separated by comma (,) or put this option
@@ -255,8 +255,8 @@ max-module-lines=1000
255255
# separator` is used to allow tabulation in dicts, etc.: {1 : 1,\n222: 2}.
256256
# `trailing-comma` allows a space between comma and closing bracket: (a, ).
257257
# `empty-line` allows space-only lines.
258-
no-space-check=trailing-comma,
259-
dict-separator
258+
#no-space-check=trailing-comma,
259+
# dict-separator
260260

261261
# Allow the body of a class to be on the same line as the declaration if body
262262
# contains single statement.

Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
FROM alpine:latest
22
LABEL maintainer="docker@ix.ai" \
3-
ai.ix.repository="ix.ai/csp"
3+
ai.ix.repository="ix.ai/csp" \
4+
org.opencontianers.image.description="A basic Content Security Policy processor running in docker"
45

56
COPY csp/requirements.txt /csp/requirements.txt
67

README.md

Lines changed: 46 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -8,47 +8,55 @@
88
A basic Content Security Policy processor running in docker
99

1010
## WIP Warning
11+
1112
This is still work in progress
1213

1314
## What does it do?
15+
1416
It logs to STDOUT (LOGLEVEL `INFO`) and, optionally, to a GELF capable host, the received CSP violation.
1517

1618
The request must go to the path `/csp` (default) or to the path set in the environment variable `CSP_PATH`.
1719

1820
Just add the header:
19-
```
21+
22+
```txt
2023
Content-Security-Policy-Report-Only: upgrade-insecure-requests; default-src 'self'; report-uri https://example.com/csp;
2124
```
2225

2326
### Invalid requests
27+
2428
The following requests are not logged at all, instead a warning is logged:
29+
2530
* Zero-length requests (a HTTP POST containing no payload)
2631
* Requests larger than `MAX_CONTENT_LENGTH`
2732

2833
All other requests log the underlying WSGI environment to log level `DEBUG`. Non-JSON requests are also logged to the same level.
2934

3035
## Healthcheck
36+
3137
To enable a healthcheck, just point it to `/healthz` (default) or to the value set for the environment variable `HEALTHZ_PATH`. You can use `ENABLE_HEALTHZ_VERSION` to also have CSP display the version and build information (disabled by default).
3238

3339
## Usage Examples
3440

3541
### CLI
42+
3643
```sh
3744
docker run --rm -it \
3845
-p 9999:80 \
3946
-e PORT=80 \
4047
-e GELF_HOST=graylog \
4148
--name csp \
42-
registry.gitlab.com/ix.ai/csp:latest
49+
ghcr.io/ix-ai/csp:latest
4350
```
4451

4552
### docker-compose
53+
4654
```yml
4755
version: "3.7"
4856

4957
services:
5058
csp:
51-
image: registry.gitlab.com/ix.ai/csp:latest
59+
image: ghcr.io/ix-ai/csp:latest
5260
environment:
5361
PORT: '80'
5462
MAX_CONTENT_LENGTH: '512'
@@ -57,12 +65,13 @@ services:
5765
```
5866
5967
### docker stack with traefik
68+
6069
```yml
6170
version: "3.7"
6271

6372
services:
6473
csp:
65-
image: registry.gitlab.com/ix.ai/csp:latest
74+
image: ghcr.io/ix-ai/csp:latest
6675
deploy:
6776
labels:
6877
traefik.enable: 'true'
@@ -89,17 +98,21 @@ services:
8998
```
9099

91100
## Output example
101+
92102
Firefox browser and `LOGLEVEL: INFO`
93-
```
103+
104+
```txt
94105
2020-12-06 14:25:42.853 WARNING [__main__.<module>] Starting **csp refactor-225909200**. Listening on *:9180
95106
2020-12-06 14:28:15.442 INFO [csp.log_csp] {"csp-report": {"blocked-uri": "inline", "document-uri": "https://xxxREDACTEDxxx/", "original-policy": "upgrade-insecure-requests; default-src 'self' https://cdnjs.cloudflare.com; script-src 'self' https://cdnjs.cloudflare.com https://s.ytimg.com; font-src https://fonts.gstatic.com https://cdnjs.cloudflare.com; report-uri https://csp.example.com/csp", "referrer": "", "source-file": "https://xxxREDACTEDxxx/", "violated-directive": "default-src"}}
96107
2020-12-06 14:28:15.711 INFO [csp.log_csp] {"csp-report": {"blocked-uri": "inline", "column-number": 1, "document-uri": "https://xxxREDACTEDxxx/", "line-number": 925, "original-policy": "upgrade-insecure-requests; default-src 'self' https://cdnjs.cloudflare.com; script-src 'self' https://cdnjs.cloudflare.com https://s.ytimg.com; font-src https://fonts.gstatic.com https://cdnjs.cloudflare.com; report-uri https://csp.example.com/csp", "referrer": "", "source-file": "https://xxxREDACTEDxxx/", "violated-directive": "script-src"}}
97108
2020-12-06 14:28:15.724 INFO [csp.log_csp] {"csp-report": {"blocked-uri": "inline", "column-number": 3975, "document-uri": "https://xxxREDACTEDxxx/", "line-number": 3, "original-policy": "upgrade-insecure-requests; default-src 'self' https://cdnjs.cloudflare.com; script-src 'self' https://cdnjs.cloudflare.com https://s.ytimg.com; font-src https://fonts.gstatic.com https://cdnjs.cloudflare.com; report-uri https://csp.example.com/csp", "referrer": "", "source-file": "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js", "violated-directive": "default-src"}}
98109
2020-12-06 14:28:15.735 INFO [csp.log_csp] {"csp-report": {"blocked-uri": "inline", "column-number": 3975, "document-uri": "https://xxxREDACTEDxxx/", "line-number": 3, "original-policy": "upgrade-insecure-requests; default-src 'self' https://cdnjs.cloudflare.com; script-src 'self' https://cdnjs.cloudflare.com https://s.ytimg.com; font-src https://fonts.gstatic.com https://cdnjs.cloudflare.com; report-uri https://csp.example.com/csp", "referrer": "", "source-file": "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js", "violated-directive": "default-src"}}
99110
2020-12-06 14:28:15.738 INFO [csp.log_csp] {"csp-report": {"blocked-uri": "inline", "column-number": 14648, "document-uri": "https://xxxREDACTEDxxx/", "line-number": 3, "original-policy": "upgrade-insecure-requests; default-src 'self' https://cdnjs.cloudflare.com; script-src 'self' https://cdnjs.cloudflare.com https://s.ytimg.com; font-src https://fonts.gstatic.com https://cdnjs.cloudflare.com; report-uri https://csp.example.com/csp", "referrer": "", "source-file": "https://cdnjs.cloudflare.com/ajax/libs/jquery/2.2.4/jquery.min.js", "violated-directive": "default-src"}}
100111
```
112+
101113
Google Chrome browser and `LOGLEVEL: DEBUG`
102-
```
114+
115+
```txt
103116
2020-12-06 14:38:27.132 DEBUG [csp.log_csp] {'REMOTE_ADDR': '10.0.14.14', 'REMOTE_HOST': '10.0.14.14', 'REMOTE_PORT': '56224', 'REQUEST_METHOD': 'POST', 'SERVER_PORT': '9180', 'SERVER_NAME': '9f02bb970b0b', 'SERVER_SOFTWARE': None, 'SERVER_PROTOCOL': 'HTTP/1.1', 'SCRIPT_NAME': '', 'PATH_INFO': '/csp', 'QUERY_STRING': '', 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0), 'wsgi.errors': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, 'wsgi.multithread': True, 'wsgi.multiprocess': False, 'wsgi.run_once': False, 'wsgi.input': <_io.BytesIO object at 0x7fb398c89720>, 'wsgi.file_wrapper': <class 'waitress.buffers.ReadOnlyFileBasedBuffer'>, 'wsgi.input_terminated': True, 'HTTP_HOST': 'csp.example.com', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', 'CONTENT_LENGTH': '548', 'HTTP_ACCEPT': '*/*', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, br', 'HTTP_ACCEPT_LANGUAGE': 'en-DE,en-GB;q=0.9,en;q=0.8,de-DE;q=0.7,de;q=0.6,ro-RO;q=0.5,ro;q=0.4,en-US;q=0.3', 'CONTENT_TYPE': 'application/csp-report', 'HTTP_DNT': '1', 'HTTP_ORIGIN': 'https://xxxREDACTEDxxx', 'HTTP_REFERER': 'https://xxxREDACTEDxxx/', 'HTTP_SEC_FETCH_DEST': 'report', 'HTTP_SEC_FETCH_MODE': 'no-cors', 'HTTP_SEC_FETCH_SITE': 'cross-site', 'HTTP_X_FORWARDED_FOR': '2001:0DB8::1', 'HTTP_X_FORWARDED_HOST': 'csp.example.com', 'HTTP_X_FORWARDED_PORT': '443', 'HTTP_X_FORWARDED_PROTO': 'https', 'HTTP_X_FORWARDED_SERVER': '2319d1b2d5bf', 'HTTP_X_REAL_IP': '2001:0DB8::1', 'werkzeug.request': <Request 'http://csp.example.com/csp' [POST]>}
104117
2020-12-06 14:38:27.132 INFO [csp.log_csp] {"csp-report": {"document-uri": "https://xxxREDACTEDxxx/", "referrer": "", "violated-directive": "script-src-elem", "effective-directive": "script-src-elem", "original-policy": "upgrade-insecure-requests; default-src 'self' https://cdnjs.cloudflare.com; script-src 'self' https://cdnjs.cloudflare.com https://s.ytimg.com; font-src https://fonts.gstatic.com https://cdnjs.cloudflare.com; report-uri https://csp.example.com/csp;", "disposition": "report", "blocked-uri": "inline", "line-number": 925, "source-file": "https://xxxREDACTEDxxx/", "status-code": 0, "script-sample": ""}}
105118
2020-12-06 14:38:27.134 DEBUG [csp.log_csp] {'REMOTE_ADDR': '10.0.14.14', 'REMOTE_HOST': '10.0.14.14', 'REMOTE_PORT': '56220', 'REQUEST_METHOD': 'POST', 'SERVER_PORT': '9180', 'SERVER_NAME': '9f02bb970b0b', 'SERVER_SOFTWARE': None, 'SERVER_PROTOCOL': 'HTTP/1.1', 'SCRIPT_NAME': '', 'PATH_INFO': '/csp', 'QUERY_STRING': '', 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0), 'wsgi.errors': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, 'wsgi.multithread': True, 'wsgi.multiprocess': False, 'wsgi.run_once': False, 'wsgi.input': <_io.BytesIO object at 0x7fb398c89720>, 'wsgi.file_wrapper': <class 'waitress.buffers.ReadOnlyFileBasedBuffer'>, 'wsgi.input_terminated': True, 'HTTP_HOST': 'csp.example.com', 'HTTP_USER_AGENT': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 11_0_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36', 'CONTENT_LENGTH': '609', 'HTTP_ACCEPT': '*/*', 'HTTP_ACCEPT_ENCODING': 'gzip, deflate, br', 'HTTP_ACCEPT_LANGUAGE': 'en-DE,en-GB;q=0.9,en;q=0.8,de-DE;q=0.7,de;q=0.6,ro-RO;q=0.5,ro;q=0.4,en-US;q=0.3', 'CONTENT_TYPE': 'application/csp-report', 'HTTP_DNT': '1', 'HTTP_ORIGIN': 'https://xxxREDACTEDxxx', 'HTTP_REFERER': 'https://xxxREDACTEDxxx/', 'HTTP_SEC_FETCH_DEST': 'report', 'HTTP_SEC_FETCH_MODE': 'no-cors', 'HTTP_SEC_FETCH_SITE': 'cross-site', 'HTTP_X_FORWARDED_FOR': '2001:0DB8::1', 'HTTP_X_FORWARDED_HOST': 'csp.example.com', 'HTTP_X_FORWARDED_PORT': '443', 'HTTP_X_FORWARDED_PROTO': 'https', 'HTTP_X_FORWARDED_SERVER': '2319d1b2d5bf', 'HTTP_X_REAL_IP': '2001:0DB8::1', 'werkzeug.request': <Request 'http://csp.example.com/csp' [POST]>}
@@ -111,7 +124,8 @@ Google Chrome browser and `LOGLEVEL: DEBUG`
111124
```
112125

113126
Various errors (with `LOGLEVEL:DEBUG`):
114-
```
127+
128+
```txt
115129
2020-12-06 14:28:15.448 WARNING [csp.log_csp] Content too large (523445). Dropping.
116130
2020-12-06 14:52:47.747 WARNING [csp.log_csp] Empty content received
117131
2020-12-06 14:54:07.615 DEBUG [csp.log_csp] {'REMOTE_ADDR': '10.0.14.16', 'REMOTE_HOST': '10.0.14.16', 'REMOTE_PORT': '32772', 'REQUEST_METHOD': 'POST', 'SERVER_PORT': '9180', 'SERVER_NAME': '45d8708af6ab', 'SERVER_SOFTWARE': None, 'SERVER_PROTOCOL': 'HTTP/1.1', 'SCRIPT_NAME': '', 'PATH_INFO': '/csp', 'QUERY_STRING': '', 'wsgi.url_scheme': 'http', 'wsgi.version': (1, 0), 'wsgi.errors': <_io.TextIOWrapper name='<stderr>' mode='w' encoding='utf-8'>, 'wsgi.multithread': True, 'wsgi.multiprocess': False, 'wsgi.run_once': False, 'wsgi.input': <_io.BytesIO object at 0x7f8cbd65c0e0>, 'wsgi.file_wrapper': <class 'waitress.buffers.ReadOnlyFileBasedBuffer'>, 'wsgi.input_terminated': True, 'HTTP_HOST': 'csp.example.com', 'HTTP_USER_AGENT': 'curl/7.64.1', 'CONTENT_LENGTH': '10', 'HTTP_ACCEPT': '*/*', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'HTTP_X_FORWARDED_FOR': '2001:0DB8::1', 'HTTP_X_FORWARDED_HOST': 'csp.example.com', 'HTTP_X_FORWARDED_PORT': '443', 'HTTP_X_FORWARDED_PROTO': 'https', 'HTTP_X_FORWARDED_SERVER': 'de9e6f88b502', 'HTTP_X_REAL_IP': '2001:0DB8::1', 'HTTP_ACCEPT_ENCODING': 'gzip', 'werkzeug.request': <Request 'http://csp.example.com/csp' [POST]>}
@@ -121,7 +135,8 @@ Various errors (with `LOGLEVEL:DEBUG`):
121135
## Metrics
122136

123137
When setting `ENABLE_METRICS=yes`, the following metrics are exposed:
124-
```
138+
139+
```txt
125140
# HELP csp_valid_violation_reports_total Counts the number of valid violation reports
126141
# TYPE csp_valid_violation_reports_total counter
127142
csp_valid_violation_reports_total{blocked_uri="inline",document_uri="https://xxxREDACTEDxxx/",line_number="925",original_policy="upgrade-insecure-requests; default-src self https://cdnjs.cloudflare.com; script-src self https://cdnjs.cloudflare.com https://s.ytimg.com; font-src https://fonts.gstatic.com https://cdnjs.cloudflare.com; report-uri https://csp.example.com/csp;",violated_directive="script-src-elem"} 3.0
@@ -150,6 +165,7 @@ csp_version_info{version="0.2.0-225909200"} 1.0
150165
| **Variable** | **Default** | **Description** |
151166
|:-------------------------|:-----------:|:-----------------------------------------------------------------------|
152167
| `MAX_CONTENT_LENGTH` | `32768` | The maximum content length (in bytes) of the HTTP POST content |
168+
| `ENABLE_USER_AGENT` | `no` | Enable the labels `user_agent_platform`, `user_agent_browser` and `user_agent_version` |
153169
| `ENABLE_HEALTHZ_VERSION` | `no` | Set this to `yes` to show the version on the `HEALTHZ_PATH` endpoint |
154170
| `ENABLE_METRICS` | `no` | Set this to `yes` to enable the Prometheus metrics |
155171
| `CSP_PATH` | `/csp` | The path used for the CSP reporting |
@@ -162,29 +178,43 @@ csp_version_info{version="0.2.0-225909200"} 1.0
162178
| `ADDRESS` | `*` | The IP address to bind to |
163179

164180
## Breaking Changes
181+
165182
Starting with version `v0.1.0`, the log format has changed!
166183

167184
CSP will now parse and format any JSON received (smaller than `MAX_CONTENT_LENGTH`) and log it in form:
168-
```
185+
186+
```txt
169187
2020-12-06 14:59:13.855 INFO [csp.log_csp] {"ab": 2}
170188
```
171189

172190
Non-JSON content will be logged as follows:
173-
```
191+
192+
```txt
174193
2020-12-06 15:15:58.497 DEBUG [csp.log_csp] Content is not JSON: `{"ab": e2}`
175194
```
176195

196+
## Contributors
197+
198+
Thank you to the contributors:
199+
200+
* @bgi: ix.ai/csp!13
201+
202+
## Deprecations
203+
204+
**WARNING**: Due to the [introduction of storage usage quotas by GitLab](https://docs.gitlab.com/ee/user/usage_quotas.html), the `registry.gitlab.com` images will **not** be updated anymore and will soon be removed. Please switch to either Docker Hub or GitHub (see below).
205+
177206
## Tags and Arch
178207

179208
Starting with version `v0.1.0`, the images are multi-arch, with builds for i386, amd64, arm64, armv7 and armv6.
209+
180210
* `vN.N.N` - for example v0.1.0
181211
* `latest` - always pointing to the latest version
182212
* `dev-branch` - the last build on a feature/development branch
183213
* `dev-master` - the last build on the master branch
184214

185-
## Resources:
186-
* GitLab: https://gitlab.com/ix.ai/csp
187-
* GitHub: https://github.com/ix-ai/csp
188-
* GitLab Registry: https://gitlab.com/ix.ai/csp/container_registry
189-
* GitHub Registry: https://ghcr.io/ix-ai/csp
190-
* Docker Hub: https://hub.docker.com/r/ixdotai/csp
215+
## Resources
216+
217+
* GitLab: [gitlab.com/ix.ai/csp](https://gitlab.com/ix.ai/csp)
218+
* GitHub: [github.com/ix-ai/csp](https://github.com/ix-ai/csp)
219+
* GitHub Registry: `ghcr.io/ix-ai/csp` - [ghcr.io/ix-ai/csp](https://ghcr.io/ix-ai/csp)
220+
* Docker Hub: `ixdotai/csp` - [hub.docker.com/r/ixdotai/csp](https://hub.docker.com/r/ixdotai/csp)

csp/__main__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
'csp_path': 'string',
2121
'healthz_path': 'string',
2222
'metrics_path': 'string',
23+
'enable_user_agent': 'boolean',
2324
})
2425
c = csp.CSP(**options)
2526

csp/csp.py

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class CSP():
2424
'csp_path': '/csp',
2525
'healthz_path': '/healthz',
2626
'metrics_path': '/metrics',
27+
'enable_user_agent': False,
2728
}
2829

2930
def __init__(self, **kwargs):
@@ -60,7 +61,10 @@ def log_csp(self):
6061
log.debug(f"{request.environ}")
6162
content = request.get_data(as_text=True)
6263
try:
63-
log.info(self.__process_csp(json.loads(content)))
64+
if self.settings['enable_user_agent']:
65+
log.info(self.__process_csp(json.loads(content), request.user_agent))
66+
else:
67+
log.info(self.__process_csp(json.loads(content), None))
6468
except CSPError:
6569
log.debug(f'{W004}: `{content}`')
6670
log.warning(W004)
@@ -74,24 +78,37 @@ def log_csp(self):
7478

7579
return result
7680

77-
def __process_csp(self, content):
81+
def __process_csp(self, content, user_agent):
7882
""" Takes the JSON content and creates the metrics for it """
7983
try:
8084
report = content['csp-report']
8185
except KeyError:
8286
raise CSPError from KeyError
8387

8488
try:
85-
prometheus.PROM_VALID_VIOLATION_REPORTS_COUNTER.labels(
86-
blocked_uri=report['blocked-uri'],
87-
document_uri=report['document-uri'],
88-
original_policy=report['original-policy'],
89-
violated_directive=report['violated-directive'],
90-
line_number=report.get('line-number', 0),
91-
source_file=report.get('source-file'),
92-
).inc(1)
89+
labels = {
90+
'blocked_uri': report['blocked-uri'],
91+
'document_uri': report['document-uri'],
92+
'original_policy': report['original-policy'],
93+
'violated_directive': report['violated-directive'],
94+
'line_number': report.get('line-number', 0),
95+
'source_file': report.get('source-file'),
96+
}
97+
98+
if user_agent is None:
99+
prometheus.PROM_VALID_VIOLATION_REPORTS_COUNTER.labels(**labels).inc(1)
100+
else:
101+
labels.update({
102+
'user_agent_platform': user_agent.platform,
103+
'user_agent_browser': user_agent.browser,
104+
'user_agent_version': user_agent.version,
105+
})
106+
prometheus.PROM_VALID_VIOLATION_REPORTS_COUNTER_AGENT.labels(**labels).inc(1)
107+
108+
return json.dumps(labels)
93109
except KeyError:
94110
raise CSPError from KeyError
111+
95112
return json.dumps(content)
96113

97114
def healthz(self):

csp/lib/helpers.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
import logging
66
import os
7-
from distutils.util import strtobool
87

98
log = logging.getLogger("csp")
109

@@ -40,3 +39,16 @@ def gather_environ(keys) -> dict:
4039
environs[key] = {filters[0]: filters[1]}
4140
log.info(f'{key.upper()} is set')
4241
return environs
42+
43+
def strtobool(val):
44+
"""Convert a string representation of truth to true (1) or false (0).
45+
True values are 'y', 'yes', 't', 'true', 'on', and '1'; false values
46+
are 'n', 'no', 'f', 'false', 'off', and '0'. Raises ValueError if
47+
'val' is anything else.
48+
"""
49+
val = val.lower()
50+
if val in ('y', 'yes', 't', 'true', 'on', '1'):
51+
return 1
52+
if val in ('n', 'no', 'f', 'false', 'off', '0'):
53+
return 0
54+
raise ValueError(f"invalid truth value {(val,)}")

csp/lib/prometheus.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,20 @@
1515
'source_file',
1616
]
1717
)
18+
PROM_VALID_VIOLATION_REPORTS_COUNTER_AGENT = Counter(
19+
'csp_valid_violation_reports_by_user_agent',
20+
'Counts the number of valid violation reports with UserAgent details', [
21+
'blocked_uri',
22+
'document_uri',
23+
'original_policy',
24+
'violated_directive',
25+
'line_number',
26+
'source_file',
27+
'user_agent_platform',
28+
'user_agent_browser',
29+
'user_agent_version',
30+
]
31+
)
1832
PROM_INVALID_VIOLATION_REPORTS_COUNTER = Counter(
1933
'csp_invalid_violation_reports', 'Counts the number of invalid violation reports', [
2034
'reason',

csp/requirements.txt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
waitress==2.1.2
2-
flask==2.0.2
3-
prometheus_client==0.12.0
2+
flask==2.2.2
3+
prometheus_client==0.14.1
44
pygelf==0.4.2
5-

0 commit comments

Comments
 (0)