Skip to content

Commit 38e0bed

Browse files
authored
fix: packages w/ both provenance + trusted publishing -> trustedPublisher (#1302)
1 parent 2751a70 commit 38e0bed

File tree

3 files changed

+33
-5
lines changed

3 files changed

+33
-5
lines changed

app/composables/npm/usePackage.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ function hasTrustedPublisher(version: PackumentVersion): boolean {
2020
}
2121

2222
function getTrustLevel(version: PackumentVersion): PublishTrustLevel {
23-
if (hasAttestations(version)) return 'provenance'
23+
// trusted publishing automatically generates provenance attestations
2424
if (hasTrustedPublisher(version)) return 'trustedPublisher'
25+
if (hasAttestations(version)) return 'provenance'
2526
return 'none'
2627
}
2728

app/pages/package/[[org]]/[name].vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1099,7 +1099,7 @@ onKeyStroke(
10991099
>
11001100
<template #trustedPublishing>
11011101
<a
1102-
href="https://docs.npmjs.com/adding-a-trusted-publisher-to-a-package"
1102+
href="https://docs.npmjs.com/trusted-publishers"
11031103
target="_blank"
11041104
rel="noopener noreferrer"
11051105
class="inline-flex items-center gap-1 rounded-sm underline underline-offset-4 decoration-amber-600/60 dark:decoration-amber-400/50 hover:decoration-fg focus-visible:decoration-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 transition-colors"
@@ -1129,7 +1129,7 @@ onKeyStroke(
11291129
</template>
11301130
<template #trustedPublishing>
11311131
<a
1132-
href="https://docs.npmjs.com/adding-a-trusted-publisher-to-a-package"
1132+
href="https://docs.npmjs.com/trusted-publishers"
11331133
target="_blank"
11341134
rel="noopener noreferrer"
11351135
class="inline-flex items-center gap-1 rounded-sm underline underline-offset-4 decoration-amber-600/60 dark:decoration-amber-400/50 hover:decoration-fg focus-visible:decoration-fg focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-accent/70 transition-colors"

test/nuxt/composables/use-package-transform.spec.ts

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ describe('transformPackument', () => {
213213
expect(detectPublishSecurityDowngradeForVersion(infos, '1.0.1')?.trustedVersion).toBe('1.0.0')
214214
})
215215

216-
it('prefers provenance trust level when both trustedPublisher and attestations exist', () => {
216+
it('prefers trustedPublisher trust level when both trustedPublisher and attestations exist', () => {
217217
const packument = createPackument(
218218
{
219219
'1.0.0': createTrustedPublisherWithAttestationsVersion('1.0.0'),
@@ -230,7 +230,34 @@ describe('transformPackument', () => {
230230

231231
const transformed = transformPackument(packument, '1.0.1')
232232

233-
expect(transformed.versions['1.0.0']?.trustLevel).toBe('provenance')
233+
expect(transformed.versions['1.0.0']?.trustLevel).toBe('trustedPublisher')
234+
})
235+
236+
// https://github.com/npmx-dev/npmx.dev/issues/1292
237+
it('does not flag false downgrade when trusted publisher version also has attestations', () => {
238+
// Trusted publishing automatically generates provenance attestations,
239+
// so a version with both should be classified as trustedPublisher, not provenance.
240+
const packument = createPackument(
241+
{
242+
'7.0.0': createTrustedPublisherWithAttestationsVersion('7.0.0'),
243+
'7.0.1': createTrustedPublisherWithAttestationsVersion('7.0.1'),
244+
},
245+
{
246+
'created': '2026-01-01T00:00:00.000Z',
247+
'modified': '2026-01-02T00:00:00.000Z',
248+
'7.0.0': '2026-01-01T00:00:00.000Z',
249+
'7.0.1': '2026-01-02T00:00:00.000Z',
250+
},
251+
'7.0.1',
252+
)
253+
254+
const transformed = transformPackument(packument, '7.0.1')
255+
const infos = toVersionInfos(transformed)
256+
257+
// Both versions should be trustedPublisher — no downgrade
258+
expect(infos.find(v => v.version === '7.0.0')?.trustLevel).toBe('trustedPublisher')
259+
expect(infos.find(v => v.version === '7.0.1')?.trustLevel).toBe('trustedPublisher')
260+
expect(detectPublishSecurityDowngradeForVersion(infos, '7.0.1')).toBeNull()
234261
})
235262

236263
it('flags non-direct downgrade chain until trust is restored', () => {

0 commit comments

Comments
 (0)