Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions docs/components/resolve-cli/sbom.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ Finally, an LLM is used to extract the vulnerable file and function from the nat

### Options
- `-o`, `--out` -- path for the output `vulnerabilities.json` (defaults to `<sbom>.vuln.json`)
- `-L`, `--llm-provider` `[{gemini,ollama,opencode}]` -- LLM backend used to extract the affected file and function from each CVE description. Omit it to skip extraction (those fields are reported as `UNKNOWN`); passing `-L` with no value uses `opencode`.
- `-L`, `--llm-provider` `[{claude,gemini,ollama,opencode}]` -- LLM backend used to extract the affected file and function from each CVE description. Omit it to skip extraction (those fields are reported as `UNKNOWN`); passing `-L` with no value uses `opencode`.
- `--id` `[ID ...]` -- only report the given vulnerability id(s)
- `--min-score` -- minimum CVSS v3 base score for a CVE to be included. When set, CVEs that have no v3 score are also excluded (by default they are included).

Expand All @@ -41,7 +41,13 @@ See the [SBOM example](../../examples/sbom.md) for an end-to-end walkthrough.

## LLM Providers

Affected-file/function extraction is optional; if you do not pass `-L`, those fields are left as `UNKNOWN` and no LLM is contacted. When enabled, the supported providers are Gemini, Ollama, and Opencode.
Affected-file/function extraction is optional; if you do not pass `-L`, those fields are left as `UNKNOWN` and no LLM is contacted. When enabled, the supported providers are Claude, Gemini, Ollama, and Opencode.

### Claude

