Skip to content
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

The "deleteConnector" API runs into an unexpected exception when the connector doesn't exist #4078

Closed
ckyoog opened this issue Aug 16, 2023 · 0 comments · Fixed by #4082
Closed
Assignees
Labels
bug use for describing something not working as expected solved use to identify issue that has been solved (must be linked to the solving PR)

Comments

@ckyoog
Copy link

ckyoog commented Aug 16, 2023

Description

Environment

  1. OS (where OpenCTI server runs): Ubuntu
  2. OpenCTI version: 5.9.6

Reproducible Steps

Steps to create the smallest reproducible scenario:

  1. Use the API to delete the connector, the ID is something doesn't exist.
{
  "id": "ConnectorDeletionMutation",
  "query": "mutation ConnectorDeletionMutation(\n  $id: ID!\n) {\n  deleteConnector(id: $id)\n}\n",
  "variables": {
    "id": "5663303b-ce5b-4e34-a077-10312dd19691"
  }
}

Expected Output

The error is supposed to be like this, (in 5.7.6, the error is this)

[
  {
    "message": "Business validation",
    "name": "AlreadyDeletedError",
    "time_thrown": "2023-08-14T08:16:35.315Z",
    "data": {
      "reason": "Already deleted elements",
      "http_status": 400,
      "category": "business",
      "id": "5663303b-ce5b-4e34-a077-10312dd19691"
    }
  }
]

Actual Output

But the actual error it returns is this,

[
  {
    "message": "Cannot read properties of undefined (reading 'name')",
    "locations": [
      {
        "line": 2,
        "column": 3
      }
    ],
    "path": [
      "deleteConnector"
    ],
    "extensions": {
      "code": "INTERNAL_SERVER_ERROR"
    }
  }
]

Additional information

And if you check the opencti server's log in the meantime, you would find this error,

{
  "category": "APP",
  "error": {
    "stacktrace": [
      "TypeError: Cannot read properties of undefined (reading name)",
      "at deleteWorkForConnector (/.../src/domain/work.js:128:64)",
      "at runMicrotasks (<anonymous>)",
      "at processTicksAndRejections (node:internal/process/task_queues:96:5)",
      "at connectorDelete (/.../src/domain/connector.js:125:3)"
    ]
  },
  "inner_relation_creation": 0,
  "level": "error",
  "message": "API Call",
  "operation": "ConnectorDeletionMutation",
  "operation_query": "mutation ConnectorDeletionMutation($id:ID!){deleteConnector(id:$id)}",
  "size": 45,
  "time": 16,
  "timestamp": "2023-08-14T02:02:14.323Z",
  "type": "WRITE_ERROR",
  "user": {
    "group_ids": [
      "<a-hidden-uuid>"
    ],
    "ip": "<a-hidden-ip>",
    "organization_ids": [],
    "socket": "query",
    "user_id": "<a-hidden-uuid>"
  },
  "variables": {
    "id": "5663303b-ce5b-4e34-a077-10312dd19691"
  },
  "version": "5.9.6"
}

My attempt to fix the bug

--- src/domain/work.js
+++ /tmp/new
@@ -115,6 +115,9 @@
 
 export const deleteWorkForConnector = async (context, user, connectorId) => {
   const connector = await elLoadById(context, user, connectorId, { type: ENTITY_TYPE_CONNECTOR });
+  if (!connector) {
+    return true;
+  }
   let works = await worksForConnector(context, user, connectorId, { first: 500 });
   while (works.length > 0) {
     await deleteWorksRaw(works);

return true keeps the behavior of the function deleteWorkForConnector as same as the previous version, which is "do nothing if the connector no longer exist".

@ckyoog ckyoog added the bug use for describing something not working as expected label Aug 16, 2023
@Archidoit Archidoit self-assigned this Aug 16, 2023
@Archidoit Archidoit added the solved use to identify issue that has been solved (must be linked to the solving PR) label Aug 17, 2023
@SamuelHassine SamuelHassine added this to the Release 5.10.0 milestone Aug 17, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug use for describing something not working as expected solved use to identify issue that has been solved (must be linked to the solving PR)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants