8
8
from __future__ import absolute_import
9
9
10
10
import os
11
+ import warnings
11
12
12
13
from . import http , multipart , utils , exceptions , encoding
13
14
@@ -2126,6 +2127,14 @@ def get_json(self, multihash, **kwargs):
2126
2127
def add_pyobj (self , py_obj , ** kwargs ):
2127
2128
"""Adds a picklable Python object as a file to IPFS.
2128
2129
2130
+ .. deprecated:: 0.4.2
2131
+ The ``*_pyobj`` APIs allow for arbitrary code execution if abused.
2132
+ Either switch to :meth:`~ipfsapi.Client.add_json` or use
2133
+ ``client.add_bytes(pickle.dumps(py_obj))`` instead.
2134
+
2135
+ Please see :meth:`~ipfsapi.Client.get_pyobj` for the
2136
+ **security risks** of using these methods!
2137
+
2129
2138
.. code-block:: python
2130
2139
2131
2140
>>> c.add_pyobj([0, 1.0, 2j, '3', 4e5])
@@ -2140,18 +2149,27 @@ def add_pyobj(self, py_obj, **kwargs):
2140
2149
-------
2141
2150
str : Hash of the added IPFS object
2142
2151
"""
2152
+ warnings .warn ("Using `*_pyobj` on untrusted data is a security risk" ,
2153
+ DeprecationWarning )
2143
2154
return self .add_bytes (encoding .Pickle ().encode (py_obj ), ** kwargs )
2144
2155
2145
2156
def get_pyobj (self , multihash , ** kwargs ):
2146
2157
"""Loads a pickled Python object from IPFS.
2147
2158
2159
+ .. deprecated:: 0.4.2
2160
+ The ``*_pyobj`` APIs allow for arbitrary code execution if abused.
2161
+ Either switch to :meth:`~ipfsapi.Client.get_json` or use
2162
+ ``pickle.loads(client.cat(multihash))`` instead.
2163
+
2148
2164
.. caution::
2149
2165
2150
2166
The pickle module is not intended to be secure against erroneous or
2151
2167
maliciously constructed data. Never unpickle data received from an
2152
2168
untrusted or unauthenticated source.
2153
2169
2154
- See the :mod:`pickle` module documentation for more information.
2170
+ Please **read**
2171
+ `this article <https://www.cs.uic.edu/%7Es/musings/pickle/>`_ to
2172
+ understand the security risks of using this method!
2155
2173
2156
2174
.. code-block:: python
2157
2175
@@ -2167,4 +2185,6 @@ def get_pyobj(self, multihash, **kwargs):
2167
2185
-------
2168
2186
object : Deserialized IPFS Python object
2169
2187
"""
2188
+ warnings .warn ("Using `*_pyobj` on untrusted data is a security risk" ,
2189
+ DeprecationWarning )
2170
2190
return self .cat (multihash , decoder = 'pickle' , ** kwargs )
0 commit comments