Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,35 @@ def _product_signature(entry: dict[str, Any]) -> tuple[str, str]:
return (_package_identity(entry), str(entry.get("product") or ""))


#: The vendor Vulnogram's web editor fills in, hidden, on the one ``affected[]``
#: entry it requires (``custom/cve5/conf.js`` in apache/security-vulnogram).
EDITOR_DEFAULT_VENDOR = "Apache Software Foundation"

#: The ``CNA_private.state`` values of a record nobody has submitted for review yet.
#: Only in these states is an unfilled entry exempt from the product guard.
PLACEHOLDER_EXEMPT_STATES = frozenset({"RESERVED", "DRAFT"})


def _is_placeholder_entry(entry: Any) -> bool:
"""Return ``True`` for an ``affected[]`` entry nobody has filled in.

Allocation through the API stores no ``affected[]`` at all. A record
opened and saved in the web editor before the first push gets the one
entry the editor requires, with its default vendor and no product (an
empty product is dropped on save). That entry is not authored content:
no product, no package, and either no vendor or the editor's default.
"""
if not isinstance(entry, dict) or entry.get("product") or _package_identity(entry):
return False
vendor = str(entry.get("vendor") or "")
return vendor in ("", EDITOR_DEFAULT_VENDOR)


def _diff_affected_products(
current: list[dict[str, Any]],
new: list[dict[str, Any]],
*,
current_state: str | None = None,
) -> list[str]:
"""Return a list of human-readable diffs for product/packageName
changes between the current and new affected[] arrays.
Expand All @@ -191,16 +217,23 @@ def _diff_affected_products(
is read from ``packageURL`` or ``packageName``, whichever the entry
carries, so the two identifier shapes do not read as a rename.
Otherwise returns one line per dropped, added, or renamed signature so
the caller can decide whether to refuse or warn.
the caller can decide whether to refuse or warn. Unfilled entries the
web editor leaves in ``current`` are not authored content and are left
out (#1736, see :func:`_is_placeholder_entry`), but
only while ``current_state`` is one of :data:`PLACEHOLDER_EXEMPT_STATES`;
once the record has moved on, the guard compares them like any product.
"""
current_sigs = {_product_signature(entry) for entry in current if isinstance(entry, dict)}
skip_placeholders = current_state in PLACEHOLDER_EXEMPT_STATES
current_sigs = {
_product_signature(entry)
for entry in current
if isinstance(entry, dict) and not (skip_placeholders and _is_placeholder_entry(entry))
}
new_sigs = {_product_signature(entry) for entry in new if isinstance(entry, dict)}
if current_sigs == new_sigs:
return []
# First-time population (e.g. a freshly-allocated RESERVED record with an
# empty ``affected[]``) is not a product *change* — there is no prior
# signature to be renamed away from. Treat it as a non-diff so the guard
# does not force --allow-product-change for the normal first push.
# An empty ``affected[]`` is first-time population, not a product
# *change* — there is no prior signature to be renamed away from.
if not current_sigs:
return []
diffs: list[str] = []
Expand Down Expand Up @@ -254,7 +287,10 @@ def apply_merge_mode_guards(
current record and the new emission, raise
:class:`MergeModeRefused` with a diff so the caller can decide
whether the change is intentional (e.g. broadening the scope
to add a new package) or a regression.
to add a new package) or a regression. Replacing the unfilled
entry Vulnogram's web editor leaves (no product, no package, no
vendor or the editor's default) is exempt while the record is
still ``RESERVED`` or ``DRAFT``.

