Repository navigation
Commit 8b8a88f
authored
fix(observability): mask ?apikey= in the http.url span attribute (#1790)
## Bug
When OTLP tracing is enabled (`observability.tracing.enabled`),
`TracingManager.HTTPMiddleware` wraps the whole REST API router and
records `r.URL.String()` as the `http.url` attribute of every span. That
string includes the query.
`?apikey=` is an accepted credential (`resolveAuth`). The Web UI's SSE
stream connects to `/events?apikey=<admin key>`
(`frontend/src/services/api.ts`), and the tray sends the admin key the
same way. So the admin API key lands in span attributes and is exported
to the configured collector (Jaeger, Tempo, a shared OTel pipeline).
Anyone who can read traces can then drive the REST API as admin.
`httpLoggingMiddleware` already masks the same query before it writes to
http.log (SEC-01). The tracing middleware sees the same requests and was
missed.
## Trigger
Enable tracing, then open the Web UI. Every SSE (re)connect is a `GET
/events?apikey=…` request, and each sampled one exports the key.
## Fix
Build `http.url` from a copy of the request URL whose `RawQuery` has
been passed through `oauth.LogSafeQueryString`, the same renderer
http.log uses. The path and the non-secret parameters stay as they were.
`http.target` and the span name already use only the path.
`internal/oauth` does not import `internal/observability`, so the new
import adds no cycle.
## Test
`TestHTTPMiddleware_MasksAPIKeyInSpanURL` sends `/events?apikey=<64-hex
key>&limit=5` through the middleware with an in-memory span recorder.
The recorded `http.url` must not contain the key, and must keep
`/events?` and `limit=5`.
## Commands run
- `CGO_ENABLED=0 go test -count=1 -run 'Test'
./internal/observability/`: ok
- On current `main`, and again with the fix reverted, the new test fails
with `http.url carries the API key: "/events?apikey=3f9a…b5c6&limit=5"`.
- `go vet ./internal/observability/`: ok1 parent 9ac8a99 commit 8b8a88f
2 files changed
Lines changed: 68 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
| 7 | + | |
7 | 8 | | |
8 | 9 | | |
9 | 10 | | |
| |||
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| 19 | + | |
| 20 | + | |
18 | 21 | | |
19 | 22 | | |
20 | 23 | | |
| |||
169 | 172 | | |
170 | 173 | | |
171 | 174 | | |
172 | | - | |
| 175 | + | |
173 | 176 | | |
174 | 177 | | |
175 | 178 | | |
| |||
200 | 203 | | |
201 | 204 | | |
202 | 205 | | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
203 | 216 | | |
204 | 217 | | |
205 | 218 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
0 commit comments