Skip to content

fix(google-dtm): guard optional fields when building the alert content (#7360) - #7361

Open
Romain GUIGNARD (romain-filigran) wants to merge 2 commits into
masterfrom
fix/7360
Open

fix(google-dtm): guard optional fields when building the alert content (#7360)#7361
Romain GUIGNARD (romain-filigran) wants to merge 2 commits into
masterfrom
fix/7360

Conversation

@romain-filigran

@romain-filigran Romain GUIGNARD (romain-filigran) commented Aug 22, 2026

Copy link
Copy Markdown
Member

Proposed changes

  • Intermediate levels of every chained access now carry a {} default, in the six markdown builders and in create_channel(). account_discovery was the reported case (service_account.password absent, line 197), but source_file.hashes.*, service_account.service.inet_location.*, channel.channel_info.description, sender.identity.name and file_hashes.* had the same defect, so message and document_analysis alerts were affected too.
  • create_channel() is called outside create_incident()'s try/except, so its channel_info chain did not just lose the attachment: the exception reached process_message() and aborted the run — no bundle sent, state not advanced, and the same alert killing every subsequent run. Its "[" + channel_type + "] - " + channel_name concatenations are now f-strings, since they raised the same way on a missing messenger, and both parts default to "" so the Channel is not named [None] - leaks.
  • document_analysis and paste get the dtm_alert_doc = dtm_alert.get("doc", {}) line the four other builders already had, instead of repeating dtm_alert.get("doc").
  • doc_type and the "channel" in … test in create_incident() read doc with a default too, both being outside the try.
  • New tests/tests_connector/test_converter_to_stix.py (12 tests). The connector's suite goes from 8 to 20 tests.

Related issues

Checklist

  • I consider the submitted work as finished
  • I have signed my commits using GPG key.
  • I tested the code for its functionality using different use cases
  • I added/update the relevant documentation (either on github or on notion)
  • Where necessary I refactored code to improve the overall quality

Further comments

Copilot AI lite review requested due to automatic review settings August 22, 2026 14:01
@github-actions

Copy link
Copy Markdown

⚠️ Unused dependencies detected

The following packages appear to be unused:

  • pyyaml in external-import/google-dtm/src/requirements.txt
  • validators in external-import/google-dtm/src/requirements.txt

How to fix: (1) if the package is used but under a different import name (e.g. PyYAMLyaml), add a mapping line to .github/deptry-package-map.txt. (2) if truly unused, remove it from the connector's requirements.txt.

@github-actions

github-actions Bot commented Aug 22, 2026

Copy link
Copy Markdown

🔴 Connector Linter errors detected

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR hardens the external-import/google-dtm connector against missing optional fields in DTM alert documents so markdown generation and channel creation don’t raise exceptions that would drop the alert.md attachment or abort processing.

Changes:

  • Added {} defaults to nested .get() chains in multiple markdown builders and in create_channel().
  • Made create_incident() safer by guarding doc access (e.g., doc_type, "channel" in doc) outside the markdown-generation try/except.
  • Added a new pytest module covering missing optional fields and ensuring create_channel() doesn’t abort runs.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
external-import/google-dtm/src/google_dtm_connector/converter_to_stix.py Adds defaults to chained .get() access (markdown + channel creation) and guards some doc reads outside the try/except.
external-import/google-dtm/tests/tests_connector/test_converter_to_stix.py Adds regression tests for missing optional fields and for create_channel() behavior when channel metadata is absent.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +190 to +199
- **Source File**: {dtm_alert_doc.get("source_file", {}).get("filename")}
- **MD5**: {dtm_alert_doc.get("source_file", {}).get("hashes", {}).get("md5")}
- **SHA1**: {dtm_alert_doc.get("source_file", {}).get("hashes", {}).get("sha1")}
- **SHA256**: {dtm_alert_doc.get("source_file", {}).get("hashes", {}).get("sha256")}
### Content
- **Service URL**: {dtm_alert_doc.get("service_account").get("service").get("inet_location").get("domain")}
- **Service Domain**: {dtm_alert_doc.get("service_account").get("service").get("inet_location").get("url")}
- **Email Domain**: {dtm_alert_doc.get("service_account").get("email_domain")}
- **Login**: {dtm_alert_doc.get("service_account").get("login")}
- **Password**: {dtm_alert_doc.get("service_account").get("password").get("plain_text")}
- **Service URL**: {dtm_alert_doc.get("service_account", {}).get("service", {}).get("inet_location", {}).get("domain")}
- **Service Domain**: {dtm_alert_doc.get("service_account", {}).get("service", {}).get("inet_location", {}).get("url")}
- **Email Domain**: {dtm_alert_doc.get("service_account", {}).get("email_domain")}
- **Login**: {dtm_alert_doc.get("service_account", {}).get("login")}
- **Password**: {dtm_alert_doc.get("service_account", {}).get("password", {}).get("plain_text")}
Comment on lines +73 to +84
def test_account_discovery_without_a_plaintext_password(converter):
"""The reported bug: service_account.password is absent, .get() raised."""
stix_objects = converter.create_incident(_ACCOUNT_DISCOVERY_ALERT)

markdown = _alert_markdown(stix_objects)
converter.helper.connector_logger.error.assert_not_called()
# The absent value is rendered empty, the ones that are there are kept.
assert "- **Password**: None\n" in markdown
assert "- **Login**: jdoe@acme.com\n" in markdown
assert "- **MD5**: d41d8cd98f00b204e9800998ecf8427e\n" in markdown
assert "- **SHA256**: None\n" in markdown

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

Suppressed comments (1)

Previously missed (1) — in code that hasn't changed since the last review.

external-import/google-dtm/src/google_dtm_connector/converter_to_stix.py:76

  • When messenger is missing, channel_type becomes "" and the ExternalReference source_name becomes " - <channel_name>" (leading separator). This makes the external reference harder to read/search and can create empty/odd source_name values when name/type are missing. Consider building source_name from the non-empty parts (fallbacking to formatted_channel_name) so it never includes a leading/trailing separator.
        formatted_channel_name = f"[{channel_type}] - {channel_name}"
        external_refs = []
        if channel_url:
            external_ref = stix2.ExternalReference(
                source_name=f"{channel_type} - {channel_name}", url=channel_url

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

filigran team Item from the Filigran team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(google-dtm): alerts lose their alert.md attachment when an optional field is absent

3 participants