To use Claude, the `claude` CLI ([Claude Code](https://docs.anthropic.com/en/docs/claude-code)) must be installed and authenticated, either through a prior `claude` login or by setting the `ANTHROPIC_API_KEY` environmental variable.

This method uses the Claude Code CLI's default model.

### Gemini

Expand Down
18 changes: 9 additions & 9 deletions docs/examples/sbom.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ resolve sbom example.spdx.json -o vulnerabilities.json -L ollama
```

!!! note
The lookup queries [NIST's NVD](https://nvd.nist.gov/) and [MITRE's CWE database](https://cwe.mitre.org/) over the network, so a run needs internet access, plus the chosen LLM provider (`gemini`, `ollama`, or `opencode`) installed and authenticated. Without `-L`, the CVEs are still reported, but `affected_file` and `affected_function` come back as `UNKNOWN`.
The lookup queries [NIST's NVD](https://nvd.nist.gov/) and [MITRE's CWE database](https://cwe.mitre.org/) over the network, so a run needs internet access, plus the chosen LLM provider (`gemini`, `ollama`, or `opencode`) installed and authenticated. Without `-L`, the CVEs are still reported, but `affected-file` and `affected-function` come back as `UNKNOWN`.

Under the hood the tool runs four steps (see the [component docs](../components/resolve-cli/sbom.md) for detail):

Expand All @@ -61,14 +61,14 @@ The tool writes a [`vulnerabilities.json`](../concepts/vulnerabilities-json.md)
{
"vulnerabilities": [
{
"cve_id": "CVE-2026-34085",
"cve_description": "fontconfig before 2.17.1 has an off-by-one error in allocation during sfnt capability handling, leading to a one-byte out-of-bounds write, and potentially a crash or code execution. This is in FcFontCapabilities in fcfreetype.c.",
"package_name": "fontconfig:fontconfig_project::fontconfig",
"package_version": "2.2.1",
"cwe_id": "193",
"cwe_name": "Off-by-one Error",
"affected_file": "fcfreetype.c",
"affected_function": "FcFontCapabilities"
"cve-id": "CVE-2026-34085",
"cve-description": "fontconfig before 2.17.1 has an off-by-one error in allocation during sfnt capability handling, leading to a one-byte out-of-bounds write, and potentially a crash or code execution. This is in FcFontCapabilities in fcfreetype.c.",
"package-name": "fontconfig:fontconfig_project::fontconfig",
"package-version": "2.2.1",
"cwe-id": "193",
"cwe-name": "Off-by-one Error",
"affected-file": "fcfreetype.c",
"affected-function": "FcFontCapabilities"
}
]
}
Expand Down
2 changes: 1 addition & 1 deletion resolve-cli/src/resolve/sbom/example_out.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"vulnerabilities":[{"cve_id":"CVE-2026-34085","cve_description":"fontconfig before 2.17.1 has an off-by-one error in allocation during sfnt capability handling, leading to a one-byte out-of-bounds write, and potentially a crash or code execution. This is in FcFontCapabilities in fcfreetype.c.","package_name":"fontconfig:fontconfig_project::fontconfig","package_version":"2.2.1","cwe_id":"193","cwe_name":"Off-by-one Error","affected_file":"fcfreetype.c","affected_function":"FcFontCapabilities"}]}
{"vulnerabilities":[{"cve-id":"CVE-2026-34085","cve-description":"fontconfig before 2.17.1 has an off-by-one error in allocation during sfnt capability handling, leading to a one-byte out-of-bounds write, and potentially a crash or code execution. This is in FcFontCapabilities in fcfreetype.c.","package-name":"fontconfig:fontconfig_project::fontconfig","package-version":"2.2.1","cwe-id":"193","cwe-name":"Off-by-one Error","affected-file":"fcfreetype.c","affected-function":"FcFontCapabilities"}]}
38 changes: 38 additions & 0 deletions resolve-cli/src/resolve/sbom/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,44 @@ def _query(self, payload: str) -> str:
return process.stdout.splitlines()[-1]


class Claude(LLM):
"""Shells out to the Claude Code CLI. Auth comes from ANTHROPIC_API_KEY or a prior `claude` login."""

def __init__(self, model: str | None = None):
import shutil

if shutil.which("claude") is None:
raise APIConnectionError() from FileNotFoundError("`claude` CLI not found on PATH")
self.model = model

def _query(self, payload: str) -> str:
import subprocess

# Web tools are pre-approved (as for Opencode) so the CLI never stops to
# ask for permission; everything else stays denied.
agent_command = ["claude", "-p", "--allowedTools", "WebFetch", "WebSearch"]
if self.model is not None:
agent_command += ["--model", self.model]

# The prompt goes over stdin: --allowedTools is variadic and would
# swallow a trailing positional prompt.
process = subprocess.run(
agent_command,
input=payload,
text=True,
stderr=subprocess.PIPE,
stdout=subprocess.PIPE,
)
if process.returncode != 0:
print(process.stderr)
raise LLMError(process.stderr or process.stdout)

lines = process.stdout.strip().splitlines()
if not lines:
raise LLMError("Empty response")
return lines[-1].strip().strip("`")


class Gemini(LLM):
def __init__(self, model: str = 'gemini-2.5-flash', **kwargs) -> None:
from google import genai
Expand Down
5 changes: 3 additions & 2 deletions resolve-cli/src/resolve/sbom/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def parse_args(argv: list[str] | None = None) -> argparse.Namespace:
"-L",
"--llm-provider",
nargs="?",
choices=["gemini", "ollama", "opencode"],
choices=["claude", "gemini", "ollama", "opencode"],
const="opencode",
default=None,
)
Expand Down Expand Up @@ -81,7 +81,7 @@ def output_json(vulns: list[Vulnerability], output_path: Path):
doc = VulnerabilityDocument(vulnerabilities=vulns)

with open(output_path, 'w') as f:
f.write(doc.model_dump_json(indent=2))
f.write(doc.model_dump_json(indent=2, by_alias=True))


def cve2vuln(
Expand Down Expand Up @@ -150,6 +150,7 @@ def main(argv: list[str] | None = None) -> int:
asyncio.run(dep_lookup(deps, **kwargs))

provider = {
"claude": llm.Claude,
"gemini": llm.Gemini,
"ollama": llm.Ollama,
"opencode": llm.Opencode,
Expand Down
9 changes: 8 additions & 1 deletion resolve-cli/src/resolve/sbom/schema/vuln_spec.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from typing import Annotated

from pydantic import BaseModel, Field
from pydantic import BaseModel, ConfigDict, Field

from resolve.sbom.schema.nist_api import CveId

Expand All @@ -14,6 +14,13 @@ class VulnerabilityDocument(BaseModel):


class Vulnerability(BaseModel):
# vulnerabilities.json uses hyphenated keys (e.g. "cve-id"), which is what
# reach, remediate, and CVEAssert read. Serialize with by_alias=True.
model_config = ConfigDict(
alias_generator=lambda name: name.replace("_", "-"),
populate_by_name=True,
)

cve_id: CveId
cve_description: str
package_name: str
Expand Down