Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Report Yarn v3/v4 patches as pedigree rather than components #784

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

taylormadore
Copy link
Contributor

Yarn has a patch protocol for the package patching feature. Patches should not be reported as independent Components in the SBOM, but should instead be reported as pedigree for the patched "regular" package Component.

Maintainers will complete the following section

  • Commit messages are descriptive enough
  • Code coverage from testing does not decrease and new code is covered
  • Docs updated (if applicable)
  • Docs links in the code are still valid (if docs were updated)

Note: if the contribution is external (not from an organization member), the CI
pipeline will not run automatically. After verifying that the CI is safe to run:

In yarn v4, optional, builtin patches are now denoted with the prefix
`optional!`. Handle this in addition to the yarn v3 prefix for the same

Signed-off-by: Taylor Madore <[email protected]>
Adds an optional Pedigree for the Component model according to:
https://cyclonedx.org/docs/1.6/json/#components_items_pedigree_patches

For the PatchDiff model, provide a URL but not a text diff in the SBOM
since it is not required by the schema.

Signed-off-by: Taylor Madore <[email protected]>
Instead of reporting yarn patches as independent Components in the SBOM,
report them instead as Pedigree for the parent, non-patch Component.

Yarn has the concept of "builtin" patches that are applied by yarn
itself to make certain features of yarn work. These are currently ignored
and not reported.

Signed-off-by: Taylor Madore <[email protected]>
@@ -28,6 +28,25 @@ class ExternalReference(pydantic.BaseModel):
type: Literal["distribution"] = "distribution"


class PatchDiff(pydantic.BaseModel):
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The CycloneDX schema offers the option of a text diff for the patch, but it is not required. I opted not to include so as not to clutter the SBOM. Let me know if you disagree.

"""Map locators for dependencies that get patched to their Pedigree."""
pedigree_mapping: dict[Locator, Pedigree] = {}
for patch_locator in patch_locators:
# Filter out builtin patches
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Builtin patches are applied by Yarn itself and tied to a specific version of Yarn. They are used to make certain features of the package manager work correctly: example.

Do we want to report these?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant