| For the love of god, this is never how GraphQL was intended to be used. The official graphql website is very clear: https://graphql.org/learn/authorization/ > Delegate authorization logic to the business logic layer If you take security or performance debugging seriously, you should never expose database models through APIs directly in a production app. To illustrate, say you have an Employee model: query {
employee(userId=uuid) {
name
salary
}
}
Say you add some hacks on top of this to only allow users to query their own employee data, believing this provides adequate security.The next day, someone creates a Manager object, a relation from employee to Manager, and Manager to employee. Now, without having consider security for a second, you've granted all employees the ability to query each other: query {
employee(userId=uuid) {
name
salary
manager {
employees {
name
salary
}
}
}
}
To say that these problems occur in the wild frequently is an understatement. Since these graphql frameworks also expose introspection capabilities, discovering these exploits can be automated using crawlers. If you write a bug like this, and you will, people will find it.Please, please stop encouraging people to directly expose their databases through an API. |
For example, with postgres: https://stackoverflow.com/questions/49261452/combining-row-l...