Go straight to an AI summary of this blog post instead

  • Summarize this post with Perplexity
  • Summarize this post with Gemini

Key Takeaways

  • Patched builds rank above upstream in Maven and Python, but below it in npm and Gradle.
  • Across eight constraint checks in four package managers, a patched build won only three times.
  • Resolver visibility, meaning whether a resolver picks a patched build unprompted, decides if a fix ever ships.
  • The approach that holds everywhere is pinning the patched build explicitly and rebuilding what ships.

Here’s a scenario we’ve watched play out more than once. A team backports a security fix to a library they can’t upgrade, publishes the patched build to their internal registry, and moves on. CI is green. A week later, the scanner still flags the CVE, and when someone finally opens the lockfile, the patched build isn’t there. Nothing failed. The package manager simply looked at the fixed version, decided it didn’t qualify, and installed the vulnerable one instead.

That isn’t a bug in npm, or Gradle, or anything else. It’s each ecosystem doing exactly what its version rules say. The trouble is that those rules were written for upstream maintainers shipping releases, not for anyone shipping a fix on top of someone else’s release. Delivering patched open source packages across ecosystems is a big part of what we do on SecureChain, and the single most useful thing we’ve learned is that the version number you put on a fix matters as much as the fix itself.

What resolver visibility means

Resolver visibility is whether a package manager will select a patched build on its own, given the version constraints a project already declares. A build with high resolver visibility gets picked up by existing ranges and pins without anyone editing a manifest. A build with low resolver visibility sits in the registry, fully available and fully ignored, until someone forces it in by hand.

Visibility depends on two things. The first is ordering, meaning whether the ecosystem thinks your patched version is newer or older than the upstream release it’s based on. The second is matching, meaning whether common constraints like a caret range or an exact pin consider the patched version acceptable at all. Those two questions get different answers across ecosystems, which is why a strategy that works beautifully in one place quietly fails in the next.

One build, four different verdicts

To make this concrete, we took a single hypothetical package at upstream version 4.7.3, plus a patched build of the same release, and ran both through the real version logic each ecosystem uses. That meant npm‘s own semver library (7.6.0), Maven 3.9.11’s version comparator, Gradle 8.14 resolving against a local repository, and Python’s packaging library, which is what pip uses to evaluate versions. The patched build was spelled 4.7.3-patched.2 everywhere except Python, where it was 4.7.3+patched.2, since that’s the form Python’s spec provides for this job. Every run was a fresh resolution with no lockfile in the way.

Then we asked each one two questions. With a normal compatible range in place (^4.7.0 for npm, [4.7,4.8) for Maven and Gradle, ~=4.7.0 for Python), which version wins? And with 4.7.3 declared as an exact version, which one wins then?

Ecosystem Patched build ranks Compatible range picks Exact 4.7.3 picks
npm Below 4.7.3 Upstream 4.7.3 Upstream 4.7.3
Maven Above 4.7.3 Patched build Upstream 4.7.3
Gradle Below 4.7.3 Upstream 4.7.3 Upstream 4.7.3
Python (pip) Above 4.7.3 Patched build Patched build

Three wins out of eight, and two of them are Python. Maven and Gradle read the same POM files from the same repositories and still reached opposite conclusions about which version is newer. If that surprises you, you’re in good company. It surprised a few people on our side too.

Why npm treats your security fix like a beta

npm follows Semantic Versioning, and SemVer says a hyphen after the patch number starts a prerelease. Prereleases sort below the release they precede, so 4.7.3-patched.2 counts as older than 4.7.3. As far as npm is concerned, your hardened build is a release candidate for the vulnerable version.

Matching makes it worse. By default, npm range matching skips prerelease versions entirely, so ^4.7.0 and ~4.7.0 will never select the patched build. Even a range written as ^4.7.3-patched.0, which explicitly opts into prereleases, still prefers plain 4.7.3 when both are available, because 4.7.3 is “newer.”

