Преглед на файлове

Fix udpWriter src overwrite and add address validation

- Remove incorrect w.src overwrite by b.UDP
- w.src should remain constant (return address)
- Add validation: check b.UDP matches w.dest
- Discard packets with mismatched addresses and log warning
- Fixes issue where response packet addresses could corrupt routing

Co-authored-by: Fangliding <[email protected]>
copilot-swe-agent[bot] преди 5 месеца
родител
ревизия
ff8cee0808
променени са 1 файла, в които са добавени 12 реда и са изтрити 1 реда
  1. 12 1
      proxy/tun/handler.go

+ 12 - 1
proxy/tun/handler.go

@@ -140,8 +140,19 @@ type udpWriter struct {
 
 func (w *udpWriter) WriteMultiBuffer(mb buf.MultiBuffer) error {
 	for _, b := range mb {
+		// Validate return packet address matches expected destination
 		if b.UDP != nil {
-			w.src = *b.UDP
+			if b.UDP.Address != w.dest.Address || b.UDP.Port != w.dest.Port {
+				errors.LogWarning(
+					context.Background(),
+					"UDP return packet address mismatch: expected ",
+					w.dest,
+					", got ",
+					b.UDP,
+				)
+				b.Release()
+				continue
+			}
 		}
 
 		netProto := header.IPv4ProtocolNumber