Skip to content
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

Merged
merged 3 commits into from
Aug 7, 2020

Conversation

taylorotwell
Copy link
Member

This PR will verify column names are actual columns on the database when using guarded with explicit column names.

@GrahamCampbell GrahamCampbell changed the title Verify column names are actual columns when using guarded [6.x] Verify column names are actual columns when using guarded Aug 6, 2020
@taylorotwell taylorotwell merged commit 897d107 into 6.x Aug 7, 2020
@driesvints driesvints deleted the verify-column-name branch August 7, 2020 15:14
@LukeTowers
Copy link
Contributor

@driesvints @GrahamCampbell could you explain the reasoning behind this change? It broke some functionality in @octobercms, see octobercms/library@b779df0

@GrahamCampbell
Copy link
Member

Please see https://blog.laravel.com/security-release-laravel-61834-7232, https://blog.laravel.com/security-release-laravel-61835-7240.

driesvints pushed a commit that referenced this pull request Aug 13, 2020
* verify column names are actual columns when using guarded

* Apply fixes from StyleCI (#33778)

* remove json check
taylorotwell added a commit that referenced this pull request Aug 13, 2020
* 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]>
@shengslogar
Copy link
Contributor

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 isGuardableColumn)?

@LukeTowers
Copy link
Contributor

That's correct @shengslogar, see octobercms/library@b779df0#commitcomment-41334767

fulopattila122 added a commit to vanilophp/cart that referenced this pull request Sep 24, 2020
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants