OpenCTI-Platform / connectors

OpenCTI Connectors
https://www.opencti.io
Apache License 2.0
383 stars 415 forks source link

[Mandiant] Crash if the state is empty #3001

Open Lhorus6 opened 1 day ago

Lhorus6 commented 1 day ago

Description

If the state is empty, like at first startup for example, the connector crashes. Here is the error:

{
  "timestamp": "2024-11-20T17:09:13.010045Z",
  "level": "ERROR",
  "name": "Mandiant Threat Intelligence - Up to date",
  "message": "[ERROR] An error occurred while checking the queue size",
  "exc_info": "Traceback (most recent call last):\n  File \"/usr/local/lib/python3.12/site-packages/pycti/connector/opencti_connector_helper.py\", line 1336, in _schedule_process\n    message_callback()\n  File \"/opt/connector/base.py\", line 538, in process_message\n    last_run_value = Timestamp.from_iso(state[collection][STATE_LAST_RUN]).value\n                                        ~~~~~^^^^^^^^^^^^\nTypeError: 'NoneType' object is not subscriptable",
  "taskName": null,
  "attributes": {
    "reason": "'NoneType' object is not subscriptable"
  }
}

Environment

OCTI 6.4.0

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Run the Mandiant connector. NB: if the state is not empty, reset it from the UI (in Data > Ingestion > Connector > Mandiant)

Expected Output

I hope the connector runs without any problems. That is, if the state does not exist, the connector handles the situation.

Actual Output

Crash

Additional information

It seems simple to handle at first glance. We should check that a state exists here : https://github.com/OpenCTI-Platform/connectors/blob/d06ae3715d3d724ad2e97794a27df56984e14bd0/external-import/mandiant/src/connector/base.py#L538

Screenshots

Image