
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
A Python package for replacing hostnames, domains, and IP addresses in text under common encoding schemes.
Install with pip: pip install host-replace
Install from source:
git clone https://github.com/adamreiser/host_replace
cd host-replace
pip install .
Transform the following text file using the provided mapping: host-replace -m mappings.json sample.txt --verbose
1. https://web.example.com/path/to/resource?query=param
2. <a href="https://boards.example.com/thread/123">Discussion Board</a>
3. Redirecting to https%3A%2F%2Fen.us.wiki.example.com%2Fwelcome
4. https://web-1a.example.com/redirect?q=%65%6e%2e%75%73%2e%77%69%6b%69%2e%65%78%61%6d%70%6c%65%2e%63%6f%6d
5. <meta http-equiv="refresh" content="0; url=https%3A%2F%2Fweb.example.com%2Fhome">
6. Our domain is still example.com and archived wiki will remain at archive.en.us.wiki.example.com.
{
"web.example.com": "www.example.com",
"web-1a.example.com": "www-1a.example.com",
"boards.example.com": "forums.en.us.example.com",
"en.us.wiki.example.com": "wiki.example.com",
"us.example.com": "us-east-1.example.net",
"example.net": "example.org",
"images.example.com": "cdn.example.org"
}
Output:
INFO: Replacing web.example.com with www.example.com at offset 11
INFO: Replacing boards.example.com with forums.en.us.example.com at offset 91
INFO: Replacing en.us.wiki.example.com with wiki.example.com at offset 195
INFO: Replacing web-1a.example.com with www-1a.example.com at offset 239
INFO: Replacing %65%6e%2e%75%73%2e%77%69%6b%69%2e%65%78%61%6d%70%6c%65%2e%63%6f%6d with %77%69%6b%69%2e%65%78%61%6d%70%6c%65%2e%63%6f%6d at offset 269
INFO: Replacing web.example.com with www.example.com at offset 396
1. https://www.example.com/path/to/resource?query=param
2. <a href="https://forums.en.us.example.com/thread/123">Discussion Board</a>
3. Redirecting to https%3A%2F%2Fwiki.example.com%2Fwelcome
4. https://www-1a.example.com/redirect?q=%77%69%6b%69%2e%65%78%61%6d%70%6c%65%2e%63%6f%6d
5. <meta http-equiv="refresh" content="0; url=https%3A%2F%2Fwww.example.com%2Fhome">
6. Our domain is still example.com and archived wiki will remain at archive.en.us.wiki.example.com.
To use the module in your Python application:
import host_replace
host_map = {
"web.example.com": "www.example.com",
"boards.example.com": "forums.example.net"
}
replacer = host_replace.HostnameReplacer(host_map)
# Input text (str or bytes)
input_text = "Visit us at https://web.example.com or leave a comment at https://boards.example.com."
# Apply replacements
output_text = replacer.apply_replacements(input_text)
# Output: Visit us at https://www.example.com or leave a comment at https://forums.example.net.
print(output_text)
Does not detect encoded uppercase characters. This is generally rare and occurs when an entire hostname is URL or entity encoded with uppercase letters.
Full case preservation of individual characters is not supported due to its inherent ambiguity. For example, when mapping WWW.example.com
to example.org
, it's unclear which if any letters should be capitalized.
Variations in encoding representation (e.g., "%2F" vs "%2f"; "/" vs "/") can lead to inconsistent outputs.
Does not process binary data beyond exact byte sequence matching. Encodings like base64 are not supported.
Hostnames starting with hex codes can be ambiguous when preceded by %. For instance, %00example.com
could be interpreted as example.com
or 00example.com
.
Support for Internationalized Domain Names (IDNs) has not been thoroughly tested.
FAQs
Replace host and domain names in text under various encoding schemes.
We found that host-replace demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.