mirror of
https://github.com/lukaszraczylo/gohoarder.git
synced 2026-11-25 06:35:21 +00:00
fix(cache): scan npm and PyPI packages named like Go metadata
IsMetadataEntry treated any name ending in .mod or .info as metadata. An npm or PyPI package with such a name skipped the vulnerability scan and was never blocked. The suffix rule now applies to the go registry only.
This commit is contained in:
@@ -23,14 +23,21 @@ var MetadataVersions = []string{"list", "page", "latest", "metadata"}
|
||||
// MetadataNameSuffixes mark Go module metadata files (.mod, .info).
|
||||
var MetadataNameSuffixes = []string{".mod", ".info"}
|
||||
|
||||
// GoRegistry is the registry whose cache keys carry the name suffixes above.
|
||||
const GoRegistry = "go"
|
||||
|
||||
// IsMetadataEntry reports whether a cache entry is a metadata page that must
|
||||
// refresh, as opposed to an immutable artifact.
|
||||
func IsMetadataEntry(name, version string) bool {
|
||||
// refresh, as opposed to an immutable artifact. The name suffixes apply to Go
|
||||
// only: an npm or PyPI package may legitimately end in .mod or .info.
|
||||
func IsMetadataEntry(registry, name, version string) bool {
|
||||
for _, v := range MetadataVersions {
|
||||
if version == v {
|
||||
return true
|
||||
}
|
||||
}
|
||||
if registry != GoRegistry {
|
||||
return false
|
||||
}
|
||||
for _, suffix := range MetadataNameSuffixes {
|
||||
if strings.HasSuffix(name, suffix) {
|
||||
return true
|
||||
|
||||
Reference in New Issue
Block a user