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