Commit f6d9df5
authored
fix: hide HTTP scrape error details (#2332)
## Summary
- return a generic HTTP 500 body instead of exposing exception details
- include a safe hint explaining how to enable better diagnostics
- avoid adding server-side logging by default
- let users explicitly opt into either detailed HTTP responses or
server-side error reporting
- verify the secure default does not expose the exception type or
message
This is the focused replacement for the #2283 portion of #2297.
Fixes #2283
## Implementation plan
1. Make `HttpErrorHandlingPolicy` builder-based and pass the built
policy through the `HTTPServer` builder to the exchange adapter.
Response verbosity and error reporting remain orthogonal choices.
2. Make the default policy return a generic HTTP 500 response with a
short hint to configure server-side error reporting for diagnostic
details. The default must not add a new log entry for the scrape
exception.
3. Let callers configure either axis independently:
- attach a caller-supplied error reporter while keeping the generic
response, so applications and Java agents can route diagnostics to an
appropriate sink; and
- enable an explicitly unsafe debug response mode that includes
exception details in the HTTP body. Avoid “legacy” naming; the API and
docs must make the disclosure risk clear.
4. Preserve the existing logging behavior for failures where the error
response itself cannot be sent or response headers were already
committed, because no useful client response remains possible in those
paths.
5. Add focused tests for the secure default, diagnostic hint,
independent verbosity/reporter configuration, reporter invocation and
isolation, reporter failure handling, and the explicitly unsafe
debug-response mode. Add user documentation for the available policies
and their security tradeoffs, plus the repository’s release-please
changelog entry linking to that documentation.
## Alternatives considered
- **Unconditional server-side logging:** rejected because it replaces
the response disclosure with a new operational regression: one stack
trace per failed scrape, with possible log-ingestion cost and
application-logging side effects for unshaded integrations.
- **Keep the detailed response as the default:** rejected because it
does not remediate #2283 unless every user discovers and enables the
secure mode.
- **Generic response with no diagnostic guidance:** rejected because it
leaves operators with a silent, unexplained HTTP 500 and no discoverable
path to better diagnostics.
- **Hard-code rate limiting or deduplication in the adapter:** deferred
in favor of a reporter abstraction. Correct suppression requires bounded
state, concurrency handling, distinct-failure classification, and
suppressed-count reporting; callers or a later reusable reporter can
implement that policy without coupling it to HTTP response handling.
- **Ambient debug/verbosity configuration:** rejected in favor of an
explicit builder option on `HttpErrorHandlingPolicy`, so re-enabling
unsafe debug responses is deliberate and carries a clear security
warning.
- **Network controls or authentication documentation alone:** rejected
as the primary fix. They remain useful defense in depth but should not
substitute for a safe default response.
## Validation
- `mise run lint:fix`
- `mise run build`
- `./mvnw test -pl prometheus-metrics-exporter-httpserver
-Dcoverage.skip=true -Dcheckstyle.skip=true`
## Release note
Release Please will use this override for the generated changelog and
GitHub release notes after a squash merge:
BEGIN_COMMIT_OVERRIDE
fix(httpserver): make scrape error responses secure and configurable
Scrape failures now return a generic HTTP 500 response by default.
Applications can configure a server-side error reporter or explicitly
enable an unsafe debug response containing exception details. See the
[HTTPServer scrape error handling
documentation](https://github.com/prometheus/client_java/blob/main/docs/content/exporters/httpserver.md#scrape-error-handling).
END_COMMIT_OVERRIDE
---------
Signed-off-by: Gregor Zeitlinger <gregor.zeitlinger@grafana.com>1 parent 63149ae commit f6d9df5
11 files changed
Lines changed: 545 additions & 52 deletions
File tree
- docs
- apidiffs/current_vs_latest
- content/exporters
- integration-tests/it-exporter/it-exporter-test/src/test/java/io/prometheus/metrics/it/exporter/test
- prometheus-metrics-exporter-httpserver/src
- main/java/io/prometheus/metrics/exporter/httpserver
- test/java/io/prometheus/metrics/exporter/httpserver
Lines changed: 20 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
26 | 26 | | |
27 | 27 | | |
28 | 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 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
29 | 77 | | |
30 | 78 | | |
31 | 79 | | |
| |||
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
157 | 157 | | |
158 | 158 | | |
159 | 159 | | |
160 | | - | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
161 | 165 | | |
162 | 166 | | |
163 | 167 | | |
| |||
Lines changed: 11 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
3 | 5 | | |
4 | 6 | | |
5 | 7 | | |
6 | 8 | | |
7 | 9 | | |
8 | 10 | | |
9 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
10 | 21 | | |
Lines changed: 20 additions & 3 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
61 | 61 | | |
62 | 62 | | |
63 | 63 | | |
64 | | - | |
| 64 | + | |
| 65 | + | |
65 | 66 | | |
66 | 67 | | |
67 | 68 | | |
| |||
85 | 86 | | |
86 | 87 | | |
87 | 88 | | |
88 | | - | |
| 89 | + | |
89 | 90 | | |
90 | 91 | | |
91 | 92 | | |
| |||
211 | 212 | | |
212 | 213 | | |
213 | 214 | | |
| 215 | + | |
214 | 216 | | |
215 | 217 | | |
216 | 218 | | |
| |||
295 | 297 | | |
296 | 298 | | |
297 | 299 | | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
| 304 | + | |
| 305 | + | |
| 306 | + | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
298 | 314 | | |
299 | 315 | | |
300 | 316 | | |
| |||
318 | 334 | | |
319 | 335 | | |
320 | 336 | | |
321 | | - | |
| 337 | + | |
| 338 | + | |
322 | 339 | | |
323 | 340 | | |
324 | 341 | | |
| |||
Lines changed: 120 additions & 0 deletions
| 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 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
0 commit comments