Add remote candidate IP filtering to ICE Agent#898
Add remote candidate IP filtering to ICE Agent#898sirzooro wants to merge 1 commit intopion:masterfrom
Conversation
There was a problem hiding this comment.
Pull request overview
This PR adds a configurable remote-candidate IP filtering hook to the ICE Agent, allowing applications to accept/ignore remote candidates (including newly discovered peer-reflexive candidates) based on their IP address.
Changes:
- Added
RemoteIPFiltertoAgentConfigandWithRemoteIPFilter(...)toAgentOption. - Applied remote IP filtering when adding remote candidates and when creating peer-reflexive candidates from inbound STUN Binding requests.
- Added tests covering both the synchronous/internal and async
AddRemoteCandidatepaths, plus the inbound prflx discovery path.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
agent_config.go |
Introduces AgentConfig.RemoteIPFilter for remote candidate admission policy. |
agent_options.go |
Adds WithRemoteIPFilter option to configure the filter via options API. |
agent.go |
Wires config/option into Agent, and enforces filtering for remote + prflx candidates. |
agent_options_test.go |
Adds unit test ensuring the option sets agent.remoteIPFilter. |
agent_test.go |
Adds behavioral tests ensuring remote filtering is enforced across code paths. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #898 +/- ##
==========================================
- Coverage 88.46% 88.45% -0.02%
==========================================
Files 45 45
Lines 5633 5654 +21
==========================================
+ Hits 4983 5001 +18
- Misses 447 449 +2
- Partials 203 204 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
412debe to
e090c2c
Compare
|
@sirzooro why is this need? i guess to filter out specific prflx candidates (applications can already filter other candidates), but do you have a specific real world usage in mind? |
For security purposes. Remote peer may send any address as a candidate, including addresses from local peer's internal network. I am not sure if this may be useful for some kind of attacks or not, so I want to block local IPs just in case. |
|
@sirzooro but applications can already filter remote candidates at their end, and ice users (including pion/webrtc) can filter remote candidates too. I thought this was about prflx candidates. |
|
@JoTurk right, although app would have to parse received candidates, and resolve mDNS ones. And of course prflx ones cannot be filtered there. New filter is also easier to use as it gets IP address as a parameter. |
|
Makes sense, I'll review the api and the change tonight, thank you. |
agent.go
Outdated
| if !a.shouldAcceptRemoteCandidate(prflxCandidate) { | ||
| return nil, false | ||
| } | ||
| remoteCandidate = prflxCandidate |
There was a problem hiding this comment.
can we make it so we call shouldAcceptRemoteCandidate once, even if we have to refactor this code? I'm worried that we might cause a weird behavior if we call the filter twice, e.g: if the user filter is not-idempotent.
There was a problem hiding this comment.
Good point. Fixed this and added test for it.
e090c2c to
19ce777
Compare
Add support for filtering remote candidate IP addresses before they are accepted by the agent.
19ce777 to
9ec45ae
Compare
Summary
This PR adds support for filtering remote candidate IP addresses before they are accepted by the agent.
A new
RemoteIPFiltercallback can now be configured via bothAgentConfigandWithRemoteIPFilter(...). The filter is applied consistently when:AddRemoteCandidate/ internaladdRemoteCandidateIf a remote candidate is rejected by policy (or its address cannot be parsed), it is ignored and not added.
Motivation
IPFiltercontrols local candidate gathering, but there was no symmetric policy control for incoming remote candidates. This change enables allowlist/blocklist style enforcement for remote candidate addresses.What changed
agent_config.goRemoteIPFilter func(net.IP) (keep bool)toAgentConfig.agent_options.goWithRemoteIPFilter(filter func(net.IP) bool) AgentOption.agent.goremoteIPFilterfield toAgent.AgentConfig.RemoteIPFilterinto agent construction.shouldAcceptRemoteCandidate(cand Candidate) bool.addRemoteCandidate.Tests
agent_options_test.goTestWithRemoteIPFilterOption.agent_test.goAddRemoteCandidateasynchronous path.WithRemoteIPFilterin non-updatable options test matrix.