GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — fix(sbom): percent-encode vcs_url qualifier in generated purls (#9670) · npm/cli@024e6d9

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • lib/utils
    • sbom-cyclonedx.js
    • sbom-spdx.js
  • tap-snapshots/test/lib/utils
    • sbom-cyclonedx.js.test.cjs
    • sbom-spdx.js.test.cjs
  • test/lib/utils
    • sbom-cyclonedx.js
    • sbom-spdx.js
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎lib/utils/sbom-cyclonedx.js‎

Copy file name to clipboardExpand all lines: lib/utils/sbom-cyclonedx.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ const toCyclonedxItem = (node, { packageType }) => {
7676
// Calculate purl from package spec
7777
let spec = npa(node.pkgid)
7878
spec = (spec.type === 'alias') ? spec.subSpec : spec
79-
const purl = npa.toPurl(spec) + (isGitNode(node) ? `?vcs_url=${node.resolved}` : '')
79+
const purl = npa.toPurl(spec) + (isGitNode(node) ? `?vcs_url=${encodeURIComponent(node.resolved)}` : '')
8080

8181
if (node.package) {
8282
const toNormalize = new PackageJson()
Collapse file

‎lib/utils/sbom-spdx.js‎

Copy file name to clipboardExpand all lines: lib/utils/sbom-spdx.js
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ const toSpdxItem = (node, { packageType }) => {
109109
// Calculate purl from package spec
110110
let spec = npa(node.pkgid)
111111
spec = (spec.type === 'alias') ? spec.subSpec : spec
112-
const purl = npa.toPurl(spec) + (isGitNode(node) ? `?vcs_url=${node.resolved}` : '')
112+
const purl = npa.toPurl(spec) + (isGitNode(node) ? `?vcs_url=${encodeURIComponent(node.resolved)}` : '')
113113

114114
/* For workspace nodes, use the location from their linkNode */
115115
let location = node.location
Collapse file

‎tap-snapshots/test/lib/utils/sbom-cyclonedx.js.test.cjs‎

Copy file name to clipboardExpand all lines: tap-snapshots/test/lib/utils/sbom-cyclonedx.js.test.cjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ exports[`test/lib/utils/sbom-cyclonedx.js TAP single node - from git url > must
417417
"version": "1.0.0",
418418
"scope": "required",
419419
"author": "Author",
420-
"purl": "pkg:npm/[email protected]?vcs_url=https://github.com/foo/bar#1234",
420+
"purl": "pkg:npm/[email protected]?vcs_url=https%3A%2F%2Fgithub.com%2Ffoo%2Fbar%231234",
421421
"properties": [],
422422
"externalReferences": [
423423
{
Collapse file

‎tap-snapshots/test/lib/utils/sbom-spdx.js.test.cjs‎

Copy file name to clipboardExpand all lines: tap-snapshots/test/lib/utils/sbom-spdx.js.test.cjs
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ exports[`test/lib/utils/sbom-spdx.js TAP single node - from git url > must match
414414
{
415415
"referenceCategory": "PACKAGE-MANAGER",
416416
"referenceType": "purl",
417-
"referenceLocator": "pkg:npm/[email protected]?vcs_url=https://github.com/foo/bar#1234"
417+
"referenceLocator": "pkg:npm/[email protected]?vcs_url=https%3A%2F%2Fgithub.com%2Ffoo%2Fbar%231234"
418418
}
419419
]
420420
}
Collapse file

‎test/lib/utils/sbom-cyclonedx.js‎

Copy file name to clipboardExpand all lines: test/lib/utils/sbom-cyclonedx.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,17 @@ t.test('single node - from git url', t => {
270270
t.end()
271271
})
272272

273+
t.test('git url with special chars is encoded into the vcs_url qualifier', t => {
274+
const node = { ...root, type: 'git', resolved: 'https://github.com/foo/bar.git?a=b&c=d#1234' }
275+
const res = cyclonedxOutput({ npm, nodes: [node] })
276+
const { purl } = res.metadata.component
277+
// everything after vcs_url= must be a single percent-encoded value, so the
278+
// committish/query can't leak out as an extra purl qualifier or subpath
279+
t.equal(purl, 'pkg:npm/[email protected]?vcs_url=https%3A%2F%2Fgithub.com%2Ffoo%2Fbar.git%3Fa%3Db%26c%3Dd%231234')
280+
t.notMatch(purl.split('vcs_url=')[1], /[#&]/)
281+
t.end()
282+
})
283+
273284
t.test('single node - no package info', t => {
274285
const node = { ...root, package: undefined }
275286
const res = cyclonedxOutput({ npm, nodes: [node] })
Collapse file

‎test/lib/utils/sbom-spdx.js‎

Copy file name to clipboardExpand all lines: test/lib/utils/sbom-spdx.js
+11Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,17 @@ t.test('single node - from git url', t => {
223223
t.end()
224224
})
225225

226+
t.test('git url with special chars is encoded into the vcs_url qualifier', t => {
227+
const node = { ...root, type: 'git', resolved: 'https://github.com/foo/bar.git?a=b&c=d#1234' }
228+
const res = spdxOutput({ npm, nodes: [node] })
229+
const purl = res.packages
230+
.find(p => p.SPDXID === 'SPDXRef-Package-root-1.0.0')
231+
.externalRefs.find(r => r.referenceType === 'purl').referenceLocator
232+
t.equal(purl, 'pkg:npm/[email protected]?vcs_url=https%3A%2F%2Fgithub.com%2Ffoo%2Fbar.git%3Fa%3Db%26c%3Dd%231234')
233+
t.notMatch(purl.split('vcs_url=')[1], /[#&]/)
234+
t.end()
235+
})
236+
226237
t.test('single node - linked', t => {
227238
const node = { ...root, isLink: true, target: { edgesOut: [] } }
228239
const res = spdxOutput({ npm, nodes: [node] })

0 commit comments

Comments
0 (0)
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.