tangled
alpha
login
or
join now
atscan.net
/
plcbundle-go
1
fork
atom
[DEPRECATED] Go implementation of plcbundle
1
fork
atom
overview
issues
pulls
pipelines
common files filtering in server
tree.fail
3 months ago
866286c0
6c8b0a6f
+39
1 changed file
expand all
collapse all
unified
split
server
handlers.go
+39
server/handlers.go
···
675
675
parts := strings.SplitN(path, "/", 2)
676
676
input := parts[0]
677
677
678
678
+
// Ignore common browser files before any validation
679
679
+
if isCommonBrowserFile(input) {
680
680
+
w.WriteHeader(http.StatusNotFound)
681
681
+
return
682
682
+
}
683
683
+
678
684
// Quick validation: must be either a DID or a valid handle format
679
685
if !isValidDIDOrHandle(input) {
680
686
sendJSON(w, 404, map[string]string{"error": "not found"})
···
691
697
} else {
692
698
sendJSON(w, 404, map[string]string{"error": "not found"})
693
699
}
700
700
+
}
701
701
+
702
702
+
func isCommonBrowserFile(path string) bool {
703
703
+
// Common files browsers request automatically
704
704
+
commonFiles := []string{
705
705
+
"favicon.ico",
706
706
+
"robots.txt",
707
707
+
"sitemap.xml",
708
708
+
"apple-touch-icon.png",
709
709
+
"apple-touch-icon-precomposed.png",
710
710
+
".well-known",
711
711
+
}
712
712
+
713
713
+
for _, file := range commonFiles {
714
714
+
if path == file || strings.HasPrefix(path, file) {
715
715
+
return true
716
716
+
}
717
717
+
}
718
718
+
719
719
+
// Common file extensions that are NOT DIDs/handles
720
720
+
commonExtensions := []string{
721
721
+
".ico", ".png", ".jpg", ".jpeg", ".gif", ".svg",
722
722
+
".css", ".js", ".woff", ".woff2", ".ttf", ".eot",
723
723
+
".xml", ".txt", ".html", ".webmanifest",
724
724
+
}
725
725
+
726
726
+
for _, ext := range commonExtensions {
727
727
+
if strings.HasSuffix(path, ext) {
728
728
+
return true
729
729
+
}
730
730
+
}
731
731
+
732
732
+
return false
694
733
}
695
734
696
735
// isValidDIDOrHandle does quick format check before expensive resolution