Forked from seanieb/csv_generated_string_escape.py
Last active
August 22, 2023 23:44
-
-
Save ZephrFish/ab951ca43d95f68e557c9c2e5ca6f2cc to your computer and use it in GitHub Desktop.
Prevent CSV Injection when suing user generated data
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def escape_csv(payload): | |
if payload[0] in ('@','+','-', '=', '|'): | |
payload = "'" + payload | |
payload = payload.replace("|", "\|") | |
return payload | |
# Example | |
payload = "@cmd|' /C calc'!A0" | |
print("The Unescaped version is: " + payload) | |
print("When passed though escape function the value is: " + escape_csv(payload)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Tiny comment: the last two lines should instead be