diff --git a/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability.proto b/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability.proto index 35fb92ebf..5aea87c39 100644 --- a/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability.proto +++ b/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability.proto @@ -53,8 +53,8 @@ message CallTrace { message Metadata { optional MetadataTypeEnum type = 1; - oneof value { - string raw_value = 2; + oneof metadata_value { + string value = 2; CallTrace calltrace = 3; } } diff --git a/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability_pb2.py b/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability_pb2.py index 8768b36d3..264964ce9 100644 --- a/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability_pb2.py +++ b/src/ostorlab/agent/message/proto/v3/report/vulnerability/vulnerability_pb2.py @@ -23,17 +23,17 @@ from ostorlab.agent.message.proto.v3.asset.file.ios.ipa import ipa_pb2 as ostorlab_dot_agent_dot_message_dot_proto_dot_v3_dot_asset_dot_file_dot_ios_dot_ipa_dot_ipa__pb2 -DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\nHostorlab/agent/message/proto/v3/report/vulnerability/vulnerability.proto\x12\x34ostorlab.agent.message.proto.v3.report.vulnerability\x1a\x43ostorlab/agent/message/proto/v3/asset/domain_name/domain_name.proto\x1a\x34ostorlab/agent/message/proto/v3/asset/ip/v4/v4.proto\x1a\x34ostorlab/agent/message/proto/v3/asset/ip/v6/v6.proto\x1a\x35ostorlab/agent/message/proto/v3/asset/link/link.proto\x1aMostorlab/agent/message/proto/v3/asset/store/android_store/android_store.proto\x1a\x45ostorlab/agent/message/proto/v3/asset/store/ios_store/ios_store.proto\x1a\x35ostorlab/agent/message/proto/v3/asset/file/file.proto\x1a@ostorlab/agent/message/proto/v3/asset/file/android/aab/aab.proto\x1a@ostorlab/agent/message/proto/v3/asset/file/android/apk/apk.proto\x1a.ostorlab.agent.message.proto.v3.asset.store.ios_store.MessageH\x00\x12\x43\n\x04\x66ile\x18\x07 \x01(\x0b\x32\x33.ostorlab.agent.message.proto.v3.asset.file.MessageH\x00\x12V\n\x0b\x61ndroid_aab\x18\x08 \x01(\x0b\x32?.ostorlab.agent.message.proto.v3.asset.file.android.aab.MessageH\x00\x12V\n\x0b\x61ndroid_apk\x18\t \x01(\x0b\x32?.ostorlab.agent.message.proto.v3.asset.file.android.apk.MessageH\x00\x12N\n\x07ios_ipa\x18\n \x01(\x0b\x32;.ostorlab.agent.message.proto.v3.asset.file.ios.ipa.MessageH\x00\x12P\n\x08metadata\x18\x64 \x03(\x0b\x32>.ostorlab.agent.message.proto.v3.report.vulnerability.MetadataB\x07\n\x05\x61sset\"0\n\rCategoryGroup\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x12\n\ncategories\x18\x02 \x03(\t\"\xc1\x06\n\x07Message\x12\r\n\x05title\x18\x01 \x01(\t\x12U\n\x0brisk_rating\x18\x02 \x01(\x0e\x32@.ostorlab.agent.message.proto.v3.report.vulnerability.RiskRating\x12\x18\n\x10technical_detail\x18\x03 \x01(\t\x12\x19\n\x11short_description\x18\x04 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x05 \x01(\t\x12\x16\n\x0erecommendation\x18\x06 \x01(\t\x12S\n\nreferences\x18\x07 \x03(\x0b\x32?.ostorlab.agent.message.proto.v3.report.vulnerability.Reference\x12\x1d\n\x0esecurity_issue\x18\x08 \x01(\x08:\x05\x66\x61lse\x12\x1c\n\rprivacy_issue\x18\t \x01(\x08:\x05\x66\x61lse\x12!\n\x12has_public_exploit\x18\n \x01(\x08:\x05\x66\x61lse\x12\"\n\x13targeted_by_malware\x18\x0b \x01(\x08:\x05\x66\x61lse\x12%\n\x16targeted_by_ransomware\x18\x0c \x01(\x08:\x05\x66\x61lse\x12\'\n\x18targeted_by_nation_state\x18\r \x01(\x08:\x05\x66\x61lse\x12\x0b\n\x03\x64na\x18\x0e \x01(\t\x12\x16\n\x0e\x63vss_v3_vector\x18\x0f \x01(\t\x12k\n\x16vulnerability_location\x18\x10 \x01(\x0b\x32K.ostorlab.agent.message.proto.v3.report.vulnerability.VulnerabilityLocation\x12\\\n\x0f\x63\x61tegory_groups\x18\x11 \x03(\x0b\x32\x43.ostorlab.agent.message.proto.v3.report.vulnerability.CategoryGroup\x12\x16\n\x0e\x63vss_v4_vector\x18\x12 \x01(\t\x12\x1b\n\x13\x65xploitation_detail\x18\x13 \x01(\t\x12 \n\x18post_exploitation_detail\x18\x14 \x01(\t*~\n\nRiskRating\x12\x08\n\x04HIGH\x10\x00\x12\n\n\x06MEDIUM\x10\x01\x12\x07\n\x03LOW\x10\x02\x12\x0f\n\x0bPOTENTIALLY\x10\x03\x12\r\n\tHARDENING\x10\x04\x12\n\n\x06SECURE\x10\x05\x12\r\n\tIMPORTANT\x10\x06\x12\x08\n\x04INFO\x10\x07\x12\x0c\n\x08\x43RITICAL\x10\x08*\x93\x01\n\x10MetadataTypeEnum\x12\r\n\tFILE_PATH\x10\x00\x12\x11\n\rCODE_LOCATION\x10\x01\x12\x07\n\x03URL\x10\x02\x12\x08\n\x04PORT\x10\x03\x12\x07\n\x03LOG\x10\x04\x12\x10\n\x0cPACKAGE_NAME\x10\x05\x12\x0e\n\nCLASS_NAME\x10\x06\x12\x0f\n\x0bMETHOD_NAME\x10\x07\x12\x0e\n\nCALL_TRACE\x10\x08') +DESCRIPTOR = _descriptor_pool.Default().AddSerializedFile(b'\nHostorlab/agent/message/proto/v3/report/vulnerability/vulnerability.proto\x12\x34ostorlab.agent.message.proto.v3.report.vulnerability\x1a\x43ostorlab/agent/message/proto/v3/asset/domain_name/domain_name.proto\x1a\x34ostorlab/agent/message/proto/v3/asset/ip/v4/v4.proto\x1a\x34ostorlab/agent/message/proto/v3/asset/ip/v6/v6.proto\x1a\x35ostorlab/agent/message/proto/v3/asset/link/link.proto\x1aMostorlab/agent/message/proto/v3/asset/store/android_store/android_store.proto\x1a\x45ostorlab/agent/message/proto/v3/asset/store/ios_store/ios_store.proto\x1a\x35ostorlab/agent/message/proto/v3/asset/file/file.proto\x1a@ostorlab/agent/message/proto/v3/asset/file/android/aab/aab.proto\x1a@ostorlab/agent/message/proto/v3/asset/file/android/apk/apk.proto\x1a.ostorlab.agent.message.proto.v3.asset.store.ios_store.MessageH\x00\x12\x43\n\x04\x66ile\x18\x07 \x01(\x0b\x32\x33.ostorlab.agent.message.proto.v3.asset.file.MessageH\x00\x12V\n\x0b\x61ndroid_aab\x18\x08 \x01(\x0b\x32?.ostorlab.agent.message.proto.v3.asset.file.android.aab.MessageH\x00\x12V\n\x0b\x61ndroid_apk\x18\t \x01(\x0b\x32?.ostorlab.agent.message.proto.v3.asset.file.android.apk.MessageH\x00\x12N\n\x07ios_ipa\x18\n \x01(\x0b\x32;.ostorlab.agent.message.proto.v3.asset.file.ios.ipa.MessageH\x00\x12P\n\x08metadata\x18\x64 \x03(\x0b\x32>.ostorlab.agent.message.proto.v3.report.vulnerability.MetadataB\x07\n\x05\x61sset\"0\n\rCategoryGroup\x12\x0b\n\x03key\x18\x01 \x01(\t\x12\x12\n\ncategories\x18\x02 \x03(\t\"\xc1\x06\n\x07Message\x12\r\n\x05title\x18\x01 \x01(\t\x12U\n\x0brisk_rating\x18\x02 \x01(\x0e\x32@.ostorlab.agent.message.proto.v3.report.vulnerability.RiskRating\x12\x18\n\x10technical_detail\x18\x03 \x01(\t\x12\x19\n\x11short_description\x18\x04 \x01(\t\x12\x13\n\x0b\x64\x65scription\x18\x05 \x01(\t\x12\x16\n\x0erecommendation\x18\x06 \x01(\t\x12S\n\nreferences\x18\x07 \x03(\x0b\x32?.ostorlab.agent.message.proto.v3.report.vulnerability.Reference\x12\x1d\n\x0esecurity_issue\x18\x08 \x01(\x08:\x05\x66\x61lse\x12\x1c\n\rprivacy_issue\x18\t \x01(\x08:\x05\x66\x61lse\x12!\n\x12has_public_exploit\x18\n \x01(\x08:\x05\x66\x61lse\x12\"\n\x13targeted_by_malware\x18\x0b \x01(\x08:\x05\x66\x61lse\x12%\n\x16targeted_by_ransomware\x18\x0c \x01(\x08:\x05\x66\x61lse\x12\'\n\x18targeted_by_nation_state\x18\r \x01(\x08:\x05\x66\x61lse\x12\x0b\n\x03\x64na\x18\x0e \x01(\t\x12\x16\n\x0e\x63vss_v3_vector\x18\x0f \x01(\t\x12k\n\x16vulnerability_location\x18\x10 \x01(\x0b\x32K.ostorlab.agent.message.proto.v3.report.vulnerability.VulnerabilityLocation\x12\\\n\x0f\x63\x61tegory_groups\x18\x11 \x03(\x0b\x32\x43.ostorlab.agent.message.proto.v3.report.vulnerability.CategoryGroup\x12\x16\n\x0e\x63vss_v4_vector\x18\x12 \x01(\t\x12\x1b\n\x13\x65xploitation_detail\x18\x13 \x01(\t\x12 \n\x18post_exploitation_detail\x18\x14 \x01(\t*~\n\nRiskRating\x12\x08\n\x04HIGH\x10\x00\x12\n\n\x06MEDIUM\x10\x01\x12\x07\n\x03LOW\x10\x02\x12\x0f\n\x0bPOTENTIALLY\x10\x03\x12\r\n\tHARDENING\x10\x04\x12\n\n\x06SECURE\x10\x05\x12\r\n\tIMPORTANT\x10\x06\x12\x08\n\x04INFO\x10\x07\x12\x0c\n\x08\x43RITICAL\x10\x08*\x93\x01\n\x10MetadataTypeEnum\x12\r\n\tFILE_PATH\x10\x00\x12\x11\n\rCODE_LOCATION\x10\x01\x12\x07\n\x03URL\x10\x02\x12\x08\n\x04PORT\x10\x03\x12\x07\n\x03LOG\x10\x04\x12\x10\n\x0cPACKAGE_NAME\x10\x05\x12\x0e\n\nCLASS_NAME\x10\x06\x12\x0f\n\x0bMETHOD_NAME\x10\x07\x12\x0e\n\nCALL_TRACE\x10\x08') _builder.BuildMessageAndEnumDescriptors(DESCRIPTOR, globals()) _builder.BuildTopDescriptorsAndMessages(DESCRIPTOR, 'ostorlab.agent.message.proto.v3.report.vulnerability.vulnerability_pb2', globals()) if _descriptor._USE_C_DESCRIPTORS == False: DESCRIPTOR._options = None - _RISKRATING._serialized_start=2979 - _RISKRATING._serialized_end=3105 - _METADATATYPEENUM._serialized_start=3108 - _METADATATYPEENUM._serialized_end=3255 + _RISKRATING._serialized_start=2984 + _RISKRATING._serialized_end=3110 + _METADATATYPEENUM._serialized_start=3113 + _METADATATYPEENUM._serialized_end=3260 _REFERENCE._serialized_start=761 _REFERENCE._serialized_end=800 _FRAME._serialized_start=802 @@ -41,11 +41,11 @@ _CALLTRACE._serialized_start=876 _CALLTRACE._serialized_end=964 _METADATA._serialized_start=967 - _METADATA._serialized_end=1179 - _VULNERABILITYLOCATION._serialized_start=1182 - _VULNERABILITYLOCATION._serialized_end=2091 - _CATEGORYGROUP._serialized_start=2093 - _CATEGORYGROUP._serialized_end=2141 - _MESSAGE._serialized_start=2144 - _MESSAGE._serialized_end=2977 + _METADATA._serialized_end=1184 + _VULNERABILITYLOCATION._serialized_start=1187 + _VULNERABILITYLOCATION._serialized_end=2096 + _CATEGORYGROUP._serialized_start=2098 + _CATEGORYGROUP._serialized_end=2146 + _MESSAGE._serialized_start=2149 + _MESSAGE._serialized_end=2982 # @@protoc_insertion_point(module_scope) diff --git a/src/ostorlab/agent/mixins/agent_report_vulnerability_mixin.py b/src/ostorlab/agent/mixins/agent_report_vulnerability_mixin.py index 9231bbcb9..6a0569f0f 100644 --- a/src/ostorlab/agent/mixins/agent_report_vulnerability_mixin.py +++ b/src/ostorlab/agent/mixins/agent_report_vulnerability_mixin.py @@ -43,6 +43,7 @@ class Frame: package_name: Optional[str] = None def to_proto_dict(self) -> FrameProtoDictType: + """Return a dictionary structured same as the corresponding `Frame` protobuf field of the callTrace message.""" proto_dict_value: FrameProtoDictType = {"function_name": self.function_name} if self.class_name is not None: proto_dict_value["class_name"] = self.class_name @@ -58,6 +59,7 @@ class CallTrace: frames: List[Frame] = dataclasses.field(default_factory=lambda: []) def to_proto_dict(self) -> CallTraceProtoDictType: + """Return a dictionary structured same as the corresponding `callTrace` protobuf message.""" proto_dict_value: CallTraceProtoDictType = { "frames": [frame.to_proto_dict() for frame in self.frames] } @@ -77,7 +79,7 @@ def to_proto_dict(self) -> VulnerabilityLocationMetadataProtoDictType: "type": self.metadata_type.name } if isinstance(self.value, str): - proto_dict_value["raw_value"] = self.value + proto_dict_value["value"] = self.value if isinstance(self.value, CallTrace): proto_dict_value["calltrace"] = self.value.to_proto_dict() return proto_dict_value diff --git a/tests/agent/mixins/agent_report_vulnerability_mixin_test.py b/tests/agent/mixins/agent_report_vulnerability_mixin_test.py index b3fee8dde..44352e17c 100644 --- a/tests/agent/mixins/agent_report_vulnerability_mixin_test.py +++ b/tests/agent/mixins/agent_report_vulnerability_mixin_test.py @@ -218,23 +218,10 @@ def testFrameToProtoDict_whenAllFieldsAreSet_returnsCompleteDict() -> None: } -def testCallTraceToProtoDict_whenAllFieldsAreSet_returnsCompleteDict() -> None: +def testCallTraceToProtoDict_whenAllFieldsAreSet_returnsCompleteDict( + call_trace: agent_report_vulnerability_mixin.CallTrace, +) -> None: """Test that to_proto_dict returns a complete dictionary when all fields are set.""" - frame1 = agent_report_vulnerability_mixin.Frame( - function_name="test_func1", - class_name="TestClass1", - package_name="test.package1", - ) - frame2 = agent_report_vulnerability_mixin.Frame( - function_name="test_func2", - class_name="TestClass2", - package_name="test.package2", - ) - - call_trace = agent_report_vulnerability_mixin.CallTrace( - frames=[frame1, frame2], - ) - proto_dict = call_trace.to_proto_dict() assert proto_dict == {