specification icon indicating copy to clipboard operation
specification copied to clipboard

[FEATURE]: enum-value-formatting: harden meta:enum handling and issue paths

Open Mehrn0ush opened this issue 9 months ago • 1 comments

Describe the feature

Harden tools/src/main/js/linter/checks/enum-value-formatting.check.js so meta:enum handling is deterministic and lint output is accurate/noise-free (especially for edge-case inputs).

Use-cases

  • Schemas that correctly use meta:enum should not trigger false positives (e.g., “missing description” when the key exists).
  • Schemas with malformed meta:enum (wrong type, inherited properties) should produce a clear error instead of silent/incorrect behavior.
  • Reports should point to the correct location (meta:enum paths), and duplicate enum literals should not generate duplicate issues.

Scope / Out of scope

  • Scope: this single check file only.
  • Out of scope: changing the public API/config of the linter; adding new dependencies.

Possible solutions

Proposed changes (all within the check):

  1. Use own-property detection for meta:enum on the parent:

    • Replace 'meta:enum' in parent with Object.prototype.hasOwnProperty.call(parent, 'meta:enum') to avoid consulting the prototype chain (hardens the check against prototype-chain manipulation, including prototype-pollution scenarios).
  2. Validate meta:enum type before using it:

    • Require a plain object (non-null object, not array, prototype is Object.prototype or null).
    • If present but invalid, emit one ERROR:
      • Message: meta:enum must be a plain object mapping enum values to descriptions.
      • Context: actualType (array or typeof).
  3. Fix coverage logic:

    • Replace !metaEnum[value] with !Object.prototype.hasOwnProperty.call(metaEnum, value) to test key presence only.
    • Avoid counting inherited keys as “present”.
  4. Fix path reporting:

    • Avoid literal "undefined" / "null" paths by using a safe fallback for paths.
    • Derive a single metaEnumBasePath by replacing trailing .enum with .meta:enum (and handle root / fallback cases).
    • Report “missing description” at the meta:enum location, not the enum array.
  5. De-duplicate enum-value checks:

    • Iterate over unique string values (Set) so duplicate enum literals don't emit duplicate issues.

Additional context

  • File: tools/src/main/js/linter/checks/enum-value-formatting.check.js
  • Current implementation: https://github.com/CycloneDX/specification/blob/2.0-dev/tools/src/main/js/linter/checks/enum-value-formatting.check.js

Mehrn0ush avatar Feb 14 '26 12:02 Mehrn0ush

closed by https://github.com/CycloneDX/specification/pull/821

jkowalleck avatar Aug 24 '26 15:08 jkowalleck