Skip to content

Commit 7d23983

Browse files
committed
[feature] add httpProxyBlockedPaths that blocks even GET paths which can be malicous
1 parent eebfadb commit 7d23983

1 file changed

Lines changed: 24 additions & 2 deletions

File tree

go/socket-proxy/main.go

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import(
1111
"os/signal"
1212
"syscall"
1313
"sync"
14+
"regexp"
1415
)
1516

1617
var(
@@ -28,11 +29,32 @@ func signals(){
2829
}()
2930
}
3031

32+
func httpProxyBlockedPaths(url string) bool {
33+
blockedPatterns := []*regexp.Regexp{
34+
regexp.MustCompile(`(?i)containers/\S+/attach/ws.*`), // could attach to stdin via web socket and issue command inside the container
35+
regexp.MustCompile(`(?i)containers/\S+/export.*`), // could exfil container data
36+
regexp.MustCompile(`(?i)containers/\S+/archive.*`), // could exfil container data
37+
regexp.MustCompile(`(?i)secrets.*`), // could exfil credentials
38+
regexp.MustCompile(`(?i)configs.*`), // could exfil credentials
39+
regexp.MustCompile(`(?i)swarm/unlockkey.*`), // could exfil credentials
40+
regexp.MustCompile(`(?i)images/get.*`), // could exfil container data
41+
}
42+
43+
for _, pattern := range blockedPatterns {
44+
if pattern.MatchString(url) {
45+
return true
46+
}
47+
}
48+
return false
49+
}
50+
3151
func httpProxy(w http.ResponseWriter, r *http.Request){
32-
if(r.Method == "GET"){
52+
method := r.Method
53+
url := r.URL.String()
54+
if(method == "GET" && !httpProxyBlockedPaths(url)){
3355
proxy.ServeHTTP(w, r)
3456
}else{
35-
log.Printf("blocked: %s %s", r.Method, r.URL.String())
57+
log.Printf("blocked: %s %s", method, url)
3658
http.Error(w, "", http.StatusForbidden)
3759
}
3860
}

0 commit comments

Comments
 (0)