Most data leaks are caused by quark in ->orWhere()
#48339
Replies: 4 comments 4 replies
-
To explain: do not allow any Laravel could disable or throw exception whenever orWhere is used in root level of query so that the following code would fail:
And would have be rewritten as:
Although i think this is very drastic because it will reduce usability/simplicity. It will make it very explicit when using OR's in queries it is always done with consious thinking |
Beta Was this translation helpful? Give feedback.
-
Blocking root level Imagine a $relatedProducts = $product
->relatedProducts()
->orWhereNull('product_id')
->get(); I think your use case is best solved by just creating a test and/or a custom phpstan rule that blocks it. |
Beta Was this translation helpful? Give feedback.
-
@joelharkes thanks for this heads up. A better solution would be to not allow orWhere method on the Relation. \Illuminate\Database\Eloquent\Relations\Relation::__call
or using a macro on Relation named orWhere that throws Exception (valid only for one function at a time)
but all orWhere functions are calling |
Beta Was this translation helpful? Give feedback.
-
I think at root level no longer orWhere. But in that case I would add a way to disable that, because not every developer is a changeling named Odo. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
For some context: we are building a multi tenant application in Laravel using a single database because we need to do operations over all our clients this seemed for us the best and simplest model. We deploy regularly (now once a week). In the last 2 months we had (almost) 2 data leaks because of a single 'bug/quark' in Laravel:
As you might think: this code does not get all users of organization with either role x or age 10.
No, this wil get 'users from $organization with role X or ANY user of all organizations with age 10.
As you can see data can easily be leaked this way.
To 'fix' this code a Laravel developer must write it so:
We are at a loss:
orWhere()
are never happening at the root level of a query.My question is: are no other companies using the Laravel stack dealing with this exact same problem?
And secondly to plead: can we please fix this quark in the next major Laravel release. My suggestion would by that everything after the relationship:
$organization->users()
part is al done automatically in a sub-where statement so that:Translates to:
instead of now:
14 votes ·
Beta Was this translation helpful? Give feedback.
All reactions