diff --git a/docs/node-maintenance.md b/docs/node-maintenance.md index 82e7c89..1471e57 100644 --- a/docs/node-maintenance.md +++ b/docs/node-maintenance.md @@ -399,6 +399,7 @@ See the [tested versions](../node/runtime/toolchain.json). | --- | --- | | `validationScript` | Existing nonempty package script; default `"build"`. Names start with a letter or digit and contain only letters, digits, `:`, `_`, `.`, or `-`. | | `localPatches` | Project-local declarations identifying advisories mitigated by local patches. These are maintainer assertions, never inherited or counted as independently confirmed security fixes. See [local patches](#local-security-patches). | +| `advisoryNotes` | Project-local text keyed by GHSA ID explaining decisions such as deferral. Display only; findings and repair eligibility stay unchanged. See [advisory notes](#advisory-notes). | | `minimumReleaseAgeDays` | Minimum release cooldown in days; nonnegative integer, default `10`. pnpm workspace policy must be at least this strict. | | `maintenance.mode` | `"security-only"` or `"security-and-maintenance"`. A schedule object defaults to security-only unless a mode is supplied locally or inherited. | | `maintenance.upgradeScope` | Maximum routine direct upgrade level: `"patch"`, `"minor"` including patches, or `"major"` including both (default). Security fixes are handled separately. | @@ -468,6 +469,37 @@ Use a workflow revision whose `node/contract.json` includes `local_patches` support. Use `@v1` or update both immutable pins together; older version-6 revisions do not accept `localPatches`. +## Advisory notes + +Add context for an advisory in `.github/node-maintenance.json`: + +```json +{ + "advisoryNotes": { + "GHSA-5gmw-xhrv-c9v3": "Deferred: the affected worker feature is disabled in this project. Reassess before enabling it or changing the parent dependency." + } +} +``` + +Merge this field into the existing configuration. Up to 32 GHSA IDs are supported, +each with nonempty single-line plain text of at most 2048 characters. The existing +64 KiB configuration limit still applies. Formatting is displayed as text. Notes +stay local to the repository and are not inherited from shared defaults. + +Matching notes appear beside current package findings in audit and selected-repair +reports. They persist through report regeneration because they come from project +configuration. Notes are omitted when their advisory is absent; the configuration +entry remains for later matching audits. Review and remove stale notes yourself. + +A note explains a maintainer decision. It does not certify mitigation, suppress +the advisory, change severity or counts, prevent a repair, or count as a fix. +Use `localPatches` separately for actual local patch assertions. Notes are not +copied into raw audit evidence or each retained repair attempt. Configuration +is public project data and notes appear in published reports; do not include secrets. + +Use workflows whose `node/contract.json` declares `advisory_notes` support. Older +version-6 revisions reject this field. Adoption needs no new permissions. + ## Update or migrate an installation For an earlier Docusaurus installation, use the [migration checklist](node-migration.md). diff --git a/node/contract.json b/node/contract.json index 4c05e77..6d31ce9 100644 --- a/node/contract.json +++ b/node/contract.json @@ -74,6 +74,13 @@ "automatic_patch_removal": false, "notification": "one issue per repository for published official fixes" }, + "advisory_notes": { + "config_key": "advisoryNotes", + "inherited": false, + "maximum_notes": 32, + "maximum_characters_per_note": 2048, + "effect": "display only; findings and repair eligibility are unchanged" + }, "breaking_changes": { "previous_component": "docusaurus", "old_configuration": ".github/docusaurus.json", diff --git a/node/maintenance.md b/node/maintenance.md index df2b3d5..bbcc91c 100644 --- a/node/maintenance.md +++ b/node/maintenance.md @@ -67,6 +67,12 @@ evidence. It does not prove patch application or security effectiveness, remove raw findings, or count as a confirmed security fix. See [declaring local patches](../docs/node-maintenance.md#local-security-patches). +For decisions such as deferring an advisory, use project-local `advisoryNotes` +instead of declaring a patch. These plain-text notes accompany matching current +findings without changing evidence, severity, counts or repair eligibility. They +are not inherited or duplicated into repair history. See +[advisory notes](../docs/node-maintenance.md#advisory-notes). + Upgrade audits attempt security fixes first, then routine stable upgrades. `maintenance.upgradeScope` limits routine **direct** upgrades to `patch`, `minor` (including patches), or `major` (the default, including both). Restricted scopes diff --git a/node/runtime/advisory_notes.py b/node/runtime/advisory_notes.py new file mode 100644 index 0000000..7f446e0 --- /dev/null +++ b/node/runtime/advisory_notes.py @@ -0,0 +1,57 @@ +"""Display project-local context without changing advisory evidence or decisions.""" + +import html +import re +import unicodedata + +GHSA = r"GHSA-[a-z0-9]{4}-[a-z0-9]{4}-[a-z0-9]{4}" + + +def validate(value): + if not isinstance(value, dict) or len(value) > 32: + raise ValueError("advisoryNotes must be an object of at most 32 notes") + for advisory, text in value.items(): + if not isinstance(advisory, str) or not re.fullmatch(GHSA, advisory): + raise ValueError("advisoryNotes requires a GHSA identifier") + if ( + not isinstance(text, str) + or not text.strip() + or len(text) > 2048 + or any(unicodedata.category(c) in {"Cc", "Cs", "Zl", "Zp"} for c in text) + ): + raise ValueError( + "advisoryNotes values must be nonempty single-line Unicode text of at most 2048 characters" + ) + return value + + +def render(data, notes): + """Match exact GitHub advisory URLs and show each active note once.""" + validate(notes) + if not notes or not isinstance(data, dict): + return "" + reported = { + detail.get("url") + for vulnerability in data.get("vulnerabilities", {}).values() + for detail in vulnerability.get("via", []) + if isinstance(detail, dict) + } + rows = [] + for advisory, text in sorted(notes.items()): + if "https://github.com/advisories/" + advisory not in reported: + continue + # Encode formatting as text, including table separators and task markers. + escaped = re.sub( + r"[\\`*_\[\]~!|]", + lambda match: f"&#{ord(match[0])};", + html.escape(text), + ) + rows.append(f"- **{advisory}**: {escaped}") + if not rows: + return "" + return ( + "**Maintainer notes**\n\n" + "Project context only. Findings, severity and repair eligibility are unchanged.\n\n" + + "\n".join(rows) + + "\n\n" + ) diff --git a/node/runtime/configuration.py b/node/runtime/configuration.py index 57439b7..41e6735 100644 --- a/node/runtime/configuration.py +++ b/node/runtime/configuration.py @@ -10,11 +10,12 @@ SCHEDULING = runpy.run_path(str(Path(__file__).with_name("scheduling.py"))) LOCAL_PATCHES = runpy.run_path(str(Path(__file__).with_name("local_patches.py"))) +ADVISORY_NOTES = runpy.run_path(str(Path(__file__).with_name("advisory_notes.py"))) MAX_BYTES = 65536 MAX_SOURCES = 8 SHARED_KEYS = {"toolchain", "maintenance", "minimumReleaseAgeDays", "schedule"} -LOCAL_KEYS = {"directory", "validationScript", "localPatches"} +LOCAL_KEYS = {"directory", "validationScript", "localPatches", "advisoryNotes"} def json_object(data, location, max_bytes=MAX_BYTES): @@ -77,6 +78,8 @@ def validate_settings(config, location): raise ValueError(f"{location}: unknown configuration fields: {sorted(unknown)}") if "localPatches" in config: LOCAL_PATCHES["validate_declarations"](config["localPatches"]) + if "advisoryNotes" in config: + ADVISORY_NOTES["validate"](config["advisoryNotes"]) if "schedule" in config: SCHEDULING["validate_schedule"](config["schedule"]) if "defaults" in config: diff --git a/node/runtime/fleet.py b/node/runtime/fleet.py index d45462e..0c7c11c 100644 --- a/node/runtime/fleet.py +++ b/node/runtime/fleet.py @@ -521,6 +521,13 @@ def check_caller(root, config, selected, github, default_branch="main"): raise ValueError( "Pinned workflows do not support localPatches; update both workflow pins" ) + if ( + "advisoryNotes" in config + and contract.get("advisory_notes", {}).get("config_key") != "advisoryNotes" + ): + raise ValueError( + "Pinned workflows do not support advisoryNotes; update both workflow pins" + ) toolchain = CONFIGURATION["json_object"]( source.read("node/runtime/toolchain.json"), "pinned toolchain support" ).get("supported", {}) diff --git a/node/runtime/repair.py b/node/runtime/repair.py index d13d703..1a2cfd7 100644 --- a/node/runtime/repair.py +++ b/node/runtime/repair.py @@ -1025,7 +1025,17 @@ def report_rows(report): def cumulative_report( - history, expected, directory, selected, snapshot, candidate, before, after, fixed + history, + expected, + directory, + selected, + snapshot, + candidate, + before, + after, + fixed, + *, + advisory_notes=None, ): project = directory.relative_to(Path.cwd().resolve()).as_posix() state = ENGINE["dependency_state"](snapshot) @@ -1148,7 +1158,10 @@ def cumulative_report( "| Package | Update | Severity | Advisories | Action / blocker | Security evidence |\n| --- | --- | --- | --- | --- | --- |\n" + "\n".join(rows) ) - report += "\n\n" + ENGINE["history_marker"](record) + "\n" + report += "\n\n" + ENGINE["ADVISORY_NOTES"]["render"]( + after, {} if advisory_notes is None else advisory_notes + ) + report += ENGINE["history_marker"](record) + "\n" if len(report.encode()) > 1048576: raise ValueError("Cumulative history exceeds its bound; no artifact sealed") return report @@ -1448,6 +1461,7 @@ def prepare_candidate(expected, artifact): ): raise ValueError("Preparation requires a clean checkout of the expected head") directory, selected, snapshot = project_context() + config = PROJECT["CONFIGURATION"]["local_configuration"](root) history = native_history(expected, directory, snapshot) deadline = time.monotonic() + 40 * 60 before = ENGINE["audit"](directory, deadline=deadline) @@ -1503,7 +1517,16 @@ def prepare_candidate(expected, artifact): ) validate_envelope(envelope, expected, envelope["project_directory"]) report = cumulative_report( - history, expected, directory, selected, snapshot, candidate, proof, after, fixed + history, + expected, + directory, + selected, + snapshot, + candidate, + proof, + after, + fixed, + advisory_notes=config.get("advisoryNotes", {}), ) if artifact.resolve() != artifact or artifact.is_relative_to(root): raise ValueError("Candidate artifacts must be outside the project checkout") diff --git a/node/runtime/templates/dependency_audit.py b/node/runtime/templates/dependency_audit.py index 8dd1b2f..bb2ed9e 100644 --- a/node/runtime/templates/dependency_audit.py +++ b/node/runtime/templates/dependency_audit.py @@ -21,6 +21,7 @@ import yaml LOCAL_PATCHES = runpy.run_path(str(Path(__file__).parents[1] / "local_patches.py")) +ADVISORY_NOTES = runpy.run_path(str(Path(__file__).parents[1] / "advisory_notes.py")) NODE_RELEASES = runpy.run_path(str(Path(__file__).parents[1] / "node_releases.py")) HISTORY = runpy.run_path(str(Path(__file__).parents[1] / "history.py")) REPAIR_CHOICES = runpy.run_path(str(Path(__file__).parents[1] / "repair_choices.py")) @@ -3270,6 +3271,7 @@ def prepare( maintenance_mode="security-and-maintenance", upgrade_scope="major", local_patches=None, + advisory_notes=None, validate_only=False, prepare_only=False, platform=None, @@ -3298,6 +3300,9 @@ def prepare( "Valid manifest, one deployment lockfile and package-manager policy are required" ) declared_patches = LOCAL_PATCHES["validate_declarations"](local_patches or []) + advisory_notes = ADVISORY_NOTES["validate"]( + {} if advisory_notes is None else advisory_notes + ) scripts = initial_snapshot[2].get("scripts", {}) if ( not isinstance(validation_script, str) @@ -3992,6 +3997,7 @@ def published_patch_versions(specifier, *, all_versions=False): ) if isinstance(after, str): report += f"{after}\n\n" + report += ADVISORY_NOTES["render"](after, advisory_notes) report += LOCAL_PATCHES["render"](patch_report) if initial_ids is not None and remaining_ids is not None: new_count = len(new_ids) @@ -4479,11 +4485,18 @@ def main() -> None: or installed_manager.stdout.strip() != record["manager_version"] ): raise ValueError("Installed toolchain differs from sealed evidence") + project = runpy.run_path(str(Path(__file__).parents[1] / "project.py")) + config = ( + project["CONFIGURATION"]["local_configuration"](Path.cwd()) + if (Path.cwd() / ".github/node-maintenance.json").exists() + else {} + ) report = prepare( directory, validation=validation, validate_only=True, validation_script=record["validation_script"], + advisory_notes=config.get("advisoryNotes", {}), ) if node_plan is not None: node_proposal["verify_candidate"](Path.cwd().resolve(), node_plan) @@ -4508,6 +4521,7 @@ def main() -> None: return try: patches = [] + advisory_notes = {} node_plan = None if args.node_update is not None: node_proposal = runpy.run_path( @@ -4525,6 +4539,7 @@ def main() -> None: raise ValueError("Selected directory differs from the resolved project") resolved = json.loads(args.resolved_config.read_bytes()) patches = resolved["configuration"].get("localPatches", []) + advisory_notes = resolved["configuration"].get("advisoryNotes", {}) report = prepare( directory, validation=validation, @@ -4533,6 +4548,7 @@ def main() -> None: maintenance_mode=args.maintenance_mode, upgrade_scope=args.upgrade_scope, local_patches=patches, + advisory_notes=advisory_notes, validate_only=args.validate_only, prepare_only=args.prepare_only, platform=NODE_RELEASES["collect"](node_plan), diff --git a/node/tests/test_advisory_notes.py b/node/tests/test_advisory_notes.py new file mode 100644 index 0000000..eb8cf82 --- /dev/null +++ b/node/tests/test_advisory_notes.py @@ -0,0 +1,199 @@ +"""Maintainer context persists without suppressing findings or duplicating history.""" + +import copy +import json +import runpy +import subprocess +import sys +from pathlib import Path + +import pytest +from test_local_patches import evidence +from test_dependency_audit_publisher import prepared_validation as prepared_validation +from test_dependency_audit_publisher import sealed_history as sealed_history +from test_node_standard import audit_module +from test_node_standard import npm_project as npm_project +from test_node_standard import pnpm_project as pnpm_project +from test_selected_repairs import ENGINE, REPAIR, repair_audit, repair_request +from test_selected_repairs import cumulative_candidate as cumulative_candidate +from test_shared_defaults import configure, configuration, public_sources +from test_shared_defaults import site as site + +ROOT = Path(__file__).parents[2] +NOTES = runpy.run_path(str(ROOT / "node/runtime/advisory_notes.py")) +ID = "GHSA-2345-6789-cfgh" +TEXT = "Deferred pending an upstream release; revisit before enabling workers." + + +@pytest.mark.parametrize( + "value", + [ + None, + [], + "text", + {"CVE-2026-1234": TEXT}, + {ID: None}, + {ID: 1}, + {ID: ""}, + {ID: " "}, + {ID: "x" * 2049}, + {ID: "two\nlines"}, + {ID: "two\rlines"}, + {ID: "tab\there"}, + {ID: "\x7f"}, + {ID: "\ud800"}, + {ID: "\u0085"}, + {ID: "\u2028"}, + {ID: "\u2029"}, + {f"GHSA-aaaa-bbbb-{i:04d}": TEXT for i in range(33)}, + ], +) +def test_invalid_notes_fail_configuration_validation(value): + with pytest.raises(ValueError, match="advisoryNotes"): + configuration["validate_settings"]({"advisoryNotes": value}, "project") + + +def test_valid_limits_and_duplicate_key_rejection(): + value = {f"GHSA-aaaa-bbbb-{i:04d}": "🧪" * 2048 for i in range(32)} + assert NOTES["validate"](value) == value + with pytest.raises(ValueError, match="duplicate JSON key"): + configuration["json_object"]( + ('{"advisoryNotes":{"' + ID + '":"first","' + ID + '":"second"}}').encode(), + "project", + ) + + +@pytest.mark.parametrize("local", [False, True]) +def test_notes_are_project_local_and_not_inherited(site, monkeypatch, local): + root, _ = site + public_sources( + monkeypatch, + { + ("owner/settings", "defaults.json"): { + "advisoryNotes": {ID: "Other project's decision."} + } + }, + ) + if local: + configure(root, advisoryNotes={ID: TEXT}) + result = configuration["load_configuration"](root) + assert result.get("advisoryNotes", {}) == ({ID: TEXT} if local else {}) + + +@pytest.mark.parametrize("source", ["npm", "pnpm"]) +def test_render_exact_active_advisories_once_without_mutating_evidence(source): + data = evidence(source) + data["vulnerabilities"]["duplicate-parent"] = copy.deepcopy( + data["vulnerabilities"]["renderer"] + ) + original = copy.deepcopy(data) + notes = {ID: TEXT, "GHSA-aaaa-bbbb-cccc": "Not currently reported."} + rendered = NOTES["render"](data, notes) + assert rendered.count(TEXT) == rendered.count(ID) == 1 + assert "Not currently reported" not in rendered + assert data == original + assert NOTES["render"]("Audit unavailable", notes) == "" + for url in ( + "https://example.com/" + ID, + "https://github.com/advisories/" + ID + "-extra", + ): + for vulnerability in data["vulnerabilities"].values(): + vulnerability["via"][0]["url"] = url + assert NOTES["render"](data, notes) == "" + + +def test_note_markup_cannot_add_controls_tables_or_hidden_history(): + text = " [x](https://example.com) | `fix` ![image](x) &" + result = NOTES["render"](evidence(), {ID: text}) + assert "