-
Notifications
You must be signed in to change notification settings - Fork 39
Feature: Add Indicator To AddIOCtoIOCCollectionAction (1315, 1314) #2064
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,10 +1,12 @@ | ||||||||||||||||||||||||||||
| import requests | ||||||||||||||||||||||||||||
| import ipaddress | ||||||||||||||||||||||||||||
| from datetime import datetime, timedelta | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from .base import InThreatBaseAction | ||||||||||||||||||||||||||||
| import requests | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from sekoiaio.utils import datetime_to_str | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| from .base import InThreatBaseAction | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| class AddIOCtoIOCCollectionAction(InThreatBaseAction): | ||||||||||||||||||||||||||||
| def perform_request(self, indicators, ioc_collection_id, indicator_type, valid_for): | ||||||||||||||||||||||||||||
|
|
@@ -50,18 +52,21 @@ def run(self, arguments: dict): | |||||||||||||||||||||||||||
| "hash": "file.hashes", | ||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| indicators = self.json_argument("indicators", arguments) | ||||||||||||||||||||||||||||
| indicators = self.json_argument("indicators", arguments, required=False) | ||||||||||||||||||||||||||||
| single_indicator = arguments.get("indicator") | ||||||||||||||||||||||||||||
| ioc_collection_id = arguments.get("ioc_collection_id") | ||||||||||||||||||||||||||||
| indicator_type = arguments.get("indicator_type") | ||||||||||||||||||||||||||||
| valid_for = int(arguments.get("valid_for", 0)) | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| result_indicators = indicators or [single_indicator] | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| if str(indicator_type) == "IP address": | ||||||||||||||||||||||||||||
| if not isinstance(indicators, list): | ||||||||||||||||||||||||||||
| raise ValueError("Indicators should be list type") | ||||||||||||||||||||||||||||
| if not isinstance(indicators, list) and not single_indicator: | ||||||||||||||||||||||||||||
| raise ValueError("Indicators should be list type, or you should provide a single indicator value") | ||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||
| self.add_IP_action(indicators, ioc_collection_id, valid_for) | ||||||||||||||||||||||||||||
| self.add_IP_action(result_indicators, ioc_collection_id, valid_for) | ||||||||||||||||||||||||||||
|
Comment on lines
63
to
+67
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. suggestion (bug_risk): Align validation error message with the actual accepted shapes and ensure list type is also enforced when a single indicator is supplied as a list. The current condition ( if indicators is not None and not isinstance(indicators, list):
raise ValueError("'indicators' must be a list; alternatively, use 'indicator' for a single value")Then rely on the normalization of
Suggested change
|
||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| if _type := indicator_type_mapping.get(str(indicator_type)): | ||||||||||||||||||||||||||||
| self.perform_request(indicators, ioc_collection_id, _type, valid_for) | ||||||||||||||||||||||||||||
| self.perform_request(result_indicators, ioc_collection_id, _type, valid_for) | ||||||||||||||||||||||||||||
| else: | ||||||||||||||||||||||||||||
| self.error(f"Improper indicator type {indicator_type}") | ||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue: Guard against both
indicatorsandsingle_indicatorbeing missing to avoid passing[None]downstream.When both are absent,
result_indicatorsbecomes[None]and is passed toadd_IP_action/perform_request, likely causing confusing downstream errors. Add an explicit guard, for example: