fix: mass-assignment on update: - #300
Merged
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Root cause: save()-as-update and update(array $attributes) only applied the $creatable whitelist filter if (!empty($this->creatable)) — so any model that never declared $creatable (legal, since only insert enforced it) would persist every dirty attribute unfiltered on update, including attacker-supplied keys from update($request->all()).
Fix (InteractsWithModelQueryProcessing.php):
Extracted the insert-path's throw into a shared assertCreatableIsDefined(), now called on both save()'s update branch and update() — a model must declare $creatable to be persisted at all, insert or update, matching the guarantee that already existed for insert.
Made the $creatable intersect on the dirty-attribute diff unconditional (previously skipped when $creatable was empty).
update() now also filters the incoming $attributes array against $creatable before ever calling setAttribute() — so non-whitelisted keys (e.g. id, role) never even land on the in-memory model, not just get dropped at persistence time.
Left fill() and model hydration (Builder.php row-loading, Model::__construct()) completely untouched — those load full DB rows including PK/timestamps and would break if guarded the same way. The vulnerability was specifically in the two request-facing write paths, not in hydration.