Repository navigation
Description
[agent] Found by the architecture refactor routine on main at cd7c5c5, with the real Maven 3.9.11 on JDK 21.
Problem
In project mode a Maven scan keeps only the coordinates the project's poms reach (#265). It follows each cached artifact's own <dependencies> and its parents', but not the dependencies that artifact's pom declares inside a <profile>. Maven does follow those: it activates the profiles of a dependency's pom for every consumer when they are activeByDefault, tied to the JDK, or tied to a property that is absent.
So a jar that the build puts on its classpath through such a profile is never scanned. scan says "No patches available for installed packages" while a patch for that jar exists, in every mode, and nothing tells the user that part of the build was left out.
Published poms that do this:
| Artifact | Profile | Activation | Declares |
|---|---|---|---|
com.sun.jersey:jersey-server 1.19.4 and 1.9, jersey-json 1.9 |
default |
<activeByDefault>true</activeByDefault> |
jersey-core, and through it jsr311-api |
org.apache.hbase:hbase-protocol 2.4.17, hbase-protocol-shaded |
build-with-jdk11 |
<jdk>[1.11,)</jdk> |
javax.annotation:javax.annotation-api |
org.apache.hbase:hbase-client 2.4.17, hbase-common |
hadoop-2.0 |
<property><name>!hadoop.profile</name></property> |
hadoop-common, hadoop-auth |
Where
The module states the rule, and that the scope is a superset of what Maven resolves:
socket-patch/crates/socket-patch-core/src/crawlers/maven_scope.rs
Lines 15 to 30 in cd7c5c5
| //! - **Edges**: an artifact's own non-optional `compile` / `runtime` | |
| //! dependencies (and those its parents declare), which is what Maven | |
| //! resolves transitively. | |
| //! - **Versions**: the literal, interpolated through the pom's properties | |
| //! and its parent chain; a version-less declaration takes the managed | |
| //! version (the pom's parent chain, then its imported BOMs), and a | |
| //! management entry of the reactor applies to transitives as Maven | |
| //! applies it. A version this cannot determine (an undefined property, a | |
| //! range, a pom not in the repository) admits every cached version of | |
| //! that artifact instead: the scope over-approximates within an artifact | |
| //! the project names, never across artifacts it does not. | |
| //! | |
| //! Exclusions and mediation are not modelled (both only narrow what Maven | |
| //! resolves), so the scope is a superset of the resolved graph: what a | |
| //! crawl may patch in place. Which version of an artifact each module | |
| //! selects from it, and so where a pin is safe, is |
A repository pom is parsed without its profiles (include_profiles is false) where the walk visits an artifact, where it reads a parent, and where it prefetches a wave:
socket-patch/crates/socket-patch-core/src/crawlers/maven_scope.rs
Lines 552 to 554 in cd7c5c5
| let Some(model) = self.model(&path, false) else { | |
| return Some(()); | |
| }; |
| let model = parse_model(self.read(&path), false, &self.work); |
The reactor's own poms are read with every profile (self.model(&path, true)), so the two halves of one walk treat a profile differently.
docs/ecosystems.md describes the scope as "each artifact's own non-optional compile / runtime dependencies, read from the poms the repository already holds" and does not say a profile's are skipped:
socket-patch/docs/ecosystems.md
Lines 1974 to 1987 in cd7c5c5
| * **A Maven project's scan is scoped to its dependency graph.** The Maven local | |
| repository is shared by every project on the machine, so in project mode (no | |
| `--global` / `--global-prefix`) a Maven build's crawl (a `pom.xml`, no Gradle or | |
| sbt / Mill / scala-cli build beside it) keeps only the coordinates its poms reach: | |
| every reactor declaration (modules and profiles included, any scope), then each | |
| artifact's own non-optional `compile` / `runtime` dependencies, read from the poms the | |
| repository already holds, with versions from properties, parents, management and | |
| imported BOMs (the reactor's management applies to transitives, as in Maven). A | |
| version that cannot be determined (an undefined property, a range, a pom not in the | |
| repository) admits every cached version of that artifact. Artifacts another project | |
| cached are not scanned, so hosted mode never pins them and `vex` never attests them. | |
| A project that has never been resolved therefore finds nothing; resolve it once | |
| (`mvn -q dependency:resolve`) and scan again. An unreadable root `pom.xml` leaves the | |
| crawl unscoped. |
What Maven does, and what the scan finds
Each project is one pom.xml with one dependency, resolved into an empty local repository (mvn -B -q -Dmaven.repo.local=<repo> dependency:list), then scanned by the binary built from main with MAVEN_REPO_LOCAL=<repo> against a stand-in patch service that holds patches for the jars named below.
Jersey 1. The pom declares com.sun.jersey:jersey-server:1.19.4.
$ mvn -B -q dependency:list
com.sun.jersey:jersey-core:jar:1.19.4:compile
com.sun.jersey:jersey-server:jar:1.19.4:compile
javax.ws.rs:jsr311-api:jar:1.1.1:compile
$ socket-patch scan --mode agent --dry-run --yes
Found 1 package (1 maven)
No patches available for installed packages. # exit 0
The one package is jersey-server. The control is the same pom with jersey-core 1.19.4 declared beside it:
$ socket-patch scan --mode agent --dry-run --yes
Found 3 packages (3 maven)
HIGH com.sun.jersey/jersey-core@1.19.4 CVE-2024-10000
HIGH javax.ws.rs/jsr311-api@1.1.1 CVE-2024-10000
Would patch 2 packages, fixing 2 vulnerabilities (2 high).
scan --global over the same repository lists both jars too, so they are cached and readable. jersey-server's pom has no jersey-core outside its profiles; its own dependencies are provided and test only.
HBase.
| Project's one dependency | Maven resolves | scan finds |
Resolved and not scanned |
|---|---|---|---|
hbase-protocol 2.4.17 |
5 jars | 4 | javax.annotation:javax.annotation-api:1.2 |
hbase-client 2.4.17 |
77 jars | 79 | javax.annotation:javax.annotation-api:1.2 |
In the second row the scan's 79 hold three versions Maven mediated away, which is the over-approximation the module documents. hadoop-common and hadoop-auth are found there, because hbase-hadoop2-compat of that tree declares hadoop-common outside a profile. A project whose only path to them is the profile would miss them and everything below them.
The purls are the ones the binary sent to the patch service's batch route, compared with Maven's list.
The failing test
Beside the_scope_is_the_declared_graph_not_the_cache in the module's tests (a throwaway, not committed):
#[test]
fn probe_a_dependency_poms_profile_dependencies_are_in_scope() {
for activation in [
"<activeByDefault>true</activeByDefault>",
"<jdk>[1.11,)</jdk>",
"<property><name>!hadoop.profile</name></property>",
] {
let dir = tempfile::tempdir().unwrap();
let (cwd, repo) = (dir.path().join("p"), dir.path().join("m2"));
write(
&cwd,
"pom.xml",
&pom(
"com.example",
"app",
"1",
&deps(&[dep("com.sun.jersey", "jersey-server", Some("1.19.4"), "")]),
),
);
cache(
&repo,
"com.sun.jersey",
"jersey-server",
"1.19.4",
&format!(
"<profiles><profile><id>default</id><activation>{activation}</activation>{}\
</profile></profiles>",
deps(&[dep("com.sun.jersey", "jersey-core", Some("${project.version}"), "")])
),
);
cache(
&repo,
"com.sun.jersey",
"jersey-core",
"1.19.4",
&deps(&[dep("javax.ws.rs", "jsr311-api", Some("1.1.1"), "")]),
);
cache(&repo, "javax.ws.rs", "jsr311-api", "1.1.1", "");
let scope = project_scope(&cwd, &repo).unwrap();
assert!(scope.admits("com.sun.jersey", "jersey-server", "1.19.4"));
assert!(
scope.admits("com.sun.jersey", "jersey-core", "1.19.4"),
"jersey-core, declared under {activation}"
);
assert!(
scope.admits("javax.ws.rs", "jsr311-api", "1.1.1"),
"jsr311-api, below jersey-core ({activation})"
);
}
}On main:
$ cargo test -p socket-patch-core --lib probe_a_dependency_poms
test crawlers::maven_scope::tests::probe_a_dependency_poms_profile_dependencies_are_in_scope ... FAILED
panicked at crates/socket-patch-core/src/crawlers/maven_scope.rs:1041:13:
jersey-core, declared under <activeByDefault>true</activeByDefault>
test result: FAILED. 0 passed; 1 failed
History
-
08e54b2 (Maven hosted scan pins, and VEX attests, artifacts the project doesn't depend on (the crawler lists all of
~/.m2) #265, 10-10) wrote the scope. It reads the reactor with every profile and the repository's poms with none. -
940e6b7 (Hosted Maven and VEX treat a Maven 4 implicit-subproject root as one pom #1809, 11-02) fixed an earlier case of this scope being narrower than the build: the subprojects Maven 4 discovers.
-
6eaa807 (Pin a Maven patch only where Maven selects its base version #2100, 11-18) taught the selection that decides where a pin is safe that a dependency's pom may declare dependencies in a profile. It holds the pins of that module back and says why ("a profile of … declares dependencies"):
socket-patch/crates/socket-patch-core/src/crawlers/maven_selection.rs
Lines 977 to 983 in cd7c5c5
for node in chain { if node.model.profiles.deps { out.unknown = Some(format!( "a profile of {} declares dependencies", describe(node) )); } The scope beside it was not changed. So the selection knows the edge may exist, and the crawl that feeds it never follows it.
Planned fix
Read a repository pom with its profiles in the scope walk, as the reactor's poms already are: the four reads of a repository pom in maven_scope.rs (visit, the parent step of chain, prefetch, and the BOM step of managed_version) pass true. All four have to change together, because the walk caches a parsed pom by path and the first read decides what the cache holds.
That admits the dependencies of every profile, active or not. Which profiles are active depends on the JDK and the properties of the build, which a scan cannot know, and the reactor's profiles are already admitted the same way. The scope stays inside the artifacts the project's graph names: an inactive profile's dependency is scanned only if some build on the machine cached it. Hosted and vendored pins are decided by the selection, which already holds back around such poms, so no new pin follows from this.
Then: the test above, a sentence in docs/ecosystems.md beside the scope's rule, and the module's own rule text. About ten production lines.
With that change on a build: the test above passes for all three activations, the 495 tests whose names hold maven_ pass, and the three projects above scan as 3 of 3, 5 of 5 and 77 of 77 jars (80 scanned in the last: the same three mediated versions as before, no new one).
Not run
- Whether a record that an older release or a
--globalrun made for such a jar is dropped byscan --prune/--syncin project mode. A narrower crawl has been a prune hazard before (Scope a Go workspace's scan to the modules it builds, not the machine's module cache #2431, Only Cargo keeps a still-patched shared-cache copy restorable: for Maven and NuGet,scan --pruneafter a version bump, androllback/removeaftervendor, drop the record and leave the cache copy patched for every project on the machine #2472). - Maven 4, and a profile activated by
<os>or<file>. - Gradle, sbt, Mill and scala-cli builds, whose crawls are not scoped by this walk.
Generated by Claude Code
Activity
refactor: L277 to L282; #2536 filed (Maven)