SimpleFirewall from Filtering Network Traffic example not filtering traffic

I've been trying very unsuccessfully to get the Filtering Network Traffic example code to work. I've read many forum posts but I still wasn't able to figure it out.

I download the example project and set my development team for both targets. From then on the project is configured to create unique bundle identifiers and app group. Signing and provisioning profile is created and managed by Xcode with all the necessary entitlements. I am able to build the app (debug with provisioning profile) and then copy it to /Applications.

I open the app, click start, enable and allow the network extension. Activity Monitor shows that the extension is running.

But when I test local connections to port 8888 nothing happens in the app, the connection are just allowed. I tested with the following setup:

  • create a local webserver with python3 -m http.server 8888 and make a request via curl and the webbrowser
  • normal tcp connection with nc (nc -l 8888 and nc localhost 8888)

I added lots of logging and I can see that the startFilter method is called, but never the handleNewFlow method.

The only error I see in Console is

networkd_settings_read_from_file Sandbox is preventing this process from reading networkd settings file at "/Library/Preferences/com.apple.networkd.plist", please add an exception.

but don't know what to do about that. I also read the debugging guide (very helpful). I'm used to jump through a lot of hoops with this stuff, but I can't figure out what the problem is.

Answered by Shay39 in 815391022

I think you're testing connections to localhost (127.0.0.1 or ::1), which requires explicit network rules.

Refer: NetworkExtensions/NENetworkRule.h

If the address is a wildcard address (0.0.0.0 or ::) then the rule will match all destinations except for loopback (127.0.0.1 or ::1). To match loopback traffic set the address to the loopback address.

I replied to your follow-up on this old thread but I wanted to add something new here…

Are you using macOS 15? Do you have the system firewall enabled? If so, try disabling it.

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

Accepted Answer

I think you're testing connections to localhost (127.0.0.1 or ::1), which requires explicit network rules.

Refer: NetworkExtensions/NENetworkRule.h

If the address is a wildcard address (0.0.0.0 or ::) then the rule will match all destinations except for loopback (127.0.0.1 or ::1). To match loopback traffic set the address to the loopback address.

Thank you both for your help @Shay39 @DTS Engineer Quinn ! It really was the wrong address. I just tested it again with interface addresses other than loopback and it works just fine. It also works with the firewall enabled.

I already tested other interface addresses, but when I did there were probably other things wrong and I discarded the idea.

@Quinn: Thanks for the reply on the other thread, I didn't get a notification.

Thanks again!

SimpleFirewall from Filtering Network Traffic example not filtering traffic
 
 
Q