Skip to content

Commit

Permalink
Add layer file extension only to name and not to url in OciRepository…
Browse files Browse the repository at this point in the history
…Handler

reason: the url needs to end with a constant string so that "$url.sha1" requests do not respond with the layer contents
  • Loading branch information
SgtSilvio committed May 11, 2024
1 parent d194d13 commit ac1f046
Showing 1 changed file with 9 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,13 @@ internal class OciRepositoryHandler(
return response.sendBadRequest()
}
val variant = mappedComponent.variants[variantName] ?: return response.sendNotFound()
return if (segments[7].endsWith("oci-component.json")) {
getOrHeadComponent(registryUri, variant, digest, size.toInt(), credentials, isGET, response)
} else {
getOrHeadLayer(registryUri, variant.imageReference.name, digest, size, credentials, isGET, response)
val last = segments[7]
return when {
last.endsWith("oci-component.json") ->
getOrHeadComponent(registryUri, variant, digest, size.toInt(), credentials, isGET, response)
last.endsWith("oci-layer") ->
getOrHeadLayer(registryUri, variant.imageReference.name, digest, size, credentials, isGET, response)
else -> response.sendNotFound()
}
}

Expand Down Expand Up @@ -170,9 +173,8 @@ internal class OciRepositoryHandler(
layerVariantName,
algorithmId + '!' + encodedHash.take(5) + ".." + encodedHash.takeLast(5),
)
val extension = mapLayerMediaTypeToExtension(mediaType)
val layerName = "$fileNamePrefix-$classifier$extension"
addString("name", layerName)
val layerName = "$fileNamePrefix-$classifier"
addString("name", layerName + mapLayerMediaTypeToExtension(mediaType))
addString("url", "$layerVariantName/$digest/$size/$layerName")
addNumber("size", size)
addString(algorithmId, encodedHash)
Expand Down

0 comments on commit ac1f046

Please sign in to comment.