Skip to content

Fix crash on nested/grouped multipart file fields in HMAC signing and forwarding - #186

Open
morcen wants to merge 1 commit into
mainfrom
fix/issue-173-nested-multipart-hmac
Open

Fix crash on nested/grouped multipart file fields in HMAC signing and forwarding#186
morcen wants to merge 1 commit into
mainfrom
fix/issue-173-nested-multipart-hmac

Conversation

@morcen

@morcen morcen commented Jul 28, 2026

Copy link
Copy Markdown
Owner

What was broken

HasHmacAuth::resolveHmacSignedBody() and PassageService::callService() both assumed Request::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 like docs[0][avatar] produces ['docs' => [0 => ['avatar' => UploadedFile]]]. When either code path iterated one level into that structure, it found an array instead of an UploadedFile and crashed with an uncaught Error: Call to a member function getClientOriginalName() on array (or the equivalent in PassageService), turning an ordinary client request into a 500 instead of proxying it.

What changed

  • Added Morcen\Passage\Support\NestedFileResolver::flatten(), a small shared helper that recursively walks the structure returned by allFiles() to whatever depth it actually is, producing a flat map of bracket-notation keys (e.g. docs[0][avatar]) to their leaf UploadedFile.
  • 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.
  • Added Pest tests covering a nested/grouped file field (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 — clean
  • composer test — 158 passed (427 assertions)

Fixes #173

…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.
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.

HasHmacAuth::resolveHmacSignedBody() crashes with a fatal error on nested/grouped multipart file fields

1 participant