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
4 changes: 4 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,7 @@ Rules:
`content/metrics_reports/dashboards/PRO__custom_dashboards_api.md`: *"The Vue UI calls an
internal mirror of these endpoints under `/api/vue/dashboard_v2/`. Always automate against
the stable, customer-facing `/api/v2/dashboards/` paths documented here."*

## AI assistant prompts

A prompt for an AI assistant (the "... with an AI assistant" sections) lives in its own file under `content/prompts/`, never in the page that shows it. The page embeds it with `{{< prompt "<name>" >}}`, and the [Prompt Recipes](content/automation/api/prompt_recipes.md) page lists every prompt automatically. To add one, create `content/prompts/<name>.md` with a `title`, a `weight` and a `page` (the path of the page that embeds it), then add the shortcode to that page. The build fails if the shortcode names a prompt that does not exist, or if a prompt's `page` does not.
12 changes: 12 additions & 0 deletions docs/content/automation/api/prompt_recipes.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
---
title: "Prompt Recipes"
description: "Prompts that help an AI assistant write working DefectDojo pipelines, converters and scripts"
draft: false
weight: 9
---
Each prompt below gives an AI assistant (such as Claude, ChatGPT or Copilot) the DefectDojo details it usually gets wrong, so the pipeline, converter or script it writes works the first time. Fill in the bracketed values, paste the prompt into your assistant, and check the result before you run it.

Every prompt also appears on the page about its task, linked under its title.

