Skip to content

Instantly share code, notes, and snippets.

@iSpeakNerd
Last active April 27, 2023 16:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iSpeakNerd/7261feaf97d25a55d173cedeb4568544 to your computer and use it in GitHub Desktop.
Save iSpeakNerd/7261feaf97d25a55d173cedeb4568544 to your computer and use it in GitHub Desktop.
python script to remove addresses/names included in Rotki verbose log files. useful when sending debug info to the team

Preserving your privacy with verbose logs

Logs created by running in debug mode can expose your private information such as addresses.

To preserve your privacy, you can run a regex find and replace script on your log file to redact your private information.

The python script below is provided for inspiration and we make no guarantees. DO NOT make assumptions about the privacy this provides and do not share wtih anyone other than rotki developers.

import re

# The string to search in, c/p your log file
string = "<c/p_YOUR_LOG_HERE>"

# The regex patterns to search for
## Api keys
pattern_1 = re.compile(r"&apikey=[\da-zA-Z]{0,}")
## Eth addresses + strings
pattern_2 = re.compile(r"0x[\da-zA-Z]{3,}")
pattern_3 = re.compile(r"0x[\da-zA-Z]{40}")
## btc xpub + ypub addresses
pattern_4 = re.compile(r"xpub[\da-zA-Z]{2,}")
pattern_5 = re.compile(r"ypub[\da-zA-Z]{2,}")
## addresses inside api calls
pattern_6 = re.compile(r"&data=[\da-zA-Z]{0,}")
pattern_7 = re.compile(r"\|[\da-zA-Z]{2,}")
pattern_8 = re.compile(r"\?active=[\da-zA-Z]{2,}")
## Your name!
pattern_9 = re.compile("{REPLACE_YOUR_NAME_HERE}")
##DOT/KSM addresses
pattern_10 = re.compile(r"'address': '[\da-zA-Z]+'")


# The replacement strings
replacement_1 = "&apikey=<APIKEY_REDACTED>"
replacement_2 = "0x<ETH_STRING_REDACTED>"
replacement_3 = "0x<ETH_ADDRESS_REDACTED>"
replacement_4 = "xpub<BTC_ADDRESS_REDACTED>"
replacement_5 = "ypub<BTC_ADDRESS_REDACTED>"
replacement_6 = "&data=<PI_DATA_REDACTED>"
replacement_7 = "|<ADDRESS_REDACTED>"
replacement_8 = "?active=<ADDRESS_REDACTED>"
replacement_9 = "<NAME_REDACTED>"
replacement_10 = "'address': '<ADDRESS_REDACTED>'"

# Use the re.sub() function to perform the find and replace
## Sequential find + replace

res_1 = pattern_1.sub(replacement_1, string)
res_2 = pattern_2.sub(replacement_2, res_1)
res_3 = pattern_3.sub(replacement_3, res_2)
res_4 = pattern_4.sub(replacement_4, res_3)
res_5 = pattern_5.sub(replacement_5, res_4)
res_6 = pattern_6.sub(replacement_6, res_5)
res_7 = pattern_7.sub(replacement_7, res_6)
res_8 = pattern_8.sub(replacement_8, res_7)
res_9 = pattern_9.sub(replacement_9, res_8)
res_10 = pattern_10.sub(replacement_10, res_9)

# Print!
print("Original string \n" + str(string))
print("Privatized string \n" + str(res_10))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment