Skip to content
Closed
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
8 changes: 4 additions & 4 deletions internal/router/admin_peers.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func FetchNodeInfo(baseURL string) (*nodeInfoResponse, error) {
}
url := strings.TrimSuffix(baseURL, "/") + "/-/nodeinfo"

client := &http.Client{Timeout: 10 * time.Second}
client := fetch.SafeClient()
resp, err := client.Get(url)
if err != nil {
return nil, fmt.Errorf("failed to connect to peer: %w", err)
Expand Down Expand Up @@ -140,7 +140,7 @@ func (h *handler) checkPeerHealth(w http.ResponseWriter, r *http.Request) {
http.Error(w, "Invalid request", http.StatusBadRequest)
return
}
client := &http.Client{Timeout: 5 * time.Second}
client := fetch.SafeClient()
resp, err := client.Get(strings.TrimSuffix(req.URL, "/") + "/-/nodeinfo")
if err != nil || resp.StatusCode != http.StatusOK {
w.WriteHeader(http.StatusServiceUnavailable)
Expand All @@ -157,7 +157,7 @@ func (h *handler) checkPeerHealthHandler(w http.ResponseWriter, r *http.Request)
http.Error(w, "missing url parameter", http.StatusBadRequest)
return
}
client := &http.Client{Timeout: 5 * time.Second}
client := fetch.SafeClient()
resp, err := client.Get(strings.TrimSuffix(peerURL, "/") + "/-/nodeinfo")
status := "down"
if err == nil && resp.StatusCode == http.StatusOK {
Expand Down Expand Up @@ -297,7 +297,7 @@ func importPeerGossip(peerURL string) {
}
endpoint := strings.TrimSuffix(base, "/") + "/-/peers"

client := &http.Client{Timeout: 10 * time.Second}
client := fetch.SafeClient()
resp, err := client.Get(endpoint)
if err != nil {
log.Printf("[Gossip] fetch %s: %v", endpoint, err)
Expand Down
2 changes: 1 addition & 1 deletion internal/router/announce.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ func AnnounceURLToPeer(peer registry.Peer, publicURL string) error {
return fmt.Errorf("node identity not initialised")
}

client := &http.Client{Timeout: 10 * time.Second}
client := fetch.SafeClient()

// Step 1: request a fresh nonce.
chalBody, _ := json.Marshal(challengeRequest{PublicKey: pubKey})
Expand Down
9 changes: 7 additions & 2 deletions internal/router/peer_sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,12 @@ func (h *handler) pullFromPeer(peerURL, remotePath, destDir string) error {

// 4. Download every file listed in the manifest
for relPath := range manifest.Files {
fileURL := peerURL + "/content/" + remotePath + "/" + relPath
cleanRel := strings.TrimPrefix(filepath.ToSlash(filepath.Clean(relPath)), "/")
if cleanRel == "" || strings.HasPrefix(cleanRel, "..") {
return fmt.Errorf("security violation: manifest contains path traversal attempt: %s", relPath)
}

fileURL := peerURL + "/content/" + remotePath + "/" + cleanRel
fileResp, err := http.Get(fileURL)
if err != nil {
return fmt.Errorf("failed to download %s: %w", relPath, err)
Expand All @@ -58,7 +63,7 @@ func (h *handler) pullFromPeer(peerURL, remotePath, destDir string) error {
return fmt.Errorf("file %s returned HTTP %d", relPath, fileResp.StatusCode)
}

localPath := filepath.Join(destDir, relPath)
localPath := filepath.Join(destDir, filepath.FromSlash(cleanRel))
if err := os.MkdirAll(filepath.Dir(localPath), 0755); err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/router/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ func (h *handler) importRemote(w http.ResponseWriter, r *http.Request) {
return
}
httpReq.Header.Set("User-Agent", "RED-Engine-Sync/1.0")
client := &http.Client{Timeout: 15 * time.Second}
client := fetch.SafeClient()
resp, err := client.Do(httpReq)
if err != nil {
http.Error(w, "Failed to connect to remote server", http.StatusBadGateway)
Expand Down
Loading