← Back to Pull requests

Plugins: Only render plugin metadata links that point to external http(s) sites #1057

Open
unknown opened this pull request with 650 lines diff across 8 files
View on GitHub
unknown unknown commented on Nov 30, 2026 14:29 UTC
Author

<!-- 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/https URL whose host is not this Grafana server. Any other link is dropped. This covers:

  • The Learn more button on the add data source page (DataSourceTypeCard, which uses the first entry of plugin.json info.links).

  • The repository, raise-an-issue, license, documentation and sponsorship buttons, plus the custom links, in the plugin catalog details panel (PluginDetailsPanel).
  • A new shared helper, getExternalPluginLinkUrl in public/app/features/plugins/pluginLinks.ts, does the validation:

  • It runs textUtil.sanitizeUrl first, because LinkButton and TextLink call it on their href. 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.

  • It parses the result with 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.

  • It requires http: or https: and a non-empty hostname, and it rejects URLs that contain userinfo.

  • It rejects any URL whose parsed hostname matches window.location.hostname or the hostname of config.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.

  • DataSourceTypeCard now adds utm_source=grafana_add_ds through URL.searchParams rather 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.links URL as-is with ?utm_source=... appended. The only check was sanitizeUrl, 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 /logout or /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 main and pass with this change. That PR is intentionally not part of this branch.

    Other call sites

    I searched public/ and packages/ for other places that render plugin metadata URLs (info.links, details.links, repositoryUrl, licenseUrl, documentationUrl, raiseAnIssueUrl, sponsorshipUrl). DataSourceTypeCard and PluginDetailsPanel are the only components that render them as hrefs, and both are fixed here. No other call sites remain open.

    Tests run

  • Tests from https://github.com/shaw-andy/grafana/pull/1055 (DataSourceTypeCard.test.tsx and PluginDetailsPanel.test.tsx):

  • - Without the fix: 35 failed, 17 passed. Every failure was an anchor that resolved to http://localhost/logout... or /profile/switch-org/2 on the Grafana host.
    - With the fix: 52 passed, 0 failed.
  • Existing tests for the changed code, on this branch (fix only): yarn jest --no-watch public/app/features/datasources public/app/features/plugins/admin → 46 suites, 556 tests passed.

  • A throwaway test (not committed) that retried the technique with 24 more variants, all rejected: different port on the same host, LOCALHOST., http:/localhost, http:localhost, backslash forms, a percent-encoded host, an IDNA-mapped host, userinfo before and after the host, &#104;ttps://…, a leading U+2000, an embedded newline in the scheme, the config.appUrl host, bare relative paths, ?x/#x, mailto:, ftp:, javascript:. External hosts such as https://evil.com\@localhost were confirmed to still resolve to the external host.

  • yarn typecheck and yarn tsc --noEmit: pass.

  • eslint and prettier --check on 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:

  • It works as expected from a user's perspective.

  • If this is a pre-GA feature, it is behind a feature toggle.

  • The docs are updated, and if this is a notable improvement, it's added to our What's New doc.

  • <!-- 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>&nbsp;<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>&nbsp;</div>

    <!-- CURSOR_SUMMARY -->
    ---

    [!NOTE]

    Medium Risk

    Security-focused URL validation with intentional behavior change (some plugin links may be hidden), but no auth or server logic changes and legitimate external links remain unchanged.

    > <sup>Reviewed by Cursor Bugbot for commit 1c879bc042f5799e4a017501b3c90d5871217d81. Bugbot is set up for automated code reviews on this repo. Configure here.</sup>

    <!-- /CURSOR_SUMMARY -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: cursor[bot] Review duration: 20m
    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
    0.57
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.02 · 1 substantive comment(s)
    0.02
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    46%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    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
    Reviewers
    Assignees
    Unassigned
    Labels
    risk: low confidence: 46.7% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 57% (MEDIUM) · Higher = larger blast radius
    57%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 46.7% · Lower = rushed or shallow review
    46.7%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 30.4% · Safe to merge
    30.4%