Repository navigation
Conversation
POST/PUT/PATCH (and DELETE with a body) no longer merge the query string
into the FormRequest input, so credentials in URLs are not accepted and
query keys cannot reach model_fields_set. Safe methods and body-less
DELETE keep reading the query. FormRequest.merge_query = True restores
the {**query, **body} merge for models that want $request->all() parity.
ADR 056 amends ADR 053.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Contributor
Author
|
Closing. Mass assignment is protected by the model (fillable), not by where FormRequest reads its input. ADR 053's query + body merge (Laravel $request->all() parity) stays as is. |
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.
Summary
Since #336 (ADR 053),
Validated[Model]merged query-string params into the input of every request that has a JSON body. That meantPOST /login?password=…validated, so credentials could end up in access logs. It also meantPATCH /profile?role=adminputroleintomodel_fields_set, which is a mass-assignment risk.This PR changes that. ADR 056 amends ADR 053.
POST,PUT,PATCH, and aDELETEwith a body) now validate the body only. Query keys are ignored and never reachmodel_fields_set.GET,HEAD,OPTIONS) and body-lessDELETEbehave as before: they read the query, and merge it with an object body.merge_query: ClassVar[bool] = FalseonFormRequest. Set it toTrueto get the old{**query, **body}merge back (the body wins). The name follows the existingstop_on_first_failuresetting. The ADR explains why this name was picked overquery_on_writeandaccepts_query.prepare_for_validationalready gets the request, so a model can merge the query itself withcls.query_input(validator.request.query_params). A test covers this.nullin a write body, it validates{}and reports itsrequiredrules under its prefix. Withmerge_query = True, or on a safe method, it reads the query as before.request_input(params, body, *, method)now needsmethodas a keyword, so a direct caller can't fall back to the merge by accident."": ["Field required"]),model_typeerrors for non-object bodies, aliases and repeated keys, error shapes, and the OpenAPI query documentation.Tests
POST/PUT/PATCHwith a body plus query params ignore the query by default. This includes/login?password=….merge_query = True, the query is merged and the body wins, on all three methods.model_fields_setno longer contains query keys on writes.DELETEwith a body reads the body only. AGETwith a body still merges the query.POSTgivessearch.termrequired. An opted-in model reads the query and its errors are combined with the other models'. An absent key on aGETreads the query.prepare_for_validation.uv run pytest --ignore=tests/masoniteorm/postgres --cov: 3726 passed, 92.75% coverage.ruffis clean.basedpyrightreports 0 errors.Behaviour change
Apps that relied on query params filling body fields on write methods must set
merge_query = Trueon thoseFormRequests.🤖 Generated with Claude Code