Generate cve json

From apache/magpie · View interactive version

Generate cve json is an AI agent skill from the GitHub repository apache/magpie. <!-- SPDX-License-Identifier: Apache-2.0

How to use this skill

Skill file

<!-- SPDX-License-Identifier: Apache-2.0

https://www.apache.org/licenses/LICENSE-2.0 -->

<!-- START doctoc generated TOC please keep comment here to allow auto update -->

<!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE -->

Table of Contents generated with DocToc

<!-- END doctoc generated TOC please keep comment here to allow auto update -->

<!-- Licensed to the Apache Software Foundation (ASF) under one

or more contributor license agreements. See the NOTICE file

distributed with this work for additional information

regarding copyright ownership. The ASF licenses this file

to you under the Apache License, Version 2.0 (the

"License"); you may not use this file except in compliance

with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing,

software distributed under the License is distributed on an

"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY

KIND, either express or implied. See the License for the

specific language governing permissions and limitations

under the License. -->

generate-cve-json

Small Python project that generates a CVE 5.x JSON record from an

<tracker> tracking issue, ready to paste into the Vulnogram

#source tab of the ASF CVE tool.

The behavioural contract and the security-process context live in

CODE0. This README covers the local-setup and test

workflow for the project itself.

Run

From the framework's root (this repository when running standalone;

the .apache-magpie/ snapshot path inside an adopting tracker repo):

uv run --project tools/cve-tool-vulnogram/generate-cve-json generate-cve-json <ISSUE-NUMBER> [options]

Skill files reference the same invocation via the <framework>

placeholder so the path resolves in either context:

uv run --project <framework>/tools/cve-tool-vulnogram/generate-cve-json generate-cve-json <ISSUE-NUMBER>

<framework> substitutes to .apache-magpie/ in

adopting projects and to . (the repository root) in framework

standalone — see the placeholder convention in

CODE0.

Equivalent forms:

# as a module
uv run --project <framework>/tools/cve-tool-vulnogram/generate-cve-json python -m generate_cve_json <ISSUE-NUMBER>

# from inside the project dir
cd <framework>/tools/cve-tool-vulnogram/generate-cve-json
uv run generate-cve-json <ISSUE-NUMBER>

Flags are documented in generate-cve-json --help and in CODE1.

The body is normalised in memory with CODE0's normalise before any field is read.

A field repeated with different values exits 2 with the field name and heading line numbers, never a guess.

--report-json <path> writes normalisation_changes, needs_decision and missing_required (no body text) for the calling skill to act on.

A credit line that may join several people adds a non-blocking joined-credits entry to normalisation_changes, with the field and the line inside it.

--baseline <record.json> takes the live record of a published CVE: a value the body owns comes from the body, and everything else keeps its published value, so a regeneration changes only what the body changed.

Without it the output is unchanged, so new records keep the generator's current format.

Configuration

Every project-specific value comes from one TOML file, cve-json-config.toml.

The framework ships no default: an adopter writes its own.

The test fixture at CODE0 describes a fictional project and must not be copied as a starting point.

Where the file is looked up

The generator takes the first location that applies:

  1. The path given with --config <path>.
  2. The path in the CVE_JSON_CONFIG environment variable.
  3. .apache-magpie-overrides/tools/cve-tool-vulnogram/cve-json-config.toml, relative to the current directory: the committed, project-wide copy.
  4. .apache-magpie-overrides/tools/vulnogram/cve-json-config.toml, the location before the tool directory was renamed.

It is read with a warning asking you to move the file.

  1. tools/cve-tool-vulnogram/cve-json-config.toml in the personal layer, for a maintainer whose project has not committed one.

