Giter VIP home page Giter VIP logo

csp-report-collector's Introduction

csp-report-collector

Content Security Policy Report Collector

Python Flask App to receive and store CSP violation reports from browsers.

Configuration

The CSP Report Collector is configurable via file and environment variables. Loading environment variables from .env files are also supported.

The configuration file must be called settings.conf.

Environment variables take precedence over options specified in the config file.

ENVVAR Config File Example Description
CSPRC_DB_URI db_uri mariadb://localhost:3306/csp_reports Full database connection string. e.g. sqlite://db.sqlite
CSPRC_DB_TYPE db_type sqlite, mariadb, mssql, postgresql The Type of database to use
CSPRC_DB_HOST db_host localhost, 127.0.0.1 The hostname or IP address of the database server
CSPRC_DB_PORT db_port 1433, 3306, 5432 The port of the database server. May be left blank to use the default for the db_type.
CSPRC_DB_USERNAME db_username user The username to authenticate to the db server with
CSPRC_DB_PASSWORD db_password correcthorsebatterystaple The password to authenticate to the db server with
CSPRC_DB_NAME db_name csp_reports

You may specify the db connection string as a single db_uri entry, or through a combination of db_uri and other options.

Examples

Using DB_URI Only:

export CSPRC_DB_URI="mariadb://username:password@localhost:3306/csp_reports

Using a combination of DB_URI and individual options:

export CSPRC_DB_URI="mariadb://localhost:3306"
export CSPRC_DB_USERNAME="username"
export CSPRC_DB_PASSWORD="password"
export CSPRC_DB_NAME="csp_reports"

How to use

It is recommended to use the finalduty/csp-report-collector container from Dockerhub, but you may also build a container from the Dockerfile, or install the app locally using pipenv.

The app does not currently support TLS, and so it is recommended to run it behind a TLS Proxy such as Nginx or Traefik.

## Start container
docker run -d --rm -p 8000:8000 -e CSPRC_DB_URI="sqlite:///db.sqlite" --name csp_report_collector finalduty/csp_report_collector

## Check the status endpoint, this should return a 200
curl http://localhost:8000/status

## Submit a test CSP Report, this should return a 204
curl -X POST http://localhost:8000/ -H 'Content-Type: application/csp-report' --data-binary '{"csp-report":{"document-uri":"https://domain.evil/","referrer":"","violated-directive":"frame-ancestors","effective-directive":"frame-ancestors","original-policy":"frame-ancestors *.domain.net;","disposition":"enforce","blocked-uri":"https://domain.evil/","status-code":0,"script-sample":""}}'

## Stop container
docker stop csp_report_collector

License

MIT License

csp-report-collector's People

Contributors

dependabot[bot] avatar finalduty avatar maillol avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

csp-report-collector's Issues

pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

Preconditions

This project is excactly what I was looking for and I'm trying to set up a running system on my Windows host.
Sorry I have no experience with the used tech-stack.

  • I have the docker container running and receive all expected responses from port 8000 when doing the documented curl tests.
  • I have a MongoDB running on port 27017, created a DB and collection and can successfully connect to it using MongoDB Compass GUI client on windows.
  • Changed line no. 2 in settings.conf.example to enable = True (and rebuilt the image and started new container)

Issue

The POST request with sample JSON now returns 500 Internal Server Error and in the docker terminal I see this:

2023-08-21 16:46:22   File "/usr/lib/python3.6/site-packages/pymongo/topology.py", line 200, in _select_servers_loop
2023-08-21 16:46:22     self._error_message(selector))
2023-08-21 16:46:22 pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused

Additional Infos

  • Tried to start the container with additional port-mapping: -p 8000:8000 -p 27017:27017 without seeing any effect
  • The same Connection refused error occurs also when my MongoDB server is not running
  • When MongoDB server is running, it does not show any connection attempts in console output (exept the ones from MongoDB Compass)

Please excuse when opening a new issue here is not appropriate for this kind of support request.
And maybe my issue is only belonging to docker networking and my docker setup is missing something?

But for beginners it might be helpful if the README.md could be more detailed or point out helpful resources?
A working DB connection is crucial for the usage of this nice project.

Thanks in advance, Robin

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.