Commit b084eae
# Backport
This will backport the following commits from `main` to `9.4`:
- [[RAC] Disable _source for Analyzer alert stats query
(#285953)](#285953)
<!--- Backport version: 9.6.6 -->
### Questions ?
Please refer to the [Backport tool
documentation](https://github.com/sorenlouv/backport)
<!--BACKPORT [{"author":{"name":"Gerard
Soldevila","email":"gerard.soldevila@elastic.co"},"sourceCommit":{"committedDate":"2026-08-25T10:15:42Z","message":"[RAC]
Disable _source for Analyzer alert stats query (#285953)\n\n##
Summary\n\nThe Security Analyzer prevalence query
(`StatsQuery.alertStatsQuery`)\nfetches up to `size: 5000` alert hits
but only consumes aggregations and\nhit ids — it never reads `_source`.
Because Elasticsearch defaults\n`_source` to `true`, the response could
exceed\n`elasticsearch.maxResponseSize`, and Kibana aborted the
request.\n\nThis sets `_source: false` on that one query. No default is
changed, so\nevery other `find()` caller keeps its current behavior —
the blast\nradius is limited to the Analyzer path.\n\nBecause
`AlertsClient.find` runs a per-hit authorization check on every\nresult,
disabling `_source` would otherwise leave `ensureAllAuthorized`\nunable
to read the rule type id and consumer from the hits.
So\n`ensureAllAuthorized` now reads those from the `fields` API
(already\nrequested by `searchAlerts`), falling back to `_source` for
`mget`\nresponses (which don't support `fields`). The same change:\n\n-
Replaces the broken `reduce` — which rebuilt `ownersAndRuleTypeIds`
as\na single-element array each iteration, so only the **last** hit was
ever\nauthorized — with a `forEach` that collects every hit id
and\ndeduplicates `(ruleTypeId, consumer)` pairs before
calling\n`ensureAuthorized`.\n- Hardens `isValidAlert`'s `fields` access
with optional chaining, since\nwith `_source: false` validation reads
from `fields`.\n\n## Why not default `_source: false` globally\n\nAn
earlier iteration flipped the `searchAlerts` default to `false`
and\nmade each caller opt back in. That required touching ~7 consumers
across\nsecurity/o11y/apm and risked silently breaking any `find()` /
HTTP\n`/find` caller we didn't enumerate. Keeping the default as-is and
opting\n**out** only where we know `_source` is unused is smaller,
safer, and\nbackport-friendly.\n\n## Test plan\n\n- [ ] `AlertsClient`
find/get/update/bulkUpdate unit tests pass (per-hit\nauthz now covers
every unique rule type + consumer pair; dedup verified)\n- [ ]
`StatsQuery` unit test asserts the alert query runs with
`_source:\nfalse`\n- [ ] Analyzer prevalence (`resolver/tree` with
`includeHits: true`) no\nlonger returns oversized
responses\n\nCo-authored-by: Cursor
<cursoragent@cursor.com>","sha":"f2748c6aaece272b694d05b66657ad7bd3cbb389","branchLabelMapping":{"^v9.6.0$":"main","^v(\\d+).(\\d+).\\d+$":"$1.$2"}},"sourcePullRequest":{"labels":["Team:Core","release_note:skip","backport:all-open","v9.6.0"],"title":"[RAC]
Disable _source for Analyzer alert stats
query","number":285953,"url":"https://github.com/elastic/kibana/pull/285953","mergeCommit":{"message":"[RAC]
Disable _source for Analyzer alert stats query (#285953)\n\n##
Summary\n\nThe Security Analyzer prevalence query
(`StatsQuery.alertStatsQuery`)\nfetches up to `size: 5000` alert hits
but only consumes aggregations and\nhit ids — it never reads `_source`.
Because Elasticsearch defaults\n`_source` to `true`, the response could
exceed\n`elasticsearch.maxResponseSize`, and Kibana aborted the
request.\n\nThis sets `_source: false` on that one query. No default is
changed, so\nevery other `find()` caller keeps its current behavior —
the blast\nradius is limited to the Analyzer path.\n\nBecause
`AlertsClient.find` runs a per-hit authorization check on every\nresult,
disabling `_source` would otherwise leave `ensureAllAuthorized`\nunable
to read the rule type id and consumer from the hits.
So\n`ensureAllAuthorized` now reads those from the `fields` API
(already\nrequested by `searchAlerts`), falling back to `_source` for
`mget`\nresponses (which don't support `fields`). The same change:\n\n-
Replaces the broken `reduce` — which rebuilt `ownersAndRuleTypeIds`
as\na single-element array each iteration, so only the **last** hit was
ever\nauthorized — with a `forEach` that collects every hit id
and\ndeduplicates `(ruleTypeId, consumer)` pairs before
calling\n`ensureAuthorized`.\n- Hardens `isValidAlert`'s `fields` access
with optional chaining, since\nwith `_source: false` validation reads
from `fields`.\n\n## Why not default `_source: false` globally\n\nAn
earlier iteration flipped the `searchAlerts` default to `false`
and\nmade each caller opt back in. That required touching ~7 consumers
across\nsecurity/o11y/apm and risked silently breaking any `find()` /
HTTP\n`/find` caller we didn't enumerate. Keeping the default as-is and
opting\n**out** only where we know `_source` is unused is smaller,
safer, and\nbackport-friendly.\n\n## Test plan\n\n- [ ] `AlertsClient`
find/get/update/bulkUpdate unit tests pass (per-hit\nauthz now covers
every unique rule type + consumer pair; dedup verified)\n- [ ]
`StatsQuery` unit test asserts the alert query runs with
`_source:\nfalse`\n- [ ] Analyzer prevalence (`resolver/tree` with
`includeHits: true`) no\nlonger returns oversized
responses\n\nCo-authored-by: Cursor
<cursoragent@cursor.com>","sha":"f2748c6aaece272b694d05b66657ad7bd3cbb389"}},"sourceBranch":"main","suggestedTargetBranches":[],"targetPullRequestStates":[{"branch":"main","label":"v9.6.0","branchLabelMappingKey":"^v9.6.0$","isSourceBranch":true,"state":"MERGED","url":"https://github.com/elastic/kibana/pull/285953","number":285953,"mergeCommit":{"message":"[RAC]
Disable _source for Analyzer alert stats query (#285953)\n\n##
Summary\n\nThe Security Analyzer prevalence query
(`StatsQuery.alertStatsQuery`)\nfetches up to `size: 5000` alert hits
but only consumes aggregations and\nhit ids — it never reads `_source`.
Because Elasticsearch defaults\n`_source` to `true`, the response could
exceed\n`elasticsearch.maxResponseSize`, and Kibana aborted the
request.\n\nThis sets `_source: false` on that one query. No default is
changed, so\nevery other `find()` caller keeps its current behavior —
the blast\nradius is limited to the Analyzer path.\n\nBecause
`AlertsClient.find` runs a per-hit authorization check on every\nresult,
disabling `_source` would otherwise leave `ensureAllAuthorized`\nunable
to read the rule type id and consumer from the hits.
So\n`ensureAllAuthorized` now reads those from the `fields` API
(already\nrequested by `searchAlerts`), falling back to `_source` for
`mget`\nresponses (which don't support `fields`). The same change:\n\n-
Replaces the broken `reduce` — which rebuilt `ownersAndRuleTypeIds`
as\na single-element array each iteration, so only the **last** hit was
ever\nauthorized — with a `forEach` that collects every hit id
and\ndeduplicates `(ruleTypeId, consumer)` pairs before
calling\n`ensureAuthorized`.\n- Hardens `isValidAlert`'s `fields` access
with optional chaining, since\nwith `_source: false` validation reads
from `fields`.\n\n## Why not default `_source: false` globally\n\nAn
earlier iteration flipped the `searchAlerts` default to `false`
and\nmade each caller opt back in. That required touching ~7 consumers
across\nsecurity/o11y/apm and risked silently breaking any `find()` /
HTTP\n`/find` caller we didn't enumerate. Keeping the default as-is and
opting\n**out** only where we know `_source` is unused is smaller,
safer, and\nbackport-friendly.\n\n## Test plan\n\n- [ ] `AlertsClient`
find/get/update/bulkUpdate unit tests pass (per-hit\nauthz now covers
every unique rule type + consumer pair; dedup verified)\n- [ ]
`StatsQuery` unit test asserts the alert query runs with
`_source:\nfalse`\n- [ ] Analyzer prevalence (`resolver/tree` with
`includeHits: true`) no\nlonger returns oversized
responses\n\nCo-authored-by: Cursor
<cursoragent@cursor.com>","sha":"f2748c6aaece272b694d05b66657ad7bd3cbb389"}}]}]
BACKPORT-->
Co-authored-by: Gerard Soldevila <gerard.soldevila@elastic.co>
Co-authored-by: Cursor <cursoragent@cursor.com>
1 parent f6a2688 commit b084eae
5 files changed
Lines changed: 159 additions & 39 deletions
File tree
- x-pack
- solutions/security/plugins/security_solution/server/endpoint/routes/resolver/tree/queries
Lines changed: 51 additions & 34 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
99 | | - | |
100 | | - | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
104 | 129 | | |
105 | 130 | | |
106 | 131 | | |
| |||
281 | 306 | | |
282 | 307 | | |
283 | 308 | | |
| 309 | + | |
284 | 310 | | |
285 | 311 | | |
286 | 312 | | |
287 | 313 | | |
288 | 314 | | |
289 | 315 | | |
290 | 316 | | |
291 | | - | |
292 | | - | |
293 | | - | |
294 | | - | |
295 | | - | |
296 | | - | |
297 | | - | |
298 | | - | |
299 | | - | |
300 | | - | |
301 | | - | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
309 | 321 | | |
310 | | - | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
311 | 332 | | |
312 | 333 | | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
| 334 | + | |
| 335 | + | |
| 336 | + | |
| 337 | + | |
| 338 | + | |
| 339 | + | |
| 340 | + | |
| 341 | + | |
325 | 342 | | |
326 | 343 | | |
327 | 344 | | |
| |||
Lines changed: 4 additions & 4 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
213 | 213 | | |
214 | 214 | | |
215 | 215 | | |
216 | | - | |
| 216 | + | |
217 | 217 | | |
218 | 218 | | |
219 | 219 | | |
| |||
226 | 226 | | |
227 | 227 | | |
228 | 228 | | |
229 | | - | |
| 229 | + | |
230 | 230 | | |
231 | 231 | | |
232 | 232 | | |
| |||
410 | 410 | | |
411 | 411 | | |
412 | 412 | | |
413 | | - | |
| 413 | + | |
414 | 414 | | |
415 | 415 | | |
416 | 416 | | |
| |||
423 | 423 | | |
424 | 424 | | |
425 | 425 | | |
426 | | - | |
| 426 | + | |
427 | 427 | | |
428 | 428 | | |
429 | 429 | | |
| |||
Lines changed: 61 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
778 | 778 | | |
779 | 779 | | |
780 | 780 | | |
| 781 | + | |
| 782 | + | |
| 783 | + | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
| 819 | + | |
| 820 | + | |
| 821 | + | |
| 822 | + | |
| 823 | + | |
| 824 | + | |
| 825 | + | |
| 826 | + | |
| 827 | + | |
| 828 | + | |
| 829 | + | |
| 830 | + | |
| 831 | + | |
| 832 | + | |
| 833 | + | |
| 834 | + | |
| 835 | + | |
| 836 | + | |
| 837 | + | |
| 838 | + | |
| 839 | + | |
| 840 | + | |
| 841 | + | |
781 | 842 | | |
Lines changed: 38 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
| 8 | + | |
| 9 | + | |
8 | 10 | | |
9 | 11 | | |
10 | 12 | | |
| |||
83 | 85 | | |
84 | 86 | | |
85 | 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 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
86 | 124 | | |
Lines changed: 5 additions & 1 deletion
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
95 | 95 | | |
96 | 96 | | |
97 | 97 | | |
98 | | - | |
| 98 | + | |
99 | 99 | | |
100 | 100 | | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
101 | 105 | | |
102 | 106 | | |
103 | 107 | | |
| |||
0 commit comments