How to prevent accidental data leak
Filament uses model policies to prevent unauthorized access.
I have had situations where I forgot to add model policies, especially for existing models and I add the resource to Filament.
Maybe the solution is a Laravel thing rather than Filament, but how can I prevent such error?
More specifically: How can I make Filament blow up (throw Exception or something) when a resource is accessed and the underlying model does not have any policy class?
5 Replies
You could build a trait? Then apply this to the BaseModel override which Checks for a policy with say:
and in your baseModel
I'm wondering if a test would be better. That way you won't have to worry about it breaking the app if it makes it to production without a policy since the test could disable the deploy.
That's a good shout, you could send an email alert instead of throwing an exception.
But a test suite would be better
Yeah I mean the whole point is my fault in forgetting to consider auth for newly added resources
If I didn't forget that, I definitely would have added policy and then perhaps a test.
I was thinking about something that drop-kicks me whenever I forget something like that; similar to what
Model::preventLazyLoading()
when one forgets to eager-load relationshipsBut you could create a test, to ensure all models have policies and fail if they don't? It'll also allow models which don't need policies as you can exclude them?