# Dashboard variable sql injection

**URL:** <https://community.grafana.com/t/dashboard-variable-sql-injection/11660>\
**Category:** PostgreSQL\
**Tags:** postgres\
**Created:** [October 30, 2018, 5:51pm UTC](https://community.grafana.com/t/dashboard-variable-sql-injection/11660 "2018-10-30T17:51:16Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![ncpv](https://avatars.discourse-cdn.com/v4/letter/n/ecc23a/32.png) [@ncpv](https://community.grafana.com/u/ncpv)\
**Post date:** [October 30, 2018, 5:51pm UTC](https://community.grafana.com/t/dashboard-variable-sql-injection/11660/1 "2018-10-30T17:51:16Z")

</div>

Grafana **v5.1.2**

My question is about dashboard variables of _Query_ type that pull inforamtion from PostgreSQL database.

Once the variable is created, the dashboard will have a drop-down list that allows users to select the value for variable. This value is then used by SQL query to populate the graph on this dashboard.

I discovered that it is possible to type anything into the drop-down field and this user input gets inserted directly into the SQL query that pulls data for graph. For example, assume this is a query:

`SELECT value, date as "time" FROM values WHERE value_category = '$Value' ORDER BY id`

This allows users to insert anything they want in place of _$Value_ and beyond. And the impact will be only limited by the permissions of the account that is used by the data source to connect to the PostgreSQL server.

This is a flaw on my opinion. This allows users with _view_ privilege to alter the SQL query. This is basically an SQL injection “feature”.

Is there any way to prevent it? For example, create a parameterized SQL query or prohibit end users from typing arbitrary data into variable selection field?

---

<div class="post-metadata">

**Author:** ![jangaraj](https://sea2.discourse-cdn.com/grafana/user_avatar/community.grafana.com/jangaraj/32/39197_2.png) [@jangaraj](https://community.grafana.com/u/jangaraj)\
**Post date:** [October 30, 2018, 11:06pm UTC](https://community.grafana.com/t/dashboard-variable-sql-injection/11660/2 "2018-10-30T23:06:10Z")

</div>

There is Warning in the datasource configuration:

 ![image](https://us1.discourse-cdn.com/grafana/original/2X/3/300663c97a46bf09f9aa2f81d03936d80113a4aa.png)

You have to configure permissions on the DB level and/or Grafana organization level. Maybe yiu will sort mentioned “SQL injection” somehow, but users will have option to tamper SQL queries in the browser console or they can query Grafana datasources directly.
