fix(crd-generator): honor multi-package exclusions - #7952
Open
GrosQuildu wants to merge 2 commits into
Open
Conversation
GrosQuildu
marked this pull request as ready for review
June 26, 2026 14:09
GrosQuildu
added a commit
to GrosQuildu/kubernetes-client
that referenced
this pull request
Jun 26, 2026
GrosQuildu
requested review from
ash-thakur-rh,
manusa and
shawkins
as code owners
June 26, 2026 16:57
GrosQuildu
force-pushed
the
ptp-67-crd-exclude-packages
branch
from
June 26, 2026 17:14
04eabaf to
8dc59ef
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
The CRD generator's
CustomResourceCollector.withExcludePackagesmethod does not correctly combine multiple excluded package prefixes. It creates one predicate per package as!className.startsWith(pkg), then combines those negated predicates withor. As a result, a class under one excluded package is retained as long as it does not also start with another excluded package.This bypass affects the collector used by the CRD generator Maven plugin and CLI. A build that scans project classes or dependencies and configures multiple package exclusions can still load and generate CRDs for a class under an excluded prefix. The v2 CRD generator later derives
CustomResourceInfofrom the retained class and invokes the custom resource default constructor, so the exclusion bypass can execute code and emit CRDs that the build configuration intended to suppress.The vulnerable predicate composition is equivalent to:
For
com.example.Test, the first condition is false but the second condition is true, so the excluded class is retained.Exploit Scenario
An attacker contributes or compromises a dependency that is included in a downstream project's CRD generation classpath. The downstream project configures the generator to scan dependencies but excludes the attacker's package along with at least one other package. During the build, the collector's OR-composed exclude predicates retain the attacker's custom resource class. The generator loads the class, constructs generator metadata from it, invokes its default constructor, and emits CRD output for a resource that the exclusion was meant to block.
The following regression test exercises the project code path directly:
Run the regression test with:
./mvnw -B -ntp -pl crd-generator/collector -am -DskipITs \ -Dsurefire.failIfNoSpecifiedTests=false \ -Dtest=CustomResourceCollectorTest#givenClassNameAndMultipleExcludePackages_thenNoLoading \ testBefore the patch, the test fails because the excluded class is loaded:
After the patch, the same command succeeds:
Threat Model
This seems to be just a technical bug.
Fix
Combine the negated exclusion predicates with
and, so a retained class must avoid every excluded prefix.Paweł Płatek from Trail of Bits in collaboration with OpenAI.