Skip to content

Commit 609be64

Browse files
authored
Merge pull request #101 from alexander255/master
Deprecate `.add_pyobj` and `.get_pypbj` and stop recommending them in documentation (fixes #96)
2 parents a41f641 + 48002e5 commit 609be64

File tree

2 files changed

+25
-5
lines changed

2 files changed

+25
-5
lines changed

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -104,13 +104,13 @@ Or add a directory recursively:
104104
'Name': 'fake_dir'}]
105105
```
106106

107-
This module also contains some helper functions for adding strings, json, and even python objects to IPFS:
107+
This module also contains some helper functions for adding strings and JSON to IPFS:
108108

109109
```py
110110
>>> lst = [1, 77, 'lol']
111-
>>> api.add_pyobj(lst)
112-
'QmRFqz1ABQtbMBDfjpMubTaginvpVnf58Y87gheRzGfe4i'
113-
>>> api.get_pyobj(_)
111+
>>> client.add_json(lst)
112+
'QmQ4R5cCUYBWiJpNL7mFe4LDrwD6qBr5Re17BoRAY9VNpd'
113+
>>> client.get_json(_)
114114
[1, 77, 'lol']
115115
```
116116

ipfsapi/client.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
from __future__ import absolute_import
99

1010
import os
11+
import warnings
1112

1213
from . import http, multipart, utils, exceptions, encoding
1314

@@ -2126,6 +2127,14 @@ def get_json(self, multihash, **kwargs):
21262127
def add_pyobj(self, py_obj, **kwargs):
21272128
"""Adds a picklable Python object as a file to IPFS.
21282129
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+
21292138
.. code-block:: python
21302139
21312140
>>> c.add_pyobj([0, 1.0, 2j, '3', 4e5])
@@ -2140,18 +2149,27 @@ def add_pyobj(self, py_obj, **kwargs):
21402149
-------
21412150
str : Hash of the added IPFS object
21422151
"""
2152+
warnings.warn("Using `*_pyobj` on untrusted data is a security risk",
2153+
DeprecationWarning)
21432154
return self.add_bytes(encoding.Pickle().encode(py_obj), **kwargs)
21442155

21452156
def get_pyobj(self, multihash, **kwargs):
21462157
"""Loads a pickled Python object from IPFS.
21472158
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+
21482164
.. caution::
21492165
21502166
The pickle module is not intended to be secure against erroneous or
21512167
maliciously constructed data. Never unpickle data received from an
21522168
untrusted or unauthenticated source.
21532169
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!
21552173
21562174
.. code-block:: python
21572175
@@ -2167,4 +2185,6 @@ def get_pyobj(self, multihash, **kwargs):
21672185
-------
21682186
object : Deserialized IPFS Python object
21692187
"""
2188+
warnings.warn("Using `*_pyobj` on untrusted data is a security risk",
2189+
DeprecationWarning)
21702190
return self.cat(multihash, decoder='pickle', **kwargs)

0 commit comments

Comments
 (0)