Hello
I have been trying to do similar thing - filter outbound HTTP requests from Safari by URL. I am also using SimpleFirewall app provided as a sample for WWDC19 session about Network Extension. But when I try to get url of the flow originated from Safari always getting nil of string with address. I have modified only handleNewFlow
And here it is:
swift
override func handleNewFlow(_ flow: NEFilterFlow) - NEFilterNewFlowVerdict {
guard let socketFlow = flow as? NEFilterSocketFlow,
let remoteEndpoint = socketFlow.remoteEndpoint as? NWHostEndpoint,
let localEndpoint = socketFlow.localEndpoint as? NWHostEndpoint else {
return .allow()
}
let blacklisted = "www.example.com"
os_log("Flow %@", flow)
if socketFlow.direction != .outbound
{
os_log("Allow non-outbound connections")
return .allow()
}
if socketFlow.url != nil
{
os_log("Host %@", socketFlow.url?.host as! CVarArg)
if blacklisted == socketFlow.url?.host
{
return .drop()
}
}
else
{
os_log("URL is nil")
}
os_log("Endpoint hostname %@", remoteEndpoint.hostname)
os_log("New flow with local endpoint %@, remote endpoint %@", localEndpoint, remoteEndpoint)
let flowInfo = [
FlowInfoKey.localPort.rawValue: localEndpoint.port,
FlowInfoKey.remoteAddress.rawValue: remoteEndpoint.hostname
]
let prompted = IPCConnection.shared.promptUser(aboutFlow: flowInfo) { allow in
let userVerdict: NEFilterNewFlowVerdict = allow ? .allow() : .drop()
self.resumeFlow(flow, with: userVerdict)
}
guard prompted else {
return .allow()
}
return .pause()
}
When I run a firewall and check log in console I always see "URL is nil" message when I try to open websites from Safari
Could you help to understand what am I doing wrong?
Topic:
App & System Services
SubTopic:
Core OS
Tags: