Giter Site home page Giter Site logo

anthnyajp / cspr-collector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from mhilker/cspr-collector

0.0 0.0 0.0 4.38 MB

Content-Security-Policy Violation Reporting API

Home Page: https://cloud.docker.com/repository/docker/mhilker/cspr-collector

License: MIT License

Go 96.76% Dockerfile 3.24%

cspr-collector's Introduction

CSPR Collector

Content Security Policy Report Collector.

Synopsis

$ ./cspr-collector --help
Usage of ./build/cspr-collector:
  -host string
        address to listen for http requests on (default "127.0.0.1:8080")
  -n int
        the number of workers to start (default 4)
  -output-es
        enable elasticsearch output
  -output-es-ca-file string
        ca file for elasticsearch
  -output-es-cert-file string
        cert file for elasticsearch
  -output-es-host string
        elasticsearch host to send the csp violations to (default "http://localhost:9200/")
  -output-es-index string
        elasticsearch index to save the csp violations in (default "cspr-violations")
  -output-es-key-file string
        key file for elasticsearch
  -output-http
        enable http output
  -output-http-host string
        http host to send the csp violations to (default "http://localhost:80/")
  -output-stdout
        enable stdout output

Build and run

On your machine

go build -o build/cspr-collector ./cmd/cspr-collector/main.go
./build/cspr-collector -host 0.0.0.0:8080 -output-stdout

Via docker

docker build -t mhilker/cspr-collector:latest -f cmd/cspr-collector/Dockerfile .
docker run -p 8080:8080 mhilker/cspr-collector:latest -host 0.0.0.0:8080 -output-stdout

Via docker-compose

docker-compose -f cmd/cspr-collector/docker-compose.yml build
docker-compose -f cmd/cspr-collector/docker-compose.yml up

Example request

curl -X POST \
  http://localhost:8080 \
  -H 'Content-Type: application/csp-report' \
  -d '{
    "csp-report": {
        "document-uri": "https://example.com/path/to/file",
        "referrer": "",
        "violated-directive": "script-src-elem",
        "effective-directive": "script-src-elem",
        "original-policy": "default-src '\''self'\''; img-src '\''self'\'' https://*.ytimg.com; script-src-elem '\''self'\'' https://storage.googleapis.com https://www.youtube.com; connect-src '\''self'\'' https://www.googleapis.com; frame-src '\''self'\'' https://www.youtube.com; base-uri '\''self'\''; frame-ancestors '\''none'\''; form-action '\''self'\''; block-all-mixed-content; report-uri https://reporting.example.com/;",
        "disposition": "report",
        "blocked-uri": "https://www.youtube.com/iframe_api",
        "line-number": 1,
        "column-number": 7982,
        "source-file": "://example.com/static/js/7.74a7cce6.chunk.js",
        "status-code": 0,
        "script-sample": ""
    }
}'

Requirements

Elasticsearch Output

The elasticsearch output requires an elasticsearch index called csp-violations with a doc-type _doc. A mapping template is included in the template.json file.

curl -X POST \
    --header "Content-Type: application/json" \
    --data-binary @template.json \
    http://localhost:9200/_template/cspr-violations

Code Style

go fmt ./...

License

The MIT License (MIT). Please see the license file for more information.

cspr-collector's People

Contributors

mhilker avatar

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.