The case that actually bites teams is quieter than that. Say your internal registry holds the patched 4.7.3 build and an old 4.7.2, but not upstream 4.7.3. You’d expect ^4.7.0 to land on the patch. In our test, it resolved to 4.7.2, the older and still vulnerable version, because 4.7.2 was the highest non-prerelease available. The fix was right there and npm stepped over it.

So in npm, the patched build has to be named outright. If foo is a direct dependency, that just means putting the exact version in dependencies. For copies further down the tree, npm overrides are the tool, set in the root package.json of the application:

{
  "overrides": {
    "foo": "4.7.3-patched.2"
  }
}

That forces every copy of foo anywhere in the tree to the patched build, transitive or not, and npm ls foo will tell you whether it stuck. A few catches are worth knowing. npm only honors overrides in the root project, so a library can’t set them for its consumers. If foo is also a direct dependency, its entry in dependencies has to match the override exactly (the "$foo" reference form keeps the two in sync), or npm refuses to install with an EOVERRIDE error. And the override stays parked on the old base. Once upstream ships 4.7.4, any project that doesn’t carry the override will happily jump to it through a caret range, and 4.7.4 won’t have your backport if the fix was never accepted upstream. That’s why we treat every upstream patch release as a trigger to rebuild the fix on top of the new base, so 4.7.4-patched.1 exists before anyone needs it. Yarn’s resolutions and pnpm‘s overrides follow the same idea with their own syntax.

Maven and Gradle read the same POM and disagree

Maven’s version comparator knows a short list of qualifiers like alpha, beta, rc, and snapshot, and anything it doesn’t recognize sorts after the plain release. So in Maven, 4.7.3-patched.2 is newer than 4.7.3, and a range like [4.7,4.8) picks it. Good news, mostly.

The catch is that hardly anyone uses ranges in Maven. A plain version in a POM is a soft requirement, and Maven settles conflicts by distance from the root of the tree, not by which version is newest. So if the nearest declaration says 4.7.3, you get 4.7.3, full stop. Maven’s ordering is friendly to patched builds, but its resolution rarely asks the ordering question in the first place. To get the patched build in, you declare it in dependencyManagement at the top level, which overrides whatever the transitive tree asked for.

Gradle goes the other way on ordering. Its rule is that an extra non-numeric part makes a version lower, and patched isn’t one of the handful of special words (rc, snapshot, release, sp, and a few others) that get their own spot in the line. So 4.7.3-patched.2 sorts below 4.7.3. Gradle also resolves conflicts by picking the highest version in the graph, so when one dependency asked for the patched build and another asked for 4.7.3, our test build resolved to upstream 4.7.3. The vulnerable version won because Gradle considered it newer. The fix is a strict version, declared with strictly, either on the dependency itself or inside a dependency constraint, as in version { strictly '4.7.3-patched.2' }. A plain constraint won’t do it here, because Gradle only treats it as a minimum and 4.7.3 already sits above the patched build in Gradle’s eyes.

Python gets it right, if you pick the right separator

Python’s version spec, PEP 440, has something the others don’t, which is a local version label meant for exactly this situation. Anything after a plus sign is a local label, and 4.7.3+patched.2 sorts above 4.7.3. Better still, a public pin like ==4.7.3 ignores the local label when matching, so a project already pinned to 4.7.3 will accept 4.7.3+patched.2 and prefer it. No manifest changes required. It’s the only row in the table where both answers come back as the patched build. Lockfiles still get a vote, though. A lockfile or a hash-pinned requirements file keeps the old build until you regenerate it, and an environment that already has 4.7.3 installed stays put until someone runs pip install --upgrade.

The trap is using a post-release instead. 4.7.3.post1 sorts higher still, but ==4.7.3 doesn’t match it, so every project pinned to the exact upstream version silently skips it. If you’re publishing patched Python builds, the local label is the one that reaches pinned projects. Using a post-release is how you end up with a fix that only reaches people who were already upgrading.

