Skip to content

Commit

Permalink
XMLRPC server accepts request from all local IP addresses. (#729)
Browse files Browse the repository at this point in the history
Signed-off-by: Tomoya Fujita <[email protected]>
  • Loading branch information
fujitatomoya authored Jul 6, 2022
1 parent f46fa80 commit c7d3204
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion ros2cli/ros2cli/xmlrpc/local_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,19 @@
from xmlrpc.server import SimpleXMLRPCRequestHandler # noqa
from xmlrpc.server import SimpleXMLRPCServer

import netifaces


def get_local_ipaddrs():
iplist = []
interfaces = netifaces.interfaces()
for interface in interfaces:
addrs = netifaces.ifaddresses(interface)
if netifaces.AF_INET in addrs.keys():
for value in addrs[netifaces.AF_INET]:
iplist.append(value['addr'])
return iplist


class LocalXMLRPCServer(SimpleXMLRPCServer):

Expand All @@ -37,6 +50,6 @@ def get_request(self):
return sock, addr

def verify_request(self, request, client_address):
if client_address[0] != '127.0.0.1':
if client_address[0] not in get_local_ipaddrs():
return False
return super(LocalXMLRPCServer, self).verify_request(request, client_address)

0 comments on commit c7d3204

Please sign in to comment.