Fix crash on nested/grouped multipart file fields in HMAC signing and forwarding - #186
Open
morcen wants to merge 1 commit into
Open
Fix crash on nested/grouped multipart file fields in HMAC signing and forwarding#186morcen wants to merge 1 commit into
morcen wants to merge 1 commit into
Conversation
…g and forwarding HasHmacAuth::resolveHmacSignedBody() and PassageService::callService() both assumed request()->allFiles() nests at most one level deep. Symfony's FileBag builds arbitrarily deep nested arrays for bracket-style field names (e.g. docs[0][avatar]), so a request with such a field crashed with an uncaught Error instead of being signed/forwarded normally. Both call sites now flatten the file structure via a shared NestedFileResolver::flatten() helper that walks the structure to whatever depth it actually is, producing bracket-notation keys like "docs[0][avatar]" for each leaf UploadedFile.
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.
What was broken
HasHmacAuth::resolveHmacSignedBody()andPassageService::callService()both assumedRequest::allFiles()nests file uploads at most one level deep (e.g. a plain field or a simple indexed array of files under one key).Symfony's
FileBag::convertFileInformation()actually builds arbitrarily deep nested arrays for bracket-style multipart field names. A field likedocs[0][avatar]produces['docs' => [0 => ['avatar' => UploadedFile]]]. When either code path iterated one level into that structure, it found an array instead of anUploadedFileand crashed with an uncaughtError: Call to a member function getClientOriginalName() on array(or the equivalent inPassageService), turning an ordinary client request into a 500 instead of proxying it.What changed
Morcen\Passage\Support\NestedFileResolver::flatten(), a small shared helper that recursively walks the structure returned byallFiles()to whatever depth it actually is, producing a flat map of bracket-notation keys (e.g.docs[0][avatar]) to their leafUploadedFile.HasHmacAuth::resolveHmacSignedBody()now uses this helper to build the per-file metadata it signs, instead of assuming one level of nesting.PassageService::callService()now uses the same helper when attaching uploaded files to the outbound multipart request, fixing the identical bug that existed there.docs[0][avatar]) for both the HMAC signing path and the outbound forwarding path, alongside the existing flat-file-field tests.Testing
vendor/bin/pint --dirty— cleancomposer test— 158 passed (427 assertions)Fixes #173