There’s one practical wrinkle. PyPI won’t accept uploads with local version labels, so patched builds have to live somewhere else, usually a private index. How that index is wired in matters for security too. pip doesn’t rank one index above another. It just takes the best match from everywhere it’s told to look. So pointing pip at a single index that serves both your builds and upstream packages is safer than bolting on an extra index, which opens the door to dependency confusion.

What this means if you ship or consume patched packages

The lesson we took from all this is that you can’t count on any resolver to find a fix by itself. Python comes closest, and even there it depends on choosing the right version syntax. Everywhere else, the patched build has to be pinned explicitly, whether that’s an override, a dependencyManagement entry, or a strict version, and whatever ships has to be rebuilt so the pin is actually in it. If you own the application, that’s one change in one place. If you publish packages that other teams consume and the fix lands three levels down the tree, it means rebuilding the packages above it as well, in order, until the top-level artifact carries the fixed version, because nobody downstream is going to add your override for you. It’s more work than publishing a single artifact, but it’s the only approach we’ve found that behaves the same way in all four ecosystems.

The other lesson is to stop reading security status off the version string. A suffix tells a resolver where a build sorts. It says nothing reliable about which CVEs that build actually fixes, and plenty of scanners will see 4.7.3-patched.2, map it back to 4.7.3, and flag every known CVE for that release. A machine-readable record of what was fixed, such as a VEX document that travels with the build, is what lets a scanner tell the difference, as long as the scanner actually reads it.

None of this is exotic. It’s just the part of supply chain security that lives in package manager internals, and it’s where a lot of good fixes go to die. If you maintain release lines that upstream has stopped supporting, which is exactly where TuxCare’s Endless Lifecycle Support picks up, it’s worth an afternoon checking what your own resolvers actually install.

FAQ

What is resolver visibility?

Resolver visibility is whether a package manager will select a patched build on its own, given the version constraints a project already declares. It depends on how the ecosystem orders the patched version against the upstream release and whether common constraints like ranges and exact pins match it.

Why doesn’t npm install a patched package version?

npm treats any version with a hyphen suffix, like 4.7.3-patched.2, as a prerelease. Prereleases sort below the matching release and are skipped by normal caret and tilde ranges, so npm installs the upstream version, or an older release, instead.

How do you force a patched transitive dependency in npm?

Add an overrides entry to the root package.json that names the exact patched version. npm then uses that version for every copy of the package in the dependency tree, including transitive ones. If the package is also a direct dependency, its version in dependencies has to match the override, or npm stops with an EOVERRIDE error. Overrides in a library’s package.json are ignored when that library is installed as a dependency.

Does Maven treat a custom version qualifier as newer than the release?

Yes. Maven sorts unrecognized qualifiers after the plain release, so 4.7.3-patched.2 is newer than 4.7.3. Maven usually resolves conflicts by distance in the dependency tree rather than by version, though, so you still need dependencyManagement to make sure the patched build is selected.

Why does Gradle pick the upstream version over a patched build?

Gradle treats an extra non-numeric part like -patched.2 as lower than the plain release, and its conflict resolution picks the highest version. Declare the patched build with strictly, either on the dependency or inside a dependency constraint, to force it.

Will pip install 4.7.3+patched.2 with a ==4.7.3 pin?

Yes, as long as the patched build is on an index pip can see. Under PEP 440, a public pin ignores local version labels when matching, and a local version sorts above the public one, so a fresh install selects the patched build. An environment that already has 4.7.3 needs pip install --upgrade, and a lockfile has to be regenerated first.

Summary
Why Package Managers Skip Patched Package Versions
Article Name
Why Package Managers Skip Patched Package Versions
Description
One patched build, four package managers, and only 3 of 8 constraint checks picked it up. Here's why, and how to make the fix stick.
Author
Publisher Name
TuxCare
Publisher Logo

Join 4,500+ Linux & Open Source Professionals!

2x a month. No spam.

Table of Contents
Get the open-source security answers you need

Join 4,500+ Linux & Open Source Professionals!

2x a month. No spam.