Security sweep: fix open redirect, XFF rate-limit bypass, SSRF; harden image and compose
- Reject control chars and backslashes in redirect targets - Use proxy-added X-Forwarded-For entry, cap limiter keys - Block private/loopback/link-local addresses on image fetch - HSTS over HTTPS, generic error on custom CSS - x/crypto 0.59.0, pin golang:1.27.4-alpine3.24 and alpine:3.24.4 - Compose: cap_drop ALL, no-new-privileges, read_only, limits, labels - Add SECURITY.md, CHANGELOG.md, TODO.md Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
cb2604bd05
commit
796384420b
15 files changed
+220
-17
No files matched your search
@@ -0,0 +1,34 @@
|
||||
package imgcache
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestFetchRefusesLocalAddresses(t *testing.T) {
|
||||
srv := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
t.Error("request reached a loopback server")
|
||||
}))
|
||||
defer srv.Close()
|
||||
c, err := New(t.TempDir(), "test")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, u := range []string{srv.URL + "/a.png", "http://10.0.0.2/a.png", "http://169.254.169.254/latest", "http://[::1]/a.png", "http://0.0.0.0/"} {
|
||||
if _, err := c.Fetch(context.Background(), u); !errors.Is(err, errPrivateAddr) {
|
||||
t.Errorf("Fetch(%s) err = %v, want errPrivateAddr", u, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestPublicOnly(t *testing.T) {
|
||||
for addr, ok := range map[string]bool{"93.184.215.14:443": true, "[2606:4700::1]:443": true,
|
||||
"127.0.0.1:80": false, "192.168.1.5:80": false, "100.64.1.1:80": false, "[fd00::1]:80": false, "[::ffff:10.0.0.1]:80": false} {
|
||||
if err := publicOnly("tcp", addr, nil); (err == nil) != ok {
|
||||
t.Errorf("publicOnly(%s) = %v, want ok=%v", addr, err, ok)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user