@@ -71,7 +71,7 @@ func asURI(s string) string {
71
71
}
72
72
73
73
// Verify source URI in provenance statement.
74
- func verifySourceURI (prov slsaprovenance.Provenance , expectedSourceURI string , verifyMaterials bool ) error {
74
+ func verifySourceURI (prov slsaprovenance.Provenance , expectedSourceURI string , allowNoMaterialRef bool ) error {
75
75
source := asURI (expectedSourceURI )
76
76
77
77
// We expect github.com URIs only.
@@ -85,7 +85,7 @@ func verifySourceURI(prov slsaprovenance.Provenance, expectedSourceURI string, v
85
85
if err != nil {
86
86
return err
87
87
}
88
- configURI , err := sourceFromURI (fullConfigURI )
88
+ configURI , err := sourceFromURI (fullConfigURI , false )
89
89
if err != nil {
90
90
return err
91
91
}
@@ -95,15 +95,11 @@ func verifySourceURI(prov slsaprovenance.Provenance, expectedSourceURI string, v
95
95
}
96
96
97
97
// Verify source from material section.
98
- // TODO(#492): disable this option.
99
- if ! verifyMaterials {
100
- return nil
101
- }
102
98
materialSourceURI , err := prov .SourceURI ()
103
99
if err != nil {
104
100
return err
105
101
}
106
- materialURI , err := sourceFromURI (materialSourceURI )
102
+ materialURI , err := sourceFromURI (materialSourceURI , allowNoMaterialRef )
107
103
if err != nil {
108
104
return err
109
105
}
@@ -114,6 +110,12 @@ func verifySourceURI(prov slsaprovenance.Provenance, expectedSourceURI string, v
114
110
115
111
// Last, verify that both fields match.
116
112
// We use the full URI to match on the tag as well.
113
+ if allowNoMaterialRef && len (strings .Split (materialSourceURI , "@" )) == 1 {
114
+ // NOTE: this is an exception for npm packages built before GA,
115
+ // see https://github.com/slsa-framework/slsa-verifier/issues/492.
116
+ // We don't need to compare the ref since materialSourceURI does not contain it.
117
+ return nil
118
+ }
117
119
if fullConfigURI != materialSourceURI {
118
120
return fmt .Errorf ("%w: material and config URIs do not match: '%s' != '%s'" ,
119
121
serrors .ErrorInvalidDssePayload ,
@@ -123,13 +125,19 @@ func verifySourceURI(prov slsaprovenance.Provenance, expectedSourceURI string, v
123
125
return nil
124
126
}
125
127
126
- func sourceFromURI (uri string ) (string , error ) {
128
+ // sourceFromURI retrieves the source repository given a repository URI with ref.
129
+ //
130
+ // NOTE: `allowNoRef` is to allow for verification of npm packages
131
+ // generated before GA. Their provenance did not have a ref,
132
+ // see https://github.com/slsa-framework/slsa-verifier/issues/492.
133
+ // `allowNoRef` should be set to `false` for all other cases.
134
+ func sourceFromURI (uri string , allowNoRef bool ) (string , error ) {
127
135
if uri == "" {
128
136
return "" , fmt .Errorf ("%w: empty uri" , serrors .ErrorMalformedURI )
129
137
}
130
138
131
- r := strings .SplitN (uri , "@" , 2 )
132
- if len (r ) < 2 {
139
+ r := strings .Split (uri , "@" )
140
+ if len (r ) < 2 && ! allowNoRef {
133
141
return "" , fmt .Errorf ("%w: %s" , serrors .ErrorMalformedURI ,
134
142
uri )
135
143
}
@@ -217,7 +225,7 @@ func VerifyNpmPackageProvenance(env *dsselib.Envelope, provenanceOpts *options.P
217
225
}
218
226
// NOTE: for the non trusted builders, the information may be forgeable.
219
227
// Also, the GitHub context is not recorded for the default builder.
220
- return VerifyProvenanceCommonOptions (prov , provenanceOpts , false )
228
+ return VerifyProvenanceCommonOptions (prov , provenanceOpts , true )
221
229
}
222
230
223
231
func VerifyProvenance (env * dsselib.Envelope , provenanceOpts * options.ProvenanceOpts ,
@@ -234,14 +242,14 @@ func VerifyProvenance(env *dsselib.Envelope, provenanceOpts *options.ProvenanceO
234
242
return err
235
243
}
236
244
237
- return VerifyProvenanceCommonOptions (prov , provenanceOpts , true )
245
+ return VerifyProvenanceCommonOptions (prov , provenanceOpts , false )
238
246
}
239
247
240
248
func VerifyProvenanceCommonOptions (prov slsaprovenance.Provenance , provenanceOpts * options.ProvenanceOpts ,
241
- verifyMaterials bool ,
249
+ allowNoMaterialRef bool ,
242
250
) error {
243
251
// Verify source.
244
- if err := verifySourceURI (prov , provenanceOpts .ExpectedSourceURI , verifyMaterials ); err != nil {
252
+ if err := verifySourceURI (prov , provenanceOpts .ExpectedSourceURI , allowNoMaterialRef ); err != nil {
245
253
return err
246
254
}
247
255
0 commit comments