diff --git a/isso/utils.py b/isso/utils.py index 6aa686d..6953447 100644 --- a/isso/utils.py +++ b/isso/utils.py @@ -101,9 +101,14 @@ def heading(host, path): def anonymize(remote_addr): ip = ipaddress.ip_address(remote_addr) - if ip.version == "4": + try: + ipv4 = ipaddress.IPv4Address(remote_addr) return ''.join(ip.exploded.rsplit('.', 1)[0]) + '.' + '0' - return ip.exploded.rsplit(':', 5)[0] + except ipaddress.AddressValueError: + ipv6 = ipaddress.IPv6Address(remote_addr) + if ipv6.ipv4_mapped is not None: + return anonymize(ipv6.ipv4_mapped) + return ip.exploded.rsplit(':', 5)[0] def salt(value, s=u'\x082@t9*\x17\xad\xc1\x1c\xa5\x98'): diff --git a/isso/views/comment.py b/isso/views/comment.py index 53084d0..fb2e99e 100644 --- a/isso/views/comment.py +++ b/isso/views/comment.py @@ -57,7 +57,7 @@ def create(app, environ, request, uri): if "id" in data and not isinstance(data["id"], int): return Response("Parent ID must be an integer.") - if "email" in data: + if data.get("email"): hash = data["email"] else: hash = utils.salt(utils.anonymize(unicode(request.remote_addr)))