Commit 2fec2d2
authored
fix(api): scrub driver errors from the preview endpoint and answer 400, not 500 (#258)
* fix(api): scrub driver errors from the preview endpoint and answer 400, not 500
POST /reports/{name}/preview caught only ConfigurationException. It opens a live
connection and runs SQL, so a bad filter value (say Equals "abc" against an
integer column) surfaced the raw SqlException/PostgresException/OracleException —
which names the host, port and database — as an unhandled 500, and on a host
running in Development the developer exception page renders the whole stack
trace. Every sibling endpoint that touches a source already routes failures
through SchemaProblem (logged server-side, generic to the caller); this one now
does too.
That alone would have turned a second bug into a misleading 502: a code-first
report's name is only checked for non-blank, so "sales.daily" is legal, while a
config store validates its argument against the dynamic-name pattern and throws
for it. ReportPreviewRunner probed the store before deciding the report was
typed, so that ArgumentException escaped as a 500. A name the store cannot hold
is definitively not a dynamic report, so it is now recognised as such and the
endpoint returns the clear 400 it always intended.
The regression test initially passed for the wrong reason - TestApp registers no
config store unless AddDynamicReports is called, so the runner short-circuited
before reaching the name check. Hardened to register a real file-backed store;
it now fails without the guard (502 instead of 400).
* test(api): cover the preview endpoint's driver-error scrubbing
The Sonar gate flagged new_coverage 0%: the two new lines are the catch and its
SchemaProblem return, and nothing exercised them — the existing regression test
takes the name-guard path, which returns 400 before any driver call. So the
security fix itself was untested.
Add a filter translator that fails the way a provider does, with a message naming
the connection target, and assert the response is the scrubbed 502 and carries
neither the host, the database, nor the driver text. Verified to fail without the
catch (the exception escapes with the connection string intact).1 parent a39a140 commit 2fec2d2
5 files changed
Lines changed: 89 additions & 3 deletions
File tree
- docs
- src
- Integrations/NeoReports.AspNetCore
- NeoReports.Core/Preview
- tests/NeoReports.AspNetCore.IntegrationTests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
58 | 58 | | |
59 | 59 | | |
60 | 60 | | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
61 | 69 | | |
62 | 70 | | |
63 | 71 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
245 | 245 | | |
246 | 246 | | |
247 | 247 | | |
248 | | - | |
249 | | - | |
| 248 | + | |
| 249 | + | |
250 | 250 | | |
251 | 251 | | |
252 | | - | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
253 | 256 | | |
254 | 257 | | |
255 | 258 | | |
| |||
Lines changed: 9 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
262 | 262 | | |
263 | 263 | | |
264 | 264 | | |
| 265 | + | |
| 266 | + | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
| 271 | + | |
| 272 | + | |
| 273 | + | |
265 | 274 | | |
266 | 275 | | |
267 | 276 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
51 | 51 | | |
52 | 52 | | |
53 | 53 | | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
54 | 59 | | |
| 60 | + | |
55 | 61 | | |
56 | 62 | | |
57 | 63 | | |
| |||
Lines changed: 60 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 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 | + | |
74 | 118 | | |
75 | 119 | | |
76 | 120 | | |
| |||
329 | 373 | | |
330 | 374 | | |
331 | 375 | | |
| 376 | + | |
| 377 | + | |
| 378 | + | |
| 379 | + | |
| 380 | + | |
| 381 | + | |
| 382 | + | |
| 383 | + | |
| 384 | + | |
| 385 | + | |
| 386 | + | |
| 387 | + | |
| 388 | + | |
| 389 | + | |
| 390 | + | |
| 391 | + | |
0 commit comments