fix(nuget): reject invalid manifest relationship target modes (#12684)

fix(nuget): require an internal OPC manifest mode
This commit is contained in:
morluto authored and GitHub committed 2026-11-20 02:08:39 +00:00
1 parent d7269f7385
commit 8b60f3f25f
3 files changed
+51 -26

No files matched your search

+5 -3
View File
@@ -79,9 +79,11 @@ still succeeds with a limitation.
The `.nuspec` is chosen from a unique OPC relationship with Type
`http://schemas.microsoft.com/packaging/2010/07/manifest` when that target
exists in the ZIP. Both `Relationships` and `Relationship` must use the OPC
relationships namespace. The inspector skips other child elements and still
considers eligible relationships beside them. Without an eligible target, it
exists in the ZIP. `TargetMode` must be omitted or exactly `Internal` for
the relationship to select a package member. Both `Relationships` and
`Relationship` must use the OPC relationships namespace. The inspector skips
other child elements and considers eligible relationships beside them.
Without an eligible target, it
uses a unique `.nuspec` at the package root. Multiple conflicting manifests
are not decoded.
+37 -21
View File
@@ -469,30 +469,46 @@ it("stops expanding an OPC relationships member at the budget when its declared
}
});
it("leaves an external manifest relationship unfollowed even when it names a ZIP member", async () => {
const bytes = await nugetNupkgFixture({
includeRels: false,
extraMembers: {
"_rels/.rels": `<?xml version="1.0" encoding="utf-8"?>
it.each([
{ mode: "External", selected: false, limitation: "is external" },
{ mode: "Internal", selected: true, limitation: null },
{ mode: "Unknown", selected: false, limitation: "has an invalid TargetMode" },
{ mode: "", selected: false, limitation: "has an invalid TargetMode" },
{
mode: "internal",
selected: false,
limitation: "has an invalid TargetMode",
},
])(
"uses the declared OPC manifest TargetMode $mode",
async ({ mode, selected, limitation }) => {
const bytes = await nugetNupkgFixture({
includeRels: false,
extraMembers: {
"_rels/.rels": `<?xml version="1.0" encoding="utf-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
<Relationship Type="http://schemas.microsoft.com/packaging/2010/07/manifest" Target="content/Other.nuspec" TargetMode="External" Id="R1" />
<Relationship Type="http://schemas.microsoft.com/packaging/2010/07/manifest" Target="content/Other.nuspec" TargetMode="${mode}" Id="R1" />
</Relationships>
`,
"content/Other.nuspec": ungroupedNuspec,
},
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bytes, artifactOf(bytes), defaults),
);
expect(report.nuspec).toMatchObject({
path: "Demo.Package.nuspec",
source: "root-nuspec",
});
expect(report.identity?.id).toBe("Demo.Package");
expect(report.limitations).toContain(
'OPC manifest relationship Target "content/Other.nuspec" is external and was not followed.',
);
});
"content/Other.nuspec": ungroupedNuspec,
},
});
const report = nugetNupkgSchema.parse(
await parseNugetNupkg(bytes, artifactOf(bytes), defaults),
);
expect(report.nuspec).toMatchObject({
path: selected ? "content/Other.nuspec" : "Demo.Package.nuspec",
source: selected ? "opc-relationship" : "root-nuspec",
});
expect(report.identity?.id).toBe(
selected ? "Ungrouped.Package" : "Demo.Package",
);
if (limitation !== null)
expect(report.limitations).toContain(
`OPC manifest relationship Target "content/Other.nuspec" ${limitation} and was not followed.`,
);
},
);
const manifestRels = (target: string) => `<?xml version="1.0" encoding="utf-8"?>
<Relationships xmlns="http://schemas.openxmlformats.org/package/2006/relationships">
+9 -2
View File
@@ -294,13 +294,20 @@ const opcManifestTargets = (
const target = attribute(relationship, "Target");
if (target === null) continue;
const displayedTarget = redactRecordedTransportUrl(target).url;
// OPC external targets may be relative, so the mode decides, not the URI shape.
if (attribute(relationship, "TargetMode")?.toLowerCase() === "external") {
// Only an absent mode defaults to Internal. External targets can be relative.
const mode = relationship.getAttributeNS(null, "TargetMode");
if (mode === "External") {
limitations.push(
`OPC manifest relationship Target ${targetLabel(displayedTarget)} is external and was not followed.`,
);
continue;
}
if (mode !== null && mode !== "Internal") {
limitations.push(
`OPC manifest relationship Target ${targetLabel(displayedTarget)} has an invalid TargetMode and was not followed.`,
);
continue;
}
if (/^[a-z][a-z0-9+.-]*:/iu.test(target) || target.startsWith("//")) {
limitations.push(
`OPC manifest relationship Target ${targetLabel(displayedTarget)} has a URI scheme or authority and was not followed.`,