mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Avoid using serialised preferences for security purposes. This might break existing preferences.
This commit is contained in:
parent
66019fdbbf
commit
40d94e7a62
@ -59,6 +59,7 @@ class Preference extends Model
|
|||||||
*/
|
*/
|
||||||
public function getDataAttribute($value)
|
public function getDataAttribute($value)
|
||||||
{
|
{
|
||||||
|
$result = null;
|
||||||
try {
|
try {
|
||||||
$data = Crypt::decrypt($value);
|
$data = Crypt::decrypt($value);
|
||||||
} catch (DecryptException $e) {
|
} catch (DecryptException $e) {
|
||||||
@ -67,17 +68,17 @@ class Preference extends Model
|
|||||||
sprintf('Could not decrypt preference #%d. If this error persists, please run "php artisan cache:clear" on the command line.', $this->id)
|
sprintf('Could not decrypt preference #%d. If this error persists, please run "php artisan cache:clear" on the command line.', $this->id)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
$unserialized = false;
|
$serialized = true;
|
||||||
try {
|
try {
|
||||||
$unserialized = unserialize($data);
|
unserialize($data);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
// don't care, assume is false.
|
$serialized = false;
|
||||||
}
|
}
|
||||||
if (!(false === $unserialized)) {
|
if (!$serialized) {
|
||||||
return $unserialized;
|
$result = json_decode($data, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
return json_decode($data, true);
|
return $result;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -89,7 +90,7 @@ class Preference extends Model
|
|||||||
*/
|
*/
|
||||||
public function setDataAttribute($value)
|
public function setDataAttribute($value)
|
||||||
{
|
{
|
||||||
$this->attributes['data'] = Crypt::encrypt(serialize($value));
|
$this->attributes['data'] = Crypt::encrypt(json_encode($value));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -27,6 +27,7 @@ use Exception;
|
|||||||
use FireflyIII\Models\Preference;
|
use FireflyIII\Models\Preference;
|
||||||
use FireflyIII\User;
|
use FireflyIII\User;
|
||||||
use Illuminate\Support\Collection;
|
use Illuminate\Support\Collection;
|
||||||
|
use Log;
|
||||||
use Session;
|
use Session;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -134,6 +135,14 @@ class Preferences
|
|||||||
}
|
}
|
||||||
|
|
||||||
$preference = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data']);
|
$preference = Preference::where('user_id', $user->id)->where('name', $name)->first(['id', 'name', 'data']);
|
||||||
|
if (null !== $preference && null === $preference->data) {
|
||||||
|
try {
|
||||||
|
$preference->delete();
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Log::debug(sprintf('Could not delete preference #%d', $preference->id));
|
||||||
|
}
|
||||||
|
$preference = false;
|
||||||
|
}
|
||||||
|
|
||||||
if ($preference) {
|
if ($preference) {
|
||||||
Cache::forever($fullName, $preference);
|
Cache::forever($fullName, $preference);
|
||||||
@ -156,7 +165,7 @@ class Preferences
|
|||||||
{
|
{
|
||||||
$lastActivity = microtime();
|
$lastActivity = microtime();
|
||||||
$preference = $this->get('lastActivity', microtime());
|
$preference = $this->get('lastActivity', microtime());
|
||||||
if (null !== $preference) {
|
if (null !== $preference && null !== $preference->data) {
|
||||||
$lastActivity = $preference->data;
|
$lastActivity = $preference->data;
|
||||||
}
|
}
|
||||||
if (is_array($lastActivity)) {
|
if (is_array($lastActivity)) {
|
||||||
|
Loading…
Reference in New Issue
Block a user