Skip to content

Benchmark: grafana PR 106778 - #15

Open
celmis-codereviewer wants to merge 12 commits into
cr-base-106778from
cr-pr-106778
Open

celmis-codereviewer wants to merge 12 commits into
cr-base-106778from
cr-pr-106778

Conversation

@celmis-codereviewer

Copy link
Copy Markdown

Benchmark reproduction of grafana#106778

soniaAguilarPeiron and others added 12 commits June 13, 2025 15:12
Co-authored-by: Sonia Augilar <sonia.aguilar@grafana.com>
…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 celmis-codereviewer left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

celmis-codereviewer

This comment was marked as outdated.

@celmis-codereviewer celmis-codereviewer left a comment

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ 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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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);

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Suggested change
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) => {

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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').

Suggested change
{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

@celmis-codereviewer

Copy link
Copy Markdown
Author

🤖 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

  • 🔴 Critical: 1
  • 🟠 Error: 2

Scope

  • Files changed: 14
  • Lines: +542 / -418

Performance

  • Analysis time: 543.0s · agents: cve, structural, contract, security, defect · tokens: 70,130/24,050

Powered by Code Analyzer · context: tree-sitter graph + cve, structural, contract, security, defect

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants