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

[8.x] [Security Solution] [Attack discovery] Fixes intermittent refinement step error (#215816) #215966

Merged
merged 1 commit into from
Mar 26, 2025

Conversation

kibanamachine
Copy link
Contributor

Backport

This will backport the following commits from main to 8.x:

Questions ?

Please refer to the Backport tool documentation

…step error (elastic#215816)

## [Security Solution] [Attack discovery] Fixes intermittent refinement step error

This PR updates the refine prompt to fix the following intermittent error, which sometimes occurs during the refine step in the Attack discovery Langchain graph:

```
refine node is unable to parse (gemini) response from attempt 1; (this may be an incomplete response from the model): [
  {
    "code": "invalid_type",
    "expected": "object",
    "received": "array",
    "path": [],
    "message": "Expected object, received array"
  }
]
```

The fix wraps the input to the refine prompt with an opening / closing `json` codeblock, in an object with an `insights` key:

````
"""
```json
{
  "insights": [
    // ...
  ]
}
```
"""
````

### Desk testing

1. Navigate to Security > Attack discovery

2. Click the `Generate` button to generate Attack discoveries

3. When generation completes, open the entry for the completed run in LangGraph

4. In the LangGraph waterfall, click on the `ActionsClientLlm` entry for the `refine` step

**Expected result**

The input to the refine prompt is wrapped with an opening / closing `json` codeblock, in an object with an `insights` key, as illustrated by the following screenshot and example:

![langgraph](https://github.com/user-attachments/assets/d1ec75f9-4201-4ade-a876-170fab41f89b)

````
// ...
- Conform exactly to the JSON schema defined earlier
- Do not include explanatory text outside the JSON

"""
```json
{
  "insights": [
  {
    "alertIds": [
      "086469904a1ba57f4114466af23bbe2d0c62dde193a2fd4afd4ba3c4b4fc079f",
      "21ca4e4f082fd68ae2ad9a953fb5cfc9395a1769602011684750e95b36a79a99",
      "7a816e5db9464fcea1ba44ad28f4256e1fce079336bd9c32c9933c12fcdeb901",
      "986503ca78da6496646564a467e5aee9bf7fbb347bf0b017f3a57475f3546fa3"
    ],
    "detailsMarkdown": "- A malicious OneNote file was opened on {{ host.name 23466d50-b193-46cc-86f0-f6dd65902a73 }}\n- This triggered the execution of a suspicious Go application: {{ process.name My Go Application.app }}\n- The Go application then launched a malicious binary {{ file.name unix1 }} located at {{ file.path /Users/james/unix1 }}\n- The malicious binary attempted to access the user's keychain at {{ process.command_line /Users/james/unix1 /Users/james/library/Keychains/login.keychain-db TempTemp1234!! }}\n- Multiple alerts were generated for this malware execution chain",
    "mitreAttackTactics": [
      "Initial Access",
      "Execution",
      "Credential Access"
    ],
    "summaryMarkdown": "A malicious OneNote attachment was opened, leading to the execution of malware on {{ host.name 23466d50-b193-46cc-86f0-f6dd65902a73 }}. The malware was detected as it attempted to access sensitive system files.",
    "title": "Malware Execution from OneNote Attachment",
    "timestamp": "2025-03-25T03:16:20.526Z"
  },
  // ...
]
}
```
"""
````

(cherry picked from commit 1d457e4)
@kibanamachine kibanamachine merged commit 39af858 into elastic:8.x Mar 26, 2025
11 checks passed
@elasticmachine
Copy link
Contributor

💚 Build Succeeded

Metrics [docs]

✅ unchanged

cc @andrew-goldstein

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants