Skip to content

Commit 253e40d

Browse files
fix: use yaml.safe_dump() and add pickle security warning (CWE-502) (#563)
Agent-Logs-Url: https://github.com/fabiocaccamo/python-benedict/sessions/1831baca-52a5-437a-b931-886a059e7683 Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: fabiocaccamo <1035294+fabiocaccamo@users.noreply.github.com>
1 parent e92267b commit 253e40d

2 files changed

Lines changed: 6 additions & 2 deletions

File tree

benedict/serializers/pickle.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
class PickleSerializer(AbstractSerializer[str, Any]):
1111
"""
1212
This class describes a pickle serializer.
13+
14+
Security warning: Pickle deserialization can execute arbitrary code.
15+
Only use this serializer with data from trusted sources that you control.
16+
Never deserialize pickle data received from untrusted or external sources.
1317
"""
1418

1519
@override
@@ -23,7 +27,7 @@ def __init__(self) -> None:
2327
@override
2428
def decode(self, s: str, **kwargs: Any) -> Any:
2529
encoding = kwargs.pop("encoding", "utf-8")
26-
return pickle.loads(base64.b64decode(s.encode(encoding)), **kwargs)
30+
return pickle.loads(base64.b64decode(s.encode(encoding)), **kwargs) # nosec B301
2731

2832
@override
2933
def encode(self, d: Any, **kwargs: Any) -> str:

benedict/serializers/yaml.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,5 +45,5 @@ def decode(self, s: str, **kwargs: Any) -> Any:
4545
def encode(self, d: Any, **kwargs: Any) -> str:
4646
require_yaml(installed=yaml_installed)
4747
d = self._json_serializer.decode(self._json_serializer.encode(d))
48-
data = yaml.dump(d, **kwargs)
48+
data = yaml.safe_dump(d, **kwargs)
4949
return cast("str", data)

0 commit comments

Comments
 (0)