-
Notifications
You must be signed in to change notification settings - Fork 11.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[6.x] Verify column names are actual columns when using guarded #33777
Conversation
@driesvints @GrahamCampbell could you explain the reasoning behind this change? It broke some functionality in @octobercms, see octobercms/library@b779df0 |
* verify column names are actual columns when using guarded * Apply fixes from StyleCI (#33778) * remove json check
* fix casing issue with guarded * block json mass assignment * formatting * add boolean * protect table names and guarded * Apply fixes from StyleCI (#33772) * dont allow mass filling with table names * Apply fixes from StyleCI (#33773) * [6.x] Verify column names are actual columns when using guarded (#33777) * verify column names are actual columns when using guarded * Apply fixes from StyleCI (#33778) * remove json check * Apply fixes from StyleCI (#33857) Co-authored-by: Taylor Otwell <[email protected]> Co-authored-by: Taylor Otwell <[email protected]>
I've used Eloquent mutators/accessors to create virtual model columns in the past, but this change suggests that was never part of intended usage (otherwise we'd need to check for a method name within |
That's correct @shengslogar, see octobercms/library@b779df0#commitcomment-41334767 |
The reason behind is that Laravel 6.18.35 & 7.24.0 introduced a security improvement that prevents from mass assigning non-db fields to an Eloquent model. The implementation is holding a reference to the list of the table fields in the newly introduced `guardableColumns` static property. It gets populated with the fields from the db for the first time a mass assignment happens on a model. In our tests, we add fields to the cart_items table during testing. If we hit the model first with the original amount of fields, the second call - having the new fields in the underlying table - won't repopulate the `guardableColumns` static property - for obvious reasons. However, there's no facility to reset this list, therefore we can't reboot this property of a model within a single run of a PHP process (namely tests). A dirty fix was to move the test with the extended number of columns ahead, thus those columns will be populated. Cheap fix, but actually in a real application it's not the case, it's only causing problems with testing. Thus, we get away with it. We have more important stuff to take care of ;) - See: https://blog.laravel.com/security-release-laravel-61835-7240 - See: laravel/framework#33777
This PR will verify column names are actual columns on the database when using guarded with explicit column names.