-
-
Notifications
You must be signed in to change notification settings - Fork 180
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’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simple example not working #52
Comments
I sort of figured out the root cause but I'm unsure of a solid solution. This code is in a Laravel environment. Laravel sets the secret key at some point.
In Opis, the secret key sets a security provider static property:
Adding this line at the beginning of my initial code post seems to fix things:
This function nulls out that static variable before closure is created. When the task is unserialized that static property is not set by Laravel. I believe you need to somehow pull the security provider:
And pass this into the child process as well so it can be unserialized with that same security provider. |
This is the problem with Laravel: vendor/laravel/framework/src/Illuminate/Queue/QueueServiceProvider.php:
|
Adding this to the beginning of my original code seems to solve the issue:
|
The solution to this issue is pretty simple public static function encodeTask($task): string
{
if ($task instanceof Closure) {
$task = new SerializableClosure($task);
}
// Check if a security provider was set
if (null !== $securityProvider = SerializableClosure::getSecurityProvider()) {
// Don't worry about it, our closure will be executed locally
SerializableClosure::removeSecurityProvider();
}
$task = base64_encode(serialize($task));
// Restore the security provider, if any
if ($securityProvider !== null) {
SerializableClosure::addSecurityProvider($securityProvider);
}
return $task;
} |
Created pull request: |
I'll close this issue, as the solution seems to be clear: #52 (comment) |
We experienced this issue as well, but did not feel comfortable with unsetting the security provider, so we did some digging. The actual problem seems to be caused by the fact that This same class is also responsible for registering the Opis Security key when it is resolved from the container. The problem, however, is that the Solution (hotfix): we temporarily solved this issue by adding this method to protected function registerOpisSecurityKey()
{
if (Str::startsWith($key = $this->app['config']->get('app.key'), 'base64:')) {
$key = base64_decode(substr($key, 7));
}
SerializableClosure::setSecretKey($key);
} Bonus: An extra complication that we experienced was the fact that things did work when setting |
[2018-11-30 16:47:58] local.DEBUG: The serialized closure is signed. Make sure you use a security provider for both serialization and unserialization.
#0 [internal function]: Opis\Closure\SerializableClosure->unserialize('@{"closure":"a:...')
#1 /home/vagrant/code/vendor/opis/closure/functions.php(34): unserialize('C:32:"Opis\Clos...')
#2 /home/vagrant/code/vendor/spatie/async/src/Runtime/ParentRuntime.php(92): Opis\Closure\unserialize('C:32:"Opis\Clos...')
#3 /home/vagrant/code/vendor/spatie/async/src/Runtime/ChildRuntime.php(23): Spatie\Async\Runtime\ParentRuntime::decodeTask('QzozMjoiT3Bpc1x...')
#4 {main}
The $json variable is blank
The text was updated successfully, but these errors were encountered: