diff --git a/docs/README.md b/docs/README.md index 441d10f5787..a576306076f 100644 --- a/docs/README.md +++ b/docs/README.md @@ -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 "" >}}`, and the [Prompt Recipes](content/automation/api/prompt_recipes.md) page lists every prompt automatically. To add one, create `content/prompts/.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. diff --git a/docs/content/automation/api/prompt_recipes.md b/docs/content/automation/api/prompt_recipes.md new file mode 100644 index 00000000000..93e147cfab8 --- /dev/null +++ b/docs/content/automation/api/prompt_recipes.md @@ -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. + + +{{% prompt-index %}} diff --git a/docs/content/import_data/import_intro/reimport.md b/docs/content/import_data/import_intro/reimport.md index 4f12d16538f..903778339da 100644 --- a/docs/content/import_data/import_intro/reimport.md +++ b/docs/content/import_data/import_intro/reimport.md @@ -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 + + +{{< prompt "ci-reimport" >}} diff --git a/docs/content/prompts/_index.md b/docs/content/prompts/_index.md new file mode 100644 index 00000000000..7362dcd3b4d --- /dev/null +++ b/docs/content/prompts/_index.md @@ -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 +--- diff --git a/docs/content/prompts/ci-reimport.md b/docs/content/prompts/ci-reimport.md new file mode 100644 index 00000000000..8ac9793ed33 --- /dev/null +++ b/docs/content/prompts/ci-reimport.md @@ -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 ". 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/). diff --git a/docs/content/prompts/generic-findings-converter.md b/docs/content/prompts/generic-findings-converter.md new file mode 100644 index 00000000000..f25a49809a6 --- /dev/null +++ b/docs/content/prompts/generic-findings-converter.md @@ -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. diff --git a/docs/content/supported_tools/parsers/file/generic.md b/docs/content/supported_tools/parsers/file/generic.md index 456dd7795bb..07510410721 100644 --- a/docs/content/supported_tools/parsers/file/generic.md +++ b/docs/content/supported_tools/parsers/file/generic.md @@ -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 + + +{{< prompt "generic-findings-converter" >}} diff --git a/docs/layouts/shortcodes/prompt-index.html b/docs/layouts/shortcodes/prompt-index.html new file mode 100644 index 00000000000..ba2d6f0cf8e --- /dev/null +++ b/docs/layouts/shortcodes/prompt-index.html @@ -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 -}} diff --git a/docs/layouts/shortcodes/prompt.html b/docs/layouts/shortcodes/prompt.html new file mode 100644 index 00000000000..d86cecfcb95 --- /dev/null +++ b/docs/layouts/shortcodes/prompt.html @@ -0,0 +1,13 @@ +{{- /* + {{< prompt "" >}} shows the AI-assistant prompt kept in + content/prompts/.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 }}