The personal layer is <git-common-dir>/apache-magpie/ in a repository that has not adopted Magpie (then a legacy in-tree .apache-magpie-local/), and .apache-magpie-local/ in one that has (then, in a linked worktree, the main checkout's) — see CODE3.

Locations 4 and 5 are consulted only when neither --config nor CVE_JSON_CONFIG is set.

A path given by either is used as-is, and the run fails if the file does not exist.

When nothing is found the generator exits with an error listing these options.

Keys

Keys marked required have no default: a missing one stops the generator.

The --repo, --vendor, --product, --package-name, --collection-url, --org-id and --cve-tool-url flags override the matching value for a single run.

| Key | Type | Required | Default | Meaning |

|---|---|---|---|---|

| [meta].tracker_repo | string | required | — | The tracker's owner/name slug: the default --repo, and its owner segment filters tracker URLs out of references[]. |

| [meta].generator_tag | string | required | — | Written to the record's x_generator.engine, so a reader can tell which tool produced it. |

| [meta].skill_source_url | string | optional | https://github.com/<tracker_repo> | Link to the generator printed in the CVE JSON comment it attaches to the tracker. |

| [meta].cve_tool_url | string | optional | https://cveprocess.apache.org | Base URL of the CVE tool the project publishes through. Used for the CVE link in the attached comment, the paste hint, and the host filtered out of references[]; a non-ASF adopter sets its own tool's URL. A bare host is accepted, with https:// assumed. |

| [product].vendor | string | required | — | affected[].vendor. |

| [product].default_product | string | required | — | affected[].product for an Affected versions line that names no known package. |

| [product].default_package_name | string | required | — | The package name for such a line. |

| [product].default_collection_url | string | required | — | Where the packages are distributed (https://pypi.python.org, say); also the source a purl type is derived from. |

| [product].purl_type | string | optional | derived from default_collection_url | The package-url type (pypi, npm, maven, …). Derived for PyPI, npm, crates.io, RubyGems and NuGet hosts; "none" emits no purl and falls back to the collectionURL / packageName pair. |

| [product].purl_namespace | string | optional | "" | The purl namespace for types that need one (a Maven groupId, a Composer vendor, a Go module prefix). Ignored for types that have none; a type that requires one gets no purl without it. |

| [cna].org_id | string (UUID) | required | — | The CNA's UUID, written to cveMetadata.assignerOrgId and providerMetadata.orgId. No default on purpose, so a project outside the ASF never inherits the ASF's id. ASF projects copy cve_authority.vulnogram.asf_org_id from CODE4; only the generated record uses it, never CVE allocation. |

| [cna_private].project_url | string | optional | "" | CNA_private.projecturl in the record. |

| [cna_private].owner | string | optional | "" | CNA_private.owner — the project's short name in the CVE tool. |

| [cna_private].users_list | string | optional | "" | CNA_private.userslist — the project's users mailing list. |

| [packages].package_pattern | string (regex) | required | — | Matches a full package name. Named groups: package (the name), project (optional sub-project directory name), rest (optional; the version range after the name). |

| [packages].top_level_name | string | required | — | The top-level package name. |

| [packages].top_level_product | string | required | — | Its product name; also stripped as a prefix from the issue title. |

| [packages].project_product_template | string | required | — | Product name for a sub-project package, with {display} replaced by its display name. |

| [packages.project_display_map] | table of string → string | required (may be empty) | — | Sub-project directory name → display name. An unlisted name is title-cased word by word (pop-corn → Pop Corn). |

| [packages.overrides."<package>"] | table | optional | none | Per-package exceptions for a package outside the main ecosystem. Any of collection_url, purl_type and product; what it omits falls through to the values above. |

| [workflow].release_vote_gating | boolean | optional | false | When true, a complete record moves from DRAFT to REVIEW only while a release vote is running. |

| [workflow].rc_voting_label | string | optional | "rc voting" | The tracker label that marks a running release vote; read only when gating is on. |

| [workflow].forward_state_labels | array of strings | optional | ["fix released", "announced - emails sent", "announced", "vendor-advisory ready"] | Tracker labels meaning the release has shipped, so the vote gate no longer applies. |

| [discovery].internal_markers | array of strings | optional | [] | Case-insensitive text that marks an internal find (your own scanner's name, say) in the Security mailing list thread or Reporter credited as field; a hit sets source.discovery to INTERNAL. |

Minimal example

Every required key, for a project shipping one package to PyPI:

[meta]
tracker_repo = "example-org/example-security"
generator_tag = "example-org/generate-cve-json"

[product]
vendor = "Example Foundation"
default_product = "Example"
default_package_name = "example"
default_collection_url = "https://pypi.python.org"

[cna]
org_id = "00000000-0000-0000-0000-000000000000"  # your CNA's UUID

[packages]
package_pattern = '^(?P<package>example)(?:\s+(?P<rest>.*))?$'
top_level_name = "example"
top_level_product = "Example"
project_product_template = "Example {display}"

[packages.project_display_map]

The fixture linked above shows the optional [cna_private], [workflow] and [discovery] tables in use.

Record a published CVE in the project's security records — `advisory-records`

A second console script in the same project.

After the advisory is public, it proposes adding the CVE to the project's own published security records:

a site repository the project keeps over Git or Subversion.

It prints the file change and the CODE0 commands that would publish it (plus gh pr create with --publish pull-request), and runs no VCS command;

--apply writes the file change and nothing else (with --publish pull-request, also the pull-request body file).

security-issue-sync calls it from its closed-bucket scan and runs the commands only after the user confirms them

(see CODE0).

Two layouts, chosen with --layout:

| Layout | What changes | Example of a project laid out this way |

|---|---|---|

| cve-json-file | --path (e.g. content/security/json/{cve_id}.json) gets the CVE 5.x record generate-cve-json --output wrote, without the CNA tool's CNA_private block unless --keep-cna-private | Apache HTTP Server's site repository, which builds its vulnerability pages from these files |

| release-page | the entry is inserted into the page for the fixed release's line (--path xdocs/security-{line}.xml, the line being the first --release-line-parts version components), in the section named by --section-name (default Fixed in {product} {version}); a missing section is created in newest-first order | Apache Tomcat's site, one xdocs/security-<line>.xml page per release line |

The release-page templates are files: --entry-template and --section-template

(defaults: the shipped examples in CODE0,

an XML page with <section name="..." rtext="<release date>"> sections and <p> entries carrying a <cve> element and <hashlink> fix commits).

--format markdown switches to the Markdown examples: sections are headings at the level of the section template's first line.

Placeholders are {name} only; an unknown one is an error.

Entry: {impact} {title} {cve_id} {description} {fix_commits} {fix_commit_noun} {reported_date} {public_date} {affects} {product} {version} {release_date} {line}.

Section: {section_name} {release_date} {version} {line} {product}, and a line holding only {entries}.

An XML entry template must carry {cve_id} as the whole text of an element or a whole attribute value: that is how a re-run finds the entry.

Behaviour that does not depend on configuration:

and the record carries a vendor-advisory reference — the condition sync uses for the "CVE is live" step.

one recorded under a different release section is refused rather than duplicated.

identifiers are validated (CVE ID, versions, dates, commit hashes), and a rendered XML entry must be well-formed.

and the change is a splice that keeps the page's formatting, comments, entity references and line endings.

--fix-commit (added to the commits read from the record's patch references), --fixed-in, --affects VERSION=TEXT;

--public-date defaults to the date cve.org published the record.

A template placeholder with no value is refused with the flag that supplies it.

On Subversion there is no branch or push, and the commit publishes.

A missing working copy yields one checkout command (exit 4).

clean, branch, update, new-branch <--pr-branch>, the --apply run, stage, diff --cached, commit -m,

push <--fork-remote> <branch>, switch <--branch>, then gh pr create --repo <--pr-repo> --base <--branch> --head <fork owner>:<branch> --title … --body-file ….

--fork owner/name is required; --pr-repo defaults to the owner/name of a GitHub --repository URL,

--pr-branch to advisory-records/{cve_id}, --pr-title to the commit message, --fork-remote to fork.

The body lists the changed file(s), the date cve.org published the record and the record's vendor-advisory URL, never tracker text;

--apply writes it to --pr-body-file (default: <CVE-ID>-pull-request.md beside --record), and the JSON output carries it under pull_request.

The gh command starts with MAGPIE_ALLOW_SECURITY_LANG=1: the title and body name the CVE, which agent-guard's security-language guard otherwise refuses,

and the planner prints the command only past its publication gate

(see CODE0).

uv run --project <framework>/tools/cve-tool-vulnogram/generate-cve-json advisory-records \
  --layout release-page --working-copy ~/code/foo-site --path 'xdocs/security-{line}.xml' \
  --record /tmp/CVE-2026-00001.json --cve-org-state PUBLISHED --date-published 2026-04-02 \
  --reported-date 2026-02-14 --release-date 9.0.99=2026-03-30

Exit codes: 0 proposal (or unchanged, or applied), 2 usage or configuration error, 3 refused, 4 working copy missing.

Test

cd tools/cve-tool-vulnogram/generate-cve-json
uv run --group dev pytest

Lint / type-check

cd tools/cve-tool-vulnogram/generate-cve-json
uv run --group dev ruff check src tests
uv run --group dev ruff format --check src tests
uv run --group dev mypy

The prek hooks configured in .pre-commit-config.yaml at the

repository root run ruff check, ruff format --check, and mypy

on the project files automatically on every commit that touches them.

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.