With ``forbid_promotion_to_public`` (the vetted-ops path always sets
it), a push that would move the record to ``PUBLIC`` from any other
Expand Down Expand Up @@ -363,6 +399,7 @@ def apply_merge_mode_guards(
diffs = _diff_affected_products(
current=_current_affected(current_doc),
new=_new_affected(merged),
current_state=current_state,
)
if diffs and not allow_product_change:
raise MergeModeRefused(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
**Merge mode (default on)** — before the POST, the script fetches
the record's current state and applies three safety nets against
the document about to be pushed: state-downgrade refusal,
references-by-URL merge, product/package-change refusal. See
references-by-URL merge, product/package-change refusal
(replacing the unfilled entry the web editor leaves, while the
record is still ``RESERVED`` or ``DRAFT``, is exempt). See
:mod:`vulnogram_api.merge_mode` for the full rules, and the
``--allow-state-downgrade`` / ``--replace-references`` /
``--allow-product-change`` / ``--full-replace`` flags below for the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -549,6 +549,7 @@ When the state fetch fails, pass `fetched_state: "unknown"`.
Any other outcome (an interrupted run) may or may not have saved: push again, which the idempotence note below makes safe.

For Vulnogram, the push merges into the live record and refuses to rename an affected product or package.
The first push after allocation needs no override: an allocated record has no `affected[]` yet, and the unfilled entry Vulnogram's web editor adds when someone saves the record first (no product, no package, its default vendor) is exempt while the record is still `RESERVED` or `DRAFT`.
Two explicit overrides exist; use them only after confirming with the user:

- `--replace-references` — replace `references[]` instead of keeping existing URLs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,35 @@ def _product_signature(entry: dict[str, Any]) -> tuple[str, str]:
return (_package_identity(entry), str(entry.get("product") or ""))


#: The vendor Vulnogram's web editor fills in, hidden, on the one ``affected[]``
#: entry it requires (``custom/cve5/conf.js`` in apache/security-vulnogram).
EDITOR_DEFAULT_VENDOR = "Apache Software Foundation"

#: The ``CNA_private.state`` values of a record nobody has submitted for review yet.
#: Only in these states is an unfilled entry exempt from the product guard.
PLACEHOLDER_EXEMPT_STATES = frozenset({"RESERVED", "DRAFT"})


def _is_placeholder_entry(entry: Any) -> bool:
"""Return ``True`` for an ``affected[]`` entry nobody has filled in.

Allocation through the API stores no ``affected[]`` at all. A record
opened and saved in the web editor before the first push gets the one
entry the editor requires, with its default vendor and no product (an
empty product is dropped on save). That entry is not authored content:
no product, no package, and either no vendor or the editor's default.
"""
if not isinstance(entry, dict) or entry.get("product") or _package_identity(entry):
return False
vendor = str(entry.get("vendor") or "")
return vendor in ("", EDITOR_DEFAULT_VENDOR)


def _diff_affected_products(
current: list[dict[str, Any]],
new: list[dict[str, Any]],
*,
current_state: str | None = None,
) -> list[str]:
"""Return a list of human-readable diffs for product/packageName
changes between the current and new affected[] arrays.
Expand All @@ -191,16 +217,23 @@ def _diff_affected_products(
is read from ``packageURL`` or ``packageName``, whichever the entry
carries, so the two identifier shapes do not read as a rename.
Otherwise returns one line per dropped, added, or renamed signature so
the caller can decide whether to refuse or warn.
the caller can decide whether to refuse or warn. Unfilled entries the
web editor leaves in ``current`` are not authored content and are left
out (#1736, see :func:`_is_placeholder_entry`), but
only while ``current_state`` is one of :data:`PLACEHOLDER_EXEMPT_STATES`;
once the record has moved on, the guard compares them like any product.
"""
current_sigs = {_product_signature(entry) for entry in current if isinstance(entry, dict)}
skip_placeholders = current_state in PLACEHOLDER_EXEMPT_STATES
current_sigs = {
_product_signature(entry)
for entry in current
if isinstance(entry, dict) and not (skip_placeholders and _is_placeholder_entry(entry))
}
new_sigs = {_product_signature(entry) for entry in new if isinstance(entry, dict)}
if current_sigs == new_sigs:
return []
# First-time population (e.g. a freshly-allocated RESERVED record with an
# empty ``affected[]``) is not a product *change* — there is no prior
# signature to be renamed away from. Treat it as a non-diff so the guard
# does not force --allow-product-change for the normal first push.
# An empty ``affected[]`` is first-time population, not a product
# *change* — there is no prior signature to be renamed away from.
if not current_sigs:
return []
diffs: list[str] = []
Expand Down Expand Up @@ -254,7 +287,10 @@ def apply_merge_mode_guards(
current record and the new emission, raise
:class:`MergeModeRefused` with a diff so the caller can decide
whether the change is intentional (e.g. broadening the scope
to add a new package) or a regression.
to add a new package) or a regression. Replacing the unfilled
entry Vulnogram's web editor leaves (no product, no package, no
vendor or the editor's default) is exempt while the record is
still ``RESERVED`` or ``DRAFT``.

With ``forbid_promotion_to_public`` (the vetted-ops path always sets
it), a push that would move the record to ``PUBLIC`` from any other
Expand Down Expand Up @@ -363,6 +399,7 @@ def apply_merge_mode_guards(
diffs = _diff_affected_products(
current=_current_affected(current_doc),
new=_new_affected(merged),
current_state=current_state,
)
if diffs and not allow_product_change:
raise MergeModeRefused(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
**Merge mode (default on)** — before the POST, the script fetches
the record's current state and applies three safety nets against
the document about to be pushed: state-downgrade refusal,
references-by-URL merge, product/package-change refusal. See
references-by-URL merge, product/package-change refusal
(replacing the unfilled entry the web editor leaves, while the
record is still ``RESERVED`` or ``DRAFT``, is exempt). See
:mod:`vulnogram_api.merge_mode` for the full rules, and the
``--allow-state-downgrade`` / ``--replace-references`` /
``--allow-product-change`` / ``--full-replace`` flags below for the
Expand Down
51 changes: 44 additions & 7 deletions tools/cve-tool-vulnogram/oauth-api/src/vulnogram_api/merge_mode.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,35 @@ def _product_signature(entry: dict[str, Any]) -> tuple[str, str]:
return (_package_identity(entry), str(entry.get("product") or ""))


#: The vendor Vulnogram's web editor fills in, hidden, on the one ``affected[]``
#: entry it requires (``custom/cve5/conf.js`` in apache/security-vulnogram).
EDITOR_DEFAULT_VENDOR = "Apache Software Foundation"

#: The ``CNA_private.state`` values of a record nobody has submitted for review yet.
#: Only in these states is an unfilled entry exempt from the product guard.
PLACEHOLDER_EXEMPT_STATES = frozenset({"RESERVED", "DRAFT"})


def _is_placeholder_entry(entry: Any) -> bool:
"""Return ``True`` for an ``affected[]`` entry nobody has filled in.

Allocation through the API stores no ``affected[]`` at all. A record
opened and saved in the web editor before the first push gets the one
entry the editor requires, with its default vendor and no product (an
empty product is dropped on save). That entry is not authored content:
no product, no package, and either no vendor or the editor's default.
"""
if not isinstance(entry, dict) or entry.get("product") or _package_identity(entry):
return False
vendor = str(entry.get("vendor") or "")
return vendor in ("", EDITOR_DEFAULT_VENDOR)


def _diff_affected_products(
current: list[dict[str, Any]],
new: list[dict[str, Any]],
*,
current_state: str | None = None,
) -> list[str]:
"""Return a list of human-readable diffs for product/packageName
changes between the current and new affected[] arrays.
Expand All @@ -191,16 +217,23 @@ def _diff_affected_products(
is read from ``packageURL`` or ``packageName``, whichever the entry
carries, so the two identifier shapes do not read as a rename.
Otherwise returns one line per dropped, added, or renamed signature so
the caller can decide whether to refuse or warn.
the caller can decide whether to refuse or warn. Unfilled entries the
web editor leaves in ``current`` are not authored content and are left
out (#1736, see :func:`_is_placeholder_entry`), but
only while ``current_state`` is one of :data:`PLACEHOLDER_EXEMPT_STATES`;
once the record has moved on, the guard compares them like any product.
"""
current_sigs = {_product_signature(entry) for entry in current if isinstance(entry, dict)}
skip_placeholders = current_state in PLACEHOLDER_EXEMPT_STATES
current_sigs = {
_product_signature(entry)
for entry in current
if isinstance(entry, dict) and not (skip_placeholders and _is_placeholder_entry(entry))
}
new_sigs = {_product_signature(entry) for entry in new if isinstance(entry, dict)}
if current_sigs == new_sigs:
return []
# First-time population (e.g. a freshly-allocated RESERVED record with an
# empty ``affected[]``) is not a product *change* — there is no prior
# signature to be renamed away from. Treat it as a non-diff so the guard
# does not force --allow-product-change for the normal first push.
# An empty ``affected[]`` is first-time population, not a product
# *change* — there is no prior signature to be renamed away from.
if not current_sigs:
return []
diffs: list[str] = []
Expand Down Expand Up @@ -254,7 +287,10 @@ def apply_merge_mode_guards(
current record and the new emission, raise
:class:`MergeModeRefused` with a diff so the caller can decide
whether the change is intentional (e.g. broadening the scope
to add a new package) or a regression.
to add a new package) or a regression. Replacing the unfilled
entry Vulnogram's web editor leaves (no product, no package, no
vendor or the editor's default) is exempt while the record is
still ``RESERVED`` or ``DRAFT``.

With ``forbid_promotion_to_public`` (the vetted-ops path always sets
it), a push that would move the record to ``PUBLIC`` from any other
Expand Down Expand Up @@ -363,6 +399,7 @@ def apply_merge_mode_guards(
diffs = _diff_affected_products(
current=_current_affected(current_doc),
new=_new_affected(merged),
current_state=current_state,
)
if diffs and not allow_product_change:
raise MergeModeRefused(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,9 @@
**Merge mode (default on)** — before the POST, the script fetches
the record's current state and applies three safety nets against
the document about to be pushed: state-downgrade refusal,
references-by-URL merge, product/package-change refusal. See
references-by-URL merge, product/package-change refusal
(replacing the unfilled entry the web editor leaves, while the
record is still ``RESERVED`` or ``DRAFT``, is exempt). See
:mod:`vulnogram_api.merge_mode` for the full rules, and the
``--allow-state-downgrade`` / ``--replace-references`` /
``--allow-product-change`` / ``--full-replace`` flags below for the
Expand Down
Loading