Skip to content

fix(bear): BOM-root self-skip never matched - exact purl instead of regex-in-substring - #37

Open
taleodor-claude wants to merge 4 commits into
mainfrom
2026-08-root-self-skip-never-matched
Open

fix(bear): BOM-root self-skip never matched - exact purl instead of regex-in-substring#37
taleodor-claude wants to merge 4 commits into
mainfrom
2026-08-root-self-skip-never-matched

Conversation

@taleodor-claude

Copy link
Copy Markdown
Contributor

Problem

addMetadataComponentToSkipPatterns appended .*<name>.* to skipPatterns — regex syntax fed into shouldSkipPurl, which matches by substring (strings.Contains), never as a regex. A substring can only match a purl containing the literal characters .*, so the BOM-root self-skip has never fired: the root component was sent to BEAR for enrichment as if it were one of its own dependencies.

Fix

Register the metadata component's full purl for an exact (case-insensitive) match in a new rootSkipPurls list checked by shouldSkipPurl ahead of the substring patterns. Exact rather than substring is deliberate, and the choice is documented on the var:

  • a substring of the root's purl would also skip other versions of the same package appearing as real dependencies (pkg:npm/a@1.0 is a substring of pkg:npm/a@1.0.1);
  • a substring of just the name would skip every component whose purl merely contains it (app vs application).

--skipPattern substring semantics are unchanged. The purl parse (previously used only to extract the name) is gone, along with the now-unused packageurl-go import in this file.

Found during review of relizaio/rearm#288 (rebom built-in skip patterns); backend wiring to follow separately.

Verification

  • 4 new tests in cmd/bear_test.go: exact match (incl. case-insensitivity), the two over-skip cases above, missing-metadata tolerance, and unchanged --skipPattern substring behavior.
  • go build ./..., go test ./... all green, go vet clean.

🤖 Generated with Claude Code

Claude Code (ReARM Agent) and others added 4 commits July 28, 2026 01:44
… match

Two bugs in the bitnami / tag-as-digest path, both reachable from a plain
`devops replacetags` run.

An image block written as separate registry / repository / tag keys is
claimed by validateAndParseBitnamiLines, which then only emits lines when
it found a substitution for that image. With no match it returned an
empty slice while still reporting the block as handled, so the caller
took it at its word and the entire block vanished from the output --
comments, pullPolicy, pullSecrets and all. It is silent, and the file
still parses afterwards, so it surfaces later as the chart quietly
falling back to whatever the subchart ships.

That is not hypothetical: running replacetags over the ReARM chart's own
values with a tag source that happens not to carry the postgres image
drops 21 lines of postgresql.image. Any chart processed with a partial
tag source is exposed.

Such a block is now handed back unclaimed, so it goes through the normal
line-by-line path like any other content -- preserved, and still open to
property and secret resolution.

Second, a source reference carrying a digest but no tag produced
`tag: @sha256:...`, which is not a valid reference. Charts that take a
digest through the tag field accept a bare `sha256:...`, so that is what
is written when there is no tag to combine.

Both new tests fail without the fix. The existing nine still pass, so the
full-bitnami and sha-field shapes are unaffected.

ReARM-Agentic-Session: 9083aa16-4486-4bc0-8fc4-0eb6e6783f33
ReARM-Agent: 703fbe71-5a15-4bd3-b601-ce3f0d7d225b
… regex-in-substring

addMetadataComponentToSkipPatterns appended ".*<name>.*" to
skipPatterns, but shouldSkipPurl matches by substring, never regex - so
the pattern could only match a purl containing the literal characters
".*", and the root component was enriched despite the intent.

Register the root's full purl for an exact (case-insensitive) match
instead. Exact rather than substring is deliberate: a substring of the
root's purl would also skip other versions of the same package appearing
as real dependencies (pkg:npm/a@1.0 is a substring of pkg:npm/a@1.0.1),
and a substring of just the name would skip every component whose purl
merely contains it.

ReARM-Agentic-Session: 909a0a70-a1f9-400c-8584-dc30130fa04c
ReARM-Agent: 703fbe71-5a15-4bd3-b601-ce3f0d7d225b
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
…erified healthy)

ReARM-Agentic-Session: 909a0a70-a1f9-400c-8584-dc30130fa04c
ReARM-Agent: 703fbe71-5a15-4bd3-b601-ce3f0d7d225b
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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.

2 participants