Benchmark: grafana PR 106778 - #15
celmis-codereviewer wants to merge 12 commits into
Conversation
Co-authored-by: Sonia Augilar <sonia.aguilar@grafana.com>
…e-ruler-from-alert-list-view2
…on functionality - Introduced user permission grants for alerting actions in tests. - Added tests for rendering the More button with action menu options. - Verified that each rule has its own action buttons and handles permissions correctly. - Ensured the edit button is not rendered when user lacks edit permissions. - Confirmed the correct menu actions are displayed when the More button is clicked.
celmis-codereviewer
left a comment
There was a problem hiding this comment.
✅ APPROVED — no blocking findings
Full findings and scope are in the review summary comment on this pull request — one persistent comment, updated in place on every run.
celmis-codereviewer
left a comment
There was a problem hiding this comment.
❌ CHANGES REQUESTED — blocking findings
Full findings and scope are in the review summary comment on this pull request — one persistent comment, updated in place on every run.
|
|
||
| // For Grafana-managed rules, check folder permissions | ||
| const rulesPermissions = getRulesPermissions('grafana'); | ||
| const canEditGrafanaRules = ctx.hasPermissionInMetadata(rulesPermissions.update, folder); |
There was a problem hiding this comment.
Why: ctx is not defined on line 369 of useAbilities.ts; referencing ctx.hasPermissionInMetadata when folder is loaded throws a ReferenceError at runtime.
🔴 ReferenceError: ctx is not defined in useIsGrafanaPromRuleEditable
Inside useIsGrafanaPromRuleEditable, ctx is referenced on lines 369 and 370 (ctx.hasPermissionInMetadata(...)), but ctx is neither imported nor declared anywhere in useAbilities.ts or within the hook scope. When a rule and its folder are successfully loaded, executing this hook will throw an unhandled ReferenceError: ctx is not defined.
| const canEditGrafanaRules = ctx.hasPermissionInMetadata(rulesPermissions.update, folder); | |
| const rulesPermissions = getRulesPermissions('grafana'); | |
| const canEditGrafanaRules = contextSrv.hasPermissionInMetadata(rulesPermissions.update, folder); | |
| const canRemoveGrafanaRules = contextSrv.hasPermissionInMetadata(rulesPermissions.delete, folder); |
agent: defect · rule: defect.reference-error · confidence: 1.00
|
|
||
| // For Grafana-managed rules, check folder permissions | ||
| const rulesPermissions = getRulesPermissions('grafana'); | ||
| const canEditGrafanaRules = ctx.hasPermissionInMetadata(rulesPermissions.update, folder); |
There was a problem hiding this comment.
Why: Line 369 references an undeclared identifier ctx when evaluating folder permissions for Grafana alert rules, throwing an unhandled ReferenceError at runtime when the hook executes and causing component crashes / denial of service during permission checks.
🟠 ReferenceError due to undeclared ctx in permission check hook
In useIsGrafanaPromRuleEditable, line 369 calls ctx.hasPermissionInMetadata(...). However, ctx is neither imported, defined in the module scope, nor retrieved via a context hook (such as useGrafanaContext or useAccessControl). When a user views Grafana alert rules, attempting to render or evaluate rule edit/delete permissions will throw an unhandled ReferenceError: ctx is not defined, crashing the component and preventing proper permission checks.
| const canEditGrafanaRules = ctx.hasPermissionInMetadata(rulesPermissions.update, folder); | |
| const { context: ctx } = useGrafana(); | |
| const canEditGrafanaRules = ctx.hasPermissionInMetadata(rulesPermissions.update, folder); | |
| const canRemoveGrafanaRules = ctx.hasPermissionInMetadata(rulesPermissions.delete, folder); |
agent: security · rule: sec.cwe-862 · confidence: 0.95
| ); | ||
| } | ||
|
|
||
| {promResponse.data.groups.at(0)?.rules.map((promRule) => { |
There was a problem hiding this comment.
Why: promResponse.data.groups.at(0)?.rules evaluates to undefined when groups is empty on line 68 of GrafanaGroupLoader.tsx; calling .map on it throws a TypeError at runtime.
🟠 TypeError when mapping over rules of an empty group
On line 68, promResponse.data.groups.at(0)?.rules.map(...) uses optional chaining on at(0). If groups is empty ([]), at(0) returns undefined, causing at(0)?.rules to evaluate to undefined. Because optional chaining is missing before .map, JavaScript attempts to call undefined.map(...), throwing an unhandled TypeError: Cannot read properties of undefined (reading 'map').
| {promResponse.data.groups.at(0)?.rules.map((promRule) => { | |
| {(promResponse.data.groups.at(0)?.rules ?? []).map((promRule) => { |
agent: defect · rule: defect.null-dereference · confidence: 0.95
🤖 Code Review for PR #15⚙ ADJUSTED — graph context partial (13 of 14 changed files): 1 of 14 changed files have no symbols in the index; 1 of them is not in that checkout at all (public/app/features/alerting/unified/rule-list/GrafanaRuleLoader.tsx) — this PR's base is older than the indexed revision, so those files were renamed or deleted before it and no re-index can bring them back; there is nothing to fix. ❌ CHANGES REQUESTED — blocking findings Findings
Scope
Performance
Powered by Code Analyzer · context: tree-sitter graph + cve, structural, contract, security, defect |
Benchmark reproduction of grafana#106778