Skip to content

Commit 49e92c0

Browse files
authored
feat: Add DHI namespace to PURLs for Docker Hardened Images packages (#727)
feat: add DHI namespace to PURLs for Docker Hardened Images packages Docker Hardened Images patches binaries in their packages. The PURLs need to identify these patched packages with a "dhi" namespace so the vulnerability service can map them to the DHI vulnerability feed instead of the standard feeds. Without this, we get false positives from matching DHI's patched packages against unpatched vulnerability data. For deb packages, the Maintainer field in the dpkg database identifies DHI packages as "Docker Hardened Images <dhi@docker.com>". When this maintainer is found, the PURL namespace is set to "dhi" instead of the distro name. For example: - Standard: pkg:deb/debian/curl@7.88.1-10+deb12u8?distro=debian-bookworm - DHI: pkg:deb/dhi/curl@7.88.1-10+deb12u8?distro=debian-bookworm Changes: - Parse Maintainer field from dpkg database - Check maintainer in purl generation and override namespace to "dhi" - Add tests for DHI namespace behavior
1 parent b93f510 commit 49e92c0

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

lib/analyzer/package-managers/apt.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,11 @@ export function purl(
9393
vendor = osRelease.name;
9494
}
9595

96+
// Use 'dhi' namespace for Docker Hardened Images packages
97+
if (curPkg.Maintainer === "Docker Hardened Images <dhi@docker.com>") {
98+
vendor = "dhi";
99+
}
100+
96101
return new PackageURL(
97102
"deb",
98103
vendor,
@@ -151,6 +156,9 @@ function parseDpkgLine(
151156
curPkg.Provides.push(name);
152157
}
153158
break;
159+
case "Maintainer":
160+
curPkg.Maintainer = value;
161+
break;
154162
case "Pre-Depends":
155163
case "Depends":
156164
for (const depElem of value.split(",")) {

lib/analyzer/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ export interface AnalyzedPackage {
1010
Version?: string;
1111
Source?: string;
1212
SourceVersion?: string;
13+
Maintainer?: string;
1314
Provides: string[];
1415
Deps: {
1516
[name: string]: any;

test/lib/analyzer/package-managers/apt.spec.ts

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,4 +39,30 @@ describe("purl()", () => {
3939
} as unknown as AnalyzedPackageWithVersion),
4040
).toEqual("pkg:deb/bar@1.2.3-4?upstream=foo%405.6.7%2B8");
4141
});
42+
43+
it("uses 'dhi' namespace for Docker Hardened Images packages", () => {
44+
expect(
45+
purl(
46+
{
47+
Name: "curl",
48+
Version: "7.88.1-10+deb12u8",
49+
Maintainer: "Docker Hardened Images <dhi@docker.com>",
50+
} as unknown as AnalyzedPackageWithVersion,
51+
{ name: "debian", version: "12", prettyName: "Debian GNU/Linux 12" },
52+
),
53+
).toEqual("pkg:deb/dhi/curl@7.88.1-10%2Bdeb12u8?distro=debian-bookworm");
54+
});
55+
56+
it("uses osRelease vendor when maintainer is not Docker Hardened Images", () => {
57+
expect(
58+
purl(
59+
{
60+
Name: "curl",
61+
Version: "7.88.1-10+deb12u8",
62+
Maintainer: "Some Other Maintainer <other@example.com>",
63+
} as unknown as AnalyzedPackageWithVersion,
64+
{ name: "debian", version: "12", prettyName: "Debian GNU/Linux 12" },
65+
),
66+
).toEqual("pkg:deb/debian/curl@7.88.1-10%2Bdeb12u8?distro=debian-bookworm");
67+
});
4268
});

0 commit comments

Comments
 (0)