Plugins: Only render plugin metadata links that point to external http(s) sites #1057
All Vouch review confidence checks passed
Residual risk 0.30 = Change Risk (0.57) × (1 − Review Confidence (0.47)).
Review depth and reviewer attention state are adequate.
Model 1 · Change Risk (XGBoost)
Score: 0.57 · 650 lines diff across 8 files
Model 2 · Review Depth (DistilBERT)
Depth Score: 0.02 · 1 substantive comment(s)
Model 3 · Review Timing & Attention
Session adequacy: 100% · Reviewer familiarity: 35%
Bedrock Claude 3 · Risk Narration
(disconnected)
Groq Risk Narration
AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
Model 1 · Change Risk Attribution
SHAP Weights
Diff Size
diff_size
0.388
Shallow Review Depth
shallow_review_depth
0.344
Ai Authored
ai_authored
0.050
Real PR Conversation Timeline
1 comments
"Review active on #1057"
general
weight: 0.35
cursor[bot]
<!-- CURSOR_AGENT_PR_BODY_BEGIN -->
What is this feature?
Plugin-supplied links are now validated before they are rendered as clickable links. A link is rendered only if it is an absolute
http/httpsURL whose host is not this Grafana server. Any other link is dropped. This covers:DataSourceTypeCard, which uses the first entry ofplugin.jsoninfo.links).PluginDetailsPanel).A new shared helper,
getExternalPluginLinkUrlinpublic/app/features/plugins/pluginLinks.ts, does the validation:textUtil.sanitizeUrlfirst, becauseLinkButtonandTextLinkcall it on theirhref. This means entity-encoded, whitespace-prefixed or control-character values are checked in the exact form the anchor will get. Any value that sanitizing would rewrite again is rejected.new URL()and no base. That way, relative paths (/logout,/grafana/profile/switch-org/2) and malformed values are rejected instead of being resolved against the current page.http:orhttps:and a non-empty hostname, and it rejects URLs that contain userinfo.window.location.hostnameor the hostname ofconfig.appUrl. The comparison ignores case and trailing dots and ignores the port, because session cookies are not port-scoped. Since it compares the parser's hostname, percent-encoded and IDNA-mapped forms of the host are caught too.DataSourceTypeCardnow addsutm_source=grafana_add_dsthroughURL.searchParamsrather than string concatenation, and the resulting URL is validated again.Why do we need this feature?
Previously, the add data source page rendered the plugin's first
info.linksURL as-is with?utm_source=...appended. The only check wassanitizeUrl, which blocks script schemes only. The details panel did the same with the other plugin metadata URLs. A plugin whose link was a same-origin path such as/logoutor/profile/switch-org/2, or a protocol-relative or absolute URL on the Grafana host, made the user's browser send an authenticated GET to Grafana when the user clicked the link. That ended the user's session or switched their active organization.Who is this feature for?
Everyone who browses the add data source page or the plugin catalog.
Which issue(s) does this PR fix?:
Fixes the "Session logout through plugin documentation link on add data source" finding. https://github.com/shaw-andy/grafana/pull/1055 contains the tests that prove the fix. They fail on
mainand pass with this change. That PR is intentionally not part of this branch.Other call sites
I searched
public/andpackages/for other places that render plugin metadata URLs (info.links,details.links,repositoryUrl,licenseUrl,documentationUrl,raiseAnIssueUrl,sponsorshipUrl).DataSourceTypeCardandPluginDetailsPanelare the only components that render them as hrefs, and both are fixed here. No other call sites remain open.Tests run
DataSourceTypeCard.test.tsxandPluginDetailsPanel.test.tsx):- Without the fix: 35 failed, 17 passed. Every failure was an anchor that resolved to
http://localhost/logout...or/profile/switch-org/2on the Grafana host.- With the fix: 52 passed, 0 failed.
yarn jest --no-watch public/app/features/datasources public/app/features/plugins/admin→ 46 suites, 556 tests passed.LOCALHOST.,http:/localhost,http:localhost, backslash forms, a percent-encoded host, an IDNA-mapped host, userinfo before and after the host,https://…, a leading U+2000, an embedded newline in the scheme, theconfig.appUrlhost, bare relative paths,?x/#x,mailto:,ftp:,javascript:. External hosts such ashttps://evil.com\@localhostwere confirmed to still resolve to the external host.yarn typecheckandyarn tsc --noEmit: pass.eslintandprettier --checkon the changed files: pass.Special notes for your reviewer:
A plugin link that uses a relative path or points to the Grafana host is now hidden instead of rendered. External
http(s)links are unchanged, and the existing tests still match their exact href strings.Please check that:
<!-- CURSOR_AGENT_PR_BODY_END -->
<div><a href="https://cursor.com/agents/bc-b59b8ce9-8a83-4615-8616-b0199294e22a?cursor_ref=pr_footer&cursor_cta=open_in_web"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-web-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-web-light.png"><img alt="Open in Web" width="114" height="28" src="https://cursor.com/assets/images/open-in-web-dark.png"></picture></a> <a href="https://cursor.com/background-agent?bcId=bc-b59b8ce9-8a83-4615-8616-b0199294e22a&cursor_ref=pr_footer&cursor_cta=open_in_cursor"><picture><source media="(prefers-color-scheme: dark)" srcset="https://cursor.com/assets/images/open-in-cursor-dark.png"><source media="(prefers-color-scheme: light)" srcset="https://cursor.com/assets/images/open-in-cursor-light.png"><img alt="Open in Cursor" width="131" height="28" src="https://cursor.com/assets/images/open-in-cursor-dark.png"></picture></a> </div>
<!-- CURSOR_SUMMARY -->
---
<!-- /CURSOR_SUMMARY -->