Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions internal/handler/maven.go
Original file line number Diff line number Diff line change
Expand Up @@ -221,14 +221,11 @@ func (h *MavenHandler) handleDownload(w http.ResponseWriter, r *http.Request, so
// e.g., com/google/guava/guava/32.1.3-jre/guava-32.1.3-jre.jar
group, artifact, version, filename := h.parsePath(urlPath)
if artifact == "" {
if strings.Count(urlPath, "/") >= minMavenParts-1 {
// A dot or colon in a group directory, or a colon in the
// artifact, which the Maven layout never has. Proxied, the
// file would skip the denylist, scan and cooldown.
http.NotFound(w, r)
return
}
h.proxyUpstream(w, r, source, urlPath)
// Too few segments to hold a coordinate, or a dot or colon in a
// group directory, or a colon in the artifact, which the Maven
// layout never has. Proxied, the file would skip the denylist,
// scan and cooldown.
http.NotFound(w, r)
return
}

Expand Down
10 changes: 6 additions & 4 deletions internal/handler/maven_repositories_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -139,15 +139,17 @@ func TestMavenRepositoryRepointedServesTheNewUpstream(t *testing.T) {
}
}

// TestMavenDottedGroupDirectoryNotCachedAsGroup checks that a file whose
// group directories contain dots or colons, which the Maven layout never
// has, is not served: it would either share the cache entry of the group
// the dots spell or be proxied past the denylist, scan and cooldown.
// TestMavenDottedGroupDirectoryNotCachedAsGroup checks that a file outside
// the Maven layout is not served: a group directory with a dot or a colon,
// which the layout never has and which would share the cache entry of the
// group the dots spell, and a path too short to hold a coordinate. Proxied,
// they would skip the denylist, scan and cooldown.
func TestMavenDottedGroupDirectoryNotCachedAsGroup(t *testing.T) {
const standard = "/org/foo/bar/1.0/bar-1.0.jar"
odd := []string{
"/org.foo/bar/1.0/bar-1.0.jar", "/org.foo/bar/1.0/bar-1.0-linux.exe",
"/org/foo:x/bar/1.0/bar-1.0.jar", "/org/foo/b:ar/1.0/b:ar-1.0.jar",
"/bar/1.0/bar-1.0.jar", "/bar-1.0.jar",
}
central, requests := mavenRepoUpstream(t, "central", append([]string{standard}, odd...)...)
portal, _ := mavenRepoUpstream(t, "portal")
Expand Down
Loading