|
1 | 1 | # browser-reporting-api |
2 | 2 |
|
3 | 3 | Simple, self-hosted Go service for browser Reporting API ingestion. |
| 4 | + |
| 5 | +## General |
| 6 | + |
| 7 | +### What |
| 8 | + |
| 9 | +`browser-reporting-api` is an HTTP service that receives browser reporting |
| 10 | +payloads (`application/reports+json` and legacy `application/csp-report` from |
| 11 | +`report-uri`), validates each report entry, and streams accepted entries to |
| 12 | +stdout as NDJSON (one JSON object per line). |
| 13 | + |
| 14 | +The payload format and reporting behavior align with the browser Reporting API |
| 15 | +documented by |
| 16 | +[MDN](https://developer.mozilla.org/en-US/docs/Web/API/Reporting_API) and |
| 17 | +[Chrome](https://developer.chrome.com/docs/capabilities/web-apis/reporting-api). |
| 18 | + |
| 19 | +Endpoints: |
| 20 | + |
| 21 | +- `POST /v1/reports` (or `{BASE_PATH}/v1/reports`) |
| 22 | +- `GET /v1/manage/healthz` |
| 23 | +- `GET /v1/manage/readyz` |
| 24 | + |
| 25 | +### Why |
| 26 | + |
| 27 | +- Simple to run and reason about |
| 28 | +- Safe enough for ingestion (size limits, content-type checks, per-entry |
| 29 | + vetting) |
| 30 | +- Easy to self-host and observe (accepted reports stream to stdout) |
| 31 | +- Collected browser reports (including CSP report traffic) may support |
| 32 | + client-side monitoring and script-governance such as those relevant to PCI DSS |
| 33 | + payment-page security guidance for Requirements 6.4.3 and 11.6.1 from the |
| 34 | + [PCI Security Standards Council](https://blog.pcisecuritystandards.org/new-information-supplement-payment-page-security-and-preventing-e-skimming) |
| 35 | + |
| 36 | +### How |
| 37 | + |
| 38 | +Run locally with Go: |
| 39 | + |
| 40 | +```bash |
| 41 | +go run ./cmd/server |
| 42 | +``` |
| 43 | + |
| 44 | +Run a local demo with Docker Compose: |
| 45 | + |
| 46 | +```bash |
| 47 | +make demo |
| 48 | +``` |
| 49 | + |
| 50 | +This starts the API, sends a sample batched report payload, and prints API logs. |
| 51 | +To keep watching streamed report lines: |
| 52 | + |
| 53 | +```bash |
| 54 | +make logs |
| 55 | +``` |
| 56 | + |
| 57 | +The demo sender payload is stored at `demo/reports.json`. |
| 58 | + |
| 59 | +Send a manual sample report: |
| 60 | + |
| 61 | +```bash |
| 62 | +make report |
| 63 | +``` |
| 64 | + |
| 65 | +`make report` sends the same payload file used by the compose demo: |
| 66 | +`demo/reports.json`. |
| 67 | + |
| 68 | +Health check: |
| 69 | + |
| 70 | +```bash |
| 71 | +make health |
| 72 | +``` |
| 73 | + |
| 74 | +Stop containers: |
| 75 | + |
| 76 | +```bash |
| 77 | +make down |
| 78 | +``` |
| 79 | + |
| 80 | +Environment variables: |
| 81 | + |
| 82 | +- `LISTEN_ADDR` (default `:8080`) |
| 83 | +- `BASE_PATH` (default `/`) |
| 84 | +- `MAX_BODY_BYTES` (default `1048576`) |
| 85 | +- `REPORTS_ALLOWED_ORIGINS` (default `*`) |
| 86 | + |
| 87 | +Allowed origin examples: |
| 88 | + |
| 89 | +- `REPORTS_ALLOWED_ORIGINS=*` |
| 90 | +- `REPORTS_ALLOWED_ORIGINS=https://app.example.com,https://admin.example.com` |
| 91 | +- `REPORTS_ALLOWED_ORIGINS=https://*.example.com,http://localhost:*` |
| 92 | + |
| 93 | +If `BASE_PATH=/collector`, endpoints become: |
| 94 | + |
| 95 | +- `POST /collector/v1/reports` |
| 96 | +- `GET /collector/v1/manage/healthz` |
| 97 | +- `GET /collector/v1/manage/readyz` |
| 98 | + |
| 99 | +## Development |
| 100 | + |
| 101 | +Run tests: |
| 102 | + |
| 103 | +```bash |
| 104 | +go test ./... |
| 105 | +``` |
| 106 | + |
| 107 | +Make targets used during development: |
| 108 | + |
| 109 | +```bash |
| 110 | +make test |
| 111 | +make run |
| 112 | +make up |
| 113 | +make demo-send |
| 114 | +make demo |
| 115 | +make logs |
| 116 | +make report |
| 117 | +make health |
| 118 | +make down |
| 119 | +``` |
| 120 | + |
| 121 | +Implementation notes: |
| 122 | + |
| 123 | +- Routes are mounted under configurable `BASE_PATH`. |
| 124 | +- Reporting ingestion accepts batched arrays and processes entries |
| 125 | + independently. |
| 126 | +- Invalid entries are rejected while valid entries in the same batch are still |
| 127 | + accepted. |
| 128 | +- Accepted entries are emitted to stdout in NDJSON format. |
0 commit comments