Skip to content

IP fetching failure causes failure in web_reader_read tool #71

Description

@n0ech

In modules\http.py:

lines 803-808:

        try:
            self.server_ipv4 = urllib.request.urlopen("https://api.ipify.org").read().decode()
            self.server_ipv6 = urllib.request.urlopen("https://api64.ipify.org").read().decode()
        except:
            self.server_ipv4 = None
            self.server_ipv6 = None

And then lines 946-952:

def _censor_ip(self, text: str) -> str:
        """Replaces IPv4 and IPv6 addresses with [CENSORED_IP]."""
        if not isinstance(text, str):
            return text
        text = text.replace(self.server_ipv4, "[CENSORED_IP]")
        text = text.replace(self.server_ipv6, "[CENSORED_IP]")
        return text

If there's an exception getting the IPv4/IPv6 addresses, they get set to None, which causes the text.replace() to fail when invoking _censor_ip.
Updating the second block by wrapping the text replacements in if statements like this fixes the issue:

    def _censor_ip(self, text: str) -> str:
        """Replaces IPv4 and IPv6 addresses with [CENSORED_IP]."""
        if not isinstance(text, str):
            return text
        if self.server_ipv4 is not None:
            text = text.replace(self.server_ipv4, "[CENSORED_IP]")
        if self.server_ipv6 is not None:
            text = text.replace(self.server_ipv6, "[CENSORED_IP]")
        return text

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions