-
Notifications
You must be signed in to change notification settings - Fork 0
fix(serializer): require explicit opt-in to decode closure payloads #7
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| # Changelog | ||
|
|
||
| ## 0.2.0 | ||
|
|
||
| ### Breaking | ||
|
|
||
| - `Serializer::unserialize()` refuses closure payloads (data produced by `Serializer::serialize()` for a value containing a closure) and throws `Utopia\Async\Exception\Serialization`. Decoding a closure payload through `opis/closure` rebuilds the objects inside it by reflection, which the `allowed_classes` option does not govern, so it no longer happens by default. Plain payloads keep the `allowed_classes => false` default. | ||
|
|
||
| ### Added | ||
|
|
||
| - `Serializer::unserializeTrusted()` decodes closure payloads for data from a trusted channel (this process or its own workers). The Swoole process pool uses it for its own worker channel. | ||
|
|
||
| ## 0.1.1 | ||
|
|
||
| - `Promise::all()` records the error before signalling its channel. | ||
| - The parallel pool skips SIGKILL for workers that are already reaped on shutdown. | ||
| - PHPStan level-max fixes in the Timer and Promise adapters. | ||
|
|
||
| ## 0.1.0 | ||
|
|
||
| - Initial release. |
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| # Upgrade Guide | ||
|
|
||
| ## 0.1.x to 0.2.0 | ||
|
|
||
| ### Closure payloads need trusted decoding | ||
|
|
||
| `Serializer::unserialize()` no longer decodes closure payloads. It throws `Utopia\Async\Exception\Serialization` for them, because `opis/closure` rebuilds the objects inside such a payload by reflection, outside the control of the `allowed_classes` option. | ||
|
|
||
| `Serialization` extends `Utopia\Async\Exception`, not `\RuntimeException`: code that catches only `\RuntimeException` around `Serializer::unserialize()` must also catch `Serialization` (or `\Exception`) to handle a refused payload. | ||
|
|
||
| If you pass closures between processes you control, switch those call sites to `Serializer::unserializeTrusted()`: | ||
|
|
||
| ```php | ||
| // 0.1.x | ||
| $task = Serializer::unserialize($message); | ||
|
|
||
| // 0.2.0 | ||
| $task = Serializer::unserializeTrusted($message); | ||
| ``` | ||
|
|
||
| Keep `Serializer::unserialize()` for everything that does not need closures, and never pass data from users, caches, queues or other shared storage to `Serializer::unserializeTrusted()`. | ||
|
|
||
| `Serializer::unserializeTrusted()` accepts the same `$options` and still applies `allowed_classes => false` to plain payloads. |
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| <?php | ||
|
|
||
| namespace Utopia\Tests\Unit; | ||
|
|
||
| final class SerializerProbe | ||
| { | ||
| public static int $restored = 0; | ||
|
|
||
| public string $value = 'probe'; | ||
|
|
||
| /** | ||
| * @return array{value: string} | ||
| */ | ||
| public function __serialize(): array | ||
| { | ||
| return ['value' => $this->value]; | ||
| } | ||
|
|
||
| /** | ||
| * @param array{value: string} $data | ||
| */ | ||
| public function __unserialize(array $data): void | ||
| { | ||
| self::$restored++; | ||
| $this->value = $data['value']; | ||
| } | ||
| } |
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
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.