<!-- Generated from content/prompts/. Add or edit a prompt there, not here. -->
{{% prompt-index %}}
5 changes: 5 additions & 0 deletions docs/content/import_data/import_intro/reimport.md
Original file line number Diff line number Diff line change
Expand Up @@ -175,3 +175,8 @@ Note that the /reimport API endpoint can both **extend an existing Test** (apply
When a `/reimport-scan` call also creates the Engagement (with `auto_create_context`), `deduplication_on_engagement` sets that new Engagement's deduplication scope. It never changes an existing Engagement, which is why the Reimport form does not offer it. To change the scope of an existing Engagement, edit **Deduplication on Engagement** on the Engagement itself.

To learn more about creating an automated CI/CD pipeline using DefectDojo, see our guide [here](/automation/api/api-v2-docs/).

## Build a pipeline with an AI assistant

<!-- The prompt lives in content/prompts/ci-reimport.md. Edit it there: the Prompt Recipes page shows it too. -->
{{< prompt "ci-reimport" >}}
13 changes: 13 additions & 0 deletions docs/content/prompts/_index.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
---
title: "Prompts"
# Each prompt in this folder is shown on its own page with the prompt
# shortcode and listed on the Prompt Recipes page (prompt-index shortcode).
# Nothing here is published as a page of its own.
build:
render: never
list: never
cascade:
build:
render: never
list: local
---
46 changes: 46 additions & 0 deletions docs/content/prompts/ci-reimport.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
---
title: "Reimport scans from a CI/CD pipeline"
# The page that embeds this prompt with {{< prompt "ci-reimport" >}}.
page: "/import_data/import_intro/reimport"
weight: 10
---
If you use an AI assistant (such as Claude, ChatGPT or Copilot) to write CI/CD jobs, give it the prompt below. Fill in the bracketed values first. The prompt lists the API details that assistants usually get wrong, so the job it writes keeps one Test up to date instead of creating a new Test on every run.

```text
Write a [GitHub Actions / GitLab CI / Jenkins / Azure DevOps] job that sends the
results of [Trivy] to DefectDojo after every build of the [main] branch.

Facts about the DefectDojo API. Follow them exactly:
- Base URL: [https://dojo.example.com]. Use only endpoints under /api/v2/.
Never use /api/vue/ paths; they reject API tokens.
- Authenticate with the header "Authorization: Token <key>". Read the key from a
CI secret named DD_API_KEY. Never print it.
- Use POST /api/v2/reimport-scan/ with multipart/form-data. Do NOT use
/api/v2/import-scan/: import creates a new Test every run, so findings pile up.
Reimport updates one Test and creates it on the first run.
- Send these fields:
scan_type = "[Trivy Scan]" (exact string from the DefectDojo
parser list; it is case-sensitive)
file = the report file
product_type_name = "[Engineering]"
product_name = "[my-service]"
engagement_name = "[CI/CD]"
test_title = "[Trivy]" (one Test per scanner)
auto_create_context = true (creates the product and engagement
on the first run)
branch_tag, commit_hash, build_id = from the CI environment variables
- The UI may call a product an "Asset" and a product type an "Organization".
The API still uses product_name and product_type_name.
- close_old_findings already defaults to true on reimport (findings missing from
the report are closed). Leave it on unless the scan covers only part of the
service.
- Success is HTTP 201. On any other status, print the response body and fail.
- On HTTP 409, another import into the same Test is still running: wait a minute
and retry once.
- Do not retry on a client timeout without checking first. The server may still
be processing the first request.

Also show the curl command on its own so I can test it locally first.
```

Check the result before you run it in your pipeline. In particular, confirm that `scan_type` matches the name on the tool's [parser page](/supported_tools/parsers/).
43 changes: 43 additions & 0 deletions docs/content/prompts/generic-findings-converter.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
---
title: "Convert an unsupported tool to Generic Findings Import"
# The page that embeds this prompt with {{< prompt "generic-findings-converter" >}}.
page: "/supported_tools/parsers/file/generic"
weight: 20
---
If DefectDojo has no parser for your tool, an AI assistant (such as Claude, ChatGPT or Copilot) can write a converter to the [Generic Findings Import JSON format](/supported_tools/parsers/file/generic/#json-format). Attach a sample of your tool's output to the conversation and give it the prompt below. The prompt lists the format rules that most often make an import fail.

Note that this use case can also be handled with DefectDojo's [Universal Parser](/import_data/pro/specialized_import/universal_parser/). Universal Parser allows you to import any XML, CSV or JSON file, and map the fields to Finding fields in

```text
Write a [Python 3] script that converts the attached [tool name] report into
DefectDojo's "Generic Findings Import" JSON format. The script reads a file path
argument and writes the converted JSON to stdout.

The output format. Follow it exactly:
- Top level: {"type": "[ToolName]", "findings": [ ... ]}.
Always set "type". DefectDojo names the Test Type "[ToolName] Scan (Generic
Findings Import)" from it. Without "type" the findings mix with every other
generic import on the instance.
- Each finding MUST have "title", "severity" and "description".
severity is one of Critical, High, Medium, Low, Info. Map the tool's own levels
to these explicitly. Any other value fails the whole import.
- Only use these optional keys. Any key not on this list fails the import with
"Not allowed fields are present":
date (YYYY-MM-DD), cwe (integer), cwes (list), cve, vulnerability_ids (list),
cvssv3 (vector with the "CVSS:3.1/" prefix), mitigation, impact, references,
file_path, line (integer), component_name, component_version,
fix_available (bool), fix_version, unique_id_from_tool, vuln_id_from_tool,
endpoints (list of URL strings), tags (list), static_finding (bool),
dynamic_finding (bool), active (bool), verified (bool)
The false-positive flag is "false_p", not "false_positive".
- Booleans must be JSON true/false, not strings.
- If the tool gives each issue a stable ID, put it in "unique_id_from_tool".
This is the most important field: DefectDojo uses it to recognize the same
finding across runs, so reimport does not close and recreate it when a line
number shifts.
- Do not invent values. Leave out a key rather than filling it with a placeholder.

After the script, list the tool fields that you could not map so I can review them.
```

The prompt lists only the keys a converter usually needs. The [Finding fields](/supported_tools/parsers/file/generic/#finding-fields) table has the full list. Import a small sample of the converted output into a test Product before you use the converter on real reports.
5 changes: 5 additions & 0 deletions docs/content/supported_tools/parsers/file/generic.md
Original file line number Diff line number Diff line change
Expand Up @@ -379,3 +379,8 @@ By default, DefectDojo identifies duplicate Findings using these [hashcode field
- line
- file path
- description

## Write a converter with an AI assistant

<!-- The prompt lives in content/prompts/generic-findings-converter.md. Edit it there: the Prompt Recipes page shows it too. -->
{{< prompt "generic-findings-converter" >}}
19 changes: 19 additions & 0 deletions docs/layouts/shortcodes/prompt-index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{{- /*
{{% prompt-index %}} lists every prompt in content/prompts/, in weight
order, each with a link to the page that embeds it (its "page" front
matter). Used on the Prompt Recipes page. It returns Markdown and is called
with {{% %}}, so its headings are part of the page and appear, with their
anchors, in the "On this page" list.
*/ -}}
{{- $s := site.GetPage "/prompts" -}}
{{- if not $s }}{{ $s = .Page.Sites.Default.GetPage "/prompts" }}{{ end -}}
{{- range $s.Pages.ByWeight }}
{{- $home := site.GetPage .Params.page }}
{{- if not $home }}{{ errorf "prompt %q: page %q not found; fix its \"page\" front matter" .File.Path .Params.page }}{{ end }}
## {{ .Title }}

From [{{ $home.Title }}]({{ $home.RelPermalink }})

{{ strings.TrimSpace .RawContent }}

{{ end -}}
13 changes: 13 additions & 0 deletions docs/layouts/shortcodes/prompt.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{{- /*
{{< prompt "<name>" >}} shows the AI-assistant prompt kept in
content/prompts/<name>.md. The Prompt Recipes page lists the same files
(prompt-index.html). A translated page without its own prompt file shows
the English one. docs.defectdojo.com is built in dojo-pro-docs, which keeps
a copy of this shortcode: change both together.
*/ -}}
{{- $name := .Get 0 -}}
{{- $path := printf "/prompts/%s" $name -}}
{{- $p := site.GetPage $path -}}
{{- if not $p }}{{ $p = .Page.Sites.Default.GetPage $path }}{{ end -}}
{{- if not $p }}{{ errorf "prompt %q not found: add content/prompts/%s.md (%s)" $name $name .Position }}{{ end -}}
{{ $p.Content }}
Loading