Prevent modification of cache RPC answers
The cached value should never be changed after being stored by the setter or by a getter. So we make a copy of the value before storing it and return another copy when returned. issue8387 review269601002
This commit is contained in:
1 parent
8250b52aff
commit
b2a44a962c
1 file changed
+3
-2
+3
-2
@@ -1,5 +1,6 @@
|
||||
# This file is part of Tryton. The COPYRIGHT file at the top level of
|
||||
# this repository contains the full copyright notices and license terms.
|
||||
import copy
|
||||
import xmlrpc.client
|
||||
import json
|
||||
import ssl
|
||||
@@ -402,7 +403,7 @@ class _Cache:
|
||||
expire = datetime.timedelta(seconds=expire)
|
||||
if isinstance(expire, datetime.timedelta):
|
||||
expire = datetime.datetime.now() + expire
|
||||
self.store[prefix][key] = (expire, value)
|
||||
self.store[prefix][key] = (expire, copy.deepcopy(value))
|
||||
|
||||
def get(self, prefix, key):
|
||||
now = datetime.datetime.now()
|
||||
@@ -414,7 +415,7 @@ class _Cache:
|
||||
self.store.pop(key)
|
||||
raise KeyError
|
||||
logger.info('(cached) %s %s', prefix, key)
|
||||
return value
|
||||
return copy.deepcopy(value)
|
||||
|
||||
def clear(self, prefix=None):
|
||||
if prefix:
|
||||
|
||||
Reference in new issue
Block a user