Skip to content

Commit 368822a

Browse files
author
Alexandr Stelnykovych
committed
fix(firewall;interop/ivpn): apply external verdict handler in all connection filtering paths
Previously, the external verdict handler was placed in filterHandler, which is only called for new packets. This meant it was silently bypassed when connections were re-evaluated via resetConnectionVerdict. Move the handler into FilterConnection so it is consistently applied for all filtering paths, including verdict resets. https://github.com/safing/portmaster-shadow/issues/34
1 parent 26a8c03 commit 368822a

1 file changed

Lines changed: 15 additions & 16 deletions

File tree

service/firewall/packet_handler.go

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,6 @@ func filterHandler(conn *network.Connection, pkt packet.Packet) {
464464
}
465465

466466
filterConnection := true
467-
checkTunnel := true
468467

469468
// Check for special (internal) connection cases.
470469
switch {
@@ -503,24 +502,10 @@ func filterHandler(conn *network.Connection, pkt packet.Packet) {
503502

504503
issueVerdict(conn, pkt, 0, true)
505504
return
506-
507-
default:
508-
// Check if external verdict handler is set, and if so, run it.
509-
if extHandler := externalVerdictHandler.Load(); extHandler != nil {
510-
verdict, reason, skipTunnel := (*extHandler)(conn)
511-
switch verdict {
512-
// Accept and Block - only these verdicts are supported to be returned by the external handler.
513-
case network.VerdictAccept, network.VerdictBlock:
514-
conn.SetVerdict(verdict, reason, "", nil)
515-
filterConnection = false
516-
checkTunnel = !skipTunnel
517-
log.Tracer(pkt.Ctx()).Infof("filter: special verdict %s %q %s for connection", verdict, reason, conn)
518-
}
519-
}
520505
}
521506

522507
// Apply privacy filter and check tunneling.
523-
FilterConnection(pkt.Ctx(), conn, pkt, filterConnection, checkTunnel)
508+
FilterConnection(pkt.Ctx(), conn, pkt, filterConnection, true)
524509

525510
// Decide how to continue handling connection.
526511
switch {
@@ -544,6 +529,20 @@ func FilterConnection(ctx context.Context, conn *network.Connection, pkt packet.
544529
return
545530
}
546531

532+
// Check if external verdict handler is set, and if so, run it.
533+
// Note! This block can override the filter and tunnel check flags!
534+
if extHandler := externalVerdictHandler.Load(); extHandler != nil {
535+
verdict, reason, skipTunnel := (*extHandler)(conn)
536+
switch verdict {
537+
// Accept and Block - only these verdicts are supported to be returned by the external handler.
538+
case network.VerdictAccept, network.VerdictBlock:
539+
conn.SetVerdict(verdict, reason, "", nil)
540+
checkFilter = false
541+
checkTunnel = !skipTunnel
542+
log.Tracer(ctx).Infof("filter: special verdict %s %q %s for connection", verdict, reason, conn)
543+
}
544+
}
545+
547546
if checkFilter {
548547
if filterEnabled() {
549548
log.Tracer(ctx).Trace("filter: starting decision process")

0 commit comments

Comments
 (0)