Skip to content

Commit

Permalink
fix: add IP change detection during chunked uploads to enhance security
Browse files Browse the repository at this point in the history
  • Loading branch information
PlusOne committed Jan 31, 2025
1 parent c63bef6 commit f229c64
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2092,6 +2092,7 @@ func handleChunkedUpload(tempFilename string, r *http.Request, chunkSize int) er
buffer := make([]byte, chunkSize)

totalBytes := int64(0)
originalIP := r.RemoteAddr
for {
n, err := r.Body.Read(buffer)
if err != nil && err != io.EOF {
Expand All @@ -2101,6 +2102,12 @@ func handleChunkedUpload(tempFilename string, r *http.Request, chunkSize int) er
break
}

currentIP := r.RemoteAddr
if currentIP != originalIP {
log.Warnf("IP changed from %s to %s, terminating transfer", originalIP, currentIP)
return fmt.Errorf("client IP changed during transfer")
}

_, err = writer.Write(buffer[:n])
if err != nil {
return fmt.Errorf("failed to write to file: %v", err)
Expand Down

0 comments on commit f229c64

Please sign in to comment.