Fix security issue: Unsafe Pickle Deserialization Enabling Remote Code Execution (CWE-502)
This commit is contained in:
parent
b1b4ae3d5f
commit
e4880abf72
1 changed files with 2 additions and 6 deletions
|
|
@ -80,11 +80,7 @@ class DataPoint(BaseModel):
|
|||
"""Serialize the instance to pickle-compatible bytes."""
|
||||
return pickle.dumps(self.dict())
|
||||
|
||||
@classmethod
|
||||
def from_pickle(self, pickled_data: bytes):
|
||||
"""Deserialize the instance from pickled bytes."""
|
||||
data = pickle.loads(pickled_data)
|
||||
return self(**data)
|
||||
# The unsafe from_pickle method is removed due to security concerns (CWE-502).
|
||||
|
||||
def to_dict(self, **kwargs) -> Dict[str, Any]:
|
||||
"""Serialize model to a dictionary."""
|
||||
|
|
@ -93,4 +89,4 @@ class DataPoint(BaseModel):
|
|||
@classmethod
|
||||
def from_dict(cls, data: Dict[str, Any]) -> "DataPoint":
|
||||
"""Deserialize model from a dictionary."""
|
||||
return cls.model_validate(data)
|
||||
return cls.model_validate(data)
|
||||
Loading…
Add table
Reference in a new issue