fix(csv-mapper): roles are not being assigned to Threat Actor (#10944)#16748
fix(csv-mapper): roles are not being assigned to Threat Actor (#10944)#16748CelineSebe wants to merge 2 commits into
Conversation
|
🤖 [AI-generated] Hey @CelineSebe! 👋 Thanks a lot for opening PR #16748 — really appreciate you tackling the Threat Actor roles assignment in the CSV mapper! 🙏 I just had a quick look and I think the description could be enhanced a little to help reviewers get through it faster. I haven't changed anything in your description — just a gentle, optional suggestion:
No rush at all — thanks again for contributing to OpenCTI! 🚀 |
Codecov Report❌ Patch coverage is
❌ Your patch check has failed because the patch coverage (57.14%) is below the target coverage (80.00%). You can increase the patch coverage or adjust the target coverage. Additional details and impacted files@@ Coverage Diff @@
## master #16748 +/- ##
==========================================
+ Coverage 23.99% 24.09% +0.10%
==========================================
Files 3268 3271 +3
Lines 173116 174449 +1333
Branches 42909 43702 +793
==========================================
+ Hits 41541 42038 +497
- Misses 131575 132411 +836
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
This PR fixes a PyCTI open-vocabulary resolution issue that prevented roles from being assigned for Threat Actors during STIX2 ingestion (e.g., via CSV Mapper), by selecting the correct vocabulary category based on the object’s entity type (case-insensitive).
Changes:
- Extend the
vocabularyCategoriesquery to includeentity_typesand fieldmultiple, and filter vocabulary resolution by the current object entity type. - Include
category/entity_typesmetadata in cached vocabulary field definitions so resolution is deterministic when the same field key exists across multiple entity types (e.g.,roles). - Add unit tests covering correct category selection and case-insensitive entity type matching.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| client-python/pycti/utils/opencti_stix2.py | Resolves open vocabularies by matching the STIX object’s entity type to the vocabulary category’s entity_types (case-insensitive). |
| client-python/pycti/entities/opencti_vocabulary.py | Updates vocabulary cache keying to include category (avoids cross-category collisions). |
| client-python/tests/01-unit/utils/test_opencti_stix2.py | Adds unit tests ensuring open vocab roles resolve to the correct category and handle lowercase entity types. |
| """ | ||
| if "vocab_" + vocab in cache: | ||
| vocab_data = cache["vocab_" + vocab] | ||
| category = field.get("category", cache.get("category_" + field["key"])) | ||
| cache_key = f"vocab_{category}_{vocab}" | ||
| if cache_key in cache: | ||
| vocab_data = cache[cache_key] |
Proposed changes
Related issues
How to test this PR
Checklist
Further comments