1- import { parseImageReference } from "../image-reference" ;
1+ import { isValidDigest , parseImageReference } from "../image-reference" ;
22
33export interface OCIDistributionMetadata {
44 // Must be a valid host, including port if one was used to pull the image.
@@ -44,14 +44,7 @@ export function constructOCIDisributionMetadata({
4444 imageTag : parsed . tag ,
4545 } ;
4646
47- // 255 byte limit is enforced by RFC 1035.
48- if ( Buffer . byteLength ( metadata . registryHost ) > 255 ) {
49- return ;
50- }
51-
52- // 2048 byte limit is enforced by Snyk for platform stability.
53- // Longer strings may be valid, but nothing close to this limit has been observed by Snyk at time of writing.
54- if ( Buffer . byteLength ( metadata . repository ) > 2048 ) {
47+ if ( ! ociDistributionMetadataIsValid ( metadata ) ) {
5548 return ;
5649 }
5750
@@ -60,3 +53,28 @@ export function constructOCIDisributionMetadata({
6053 return ;
6154 }
6255}
56+
57+ function ociDistributionMetadataIsValid (
58+ data : OCIDistributionMetadata ,
59+ ) : boolean {
60+ // 255 byte limit is enforced by RFC 1035.
61+ if ( Buffer . byteLength ( data . registryHost ) > 255 ) {
62+ return false ;
63+ }
64+
65+ // 2048 byte limit is enforced by Snyk for platform stability.
66+ // Longer strings may be valid, but nothing close to this limit has been observed by Snyk at time of writing.
67+ if ( Buffer . byteLength ( data . repository ) > 2048 ) {
68+ return false ;
69+ }
70+
71+ if ( ! isValidDigest ( data . manifestDigest ) ) {
72+ return false ;
73+ }
74+
75+ if ( data . indexDigest && ! isValidDigest ( data . indexDigest ) ) {
76+ return false ;
77+ }
78+
79+ return true ;
80+ }
0 commit comments