diff --git a/monkey/monkey_island/cc/repository/mongo_agent_event_repository.py b/monkey/monkey_island/cc/repository/mongo_agent_event_repository.py index 2d807d896..336039319 100644 --- a/monkey/monkey_island/cc/repository/mongo_agent_event_repository.py +++ b/monkey/monkey_island/cc/repository/mongo_agent_event_repository.py @@ -31,13 +31,14 @@ def encrypt_event( if not isinstance(event_data, dict): raise TypeError("Event encryption only supported for dict") + data = event_data.copy() for field in fields: - event_data[ENCRYPTED_PREFIX + field] = str( + data[ENCRYPTED_PREFIX + field] = str( encrypt(json.dumps(event_data[field]).encode()), "utf-8" ) - del event_data[field] + del data[field] - return event_data + return data def decrypt_event( @@ -46,14 +47,15 @@ def decrypt_event( if not isinstance(event_data, dict): raise TypeError("Event decryption only supported for dict") + data = event_data.copy() for field in event_data.keys(): if field.startswith("encrypted_"): - event_data[field[len(ENCRYPTED_PREFIX) :]] = json.loads( + data[field[len(ENCRYPTED_PREFIX) :]] = json.loads( str(decrypt(event_data[field].encode()), "utf-8") ) - del event_data[field] + del data[field] - return event_data + return data class MongoAgentEventRepository(IAgentEventRepository):