Created
February 3, 2021 04:27
-
-
Save LRENZ/425d40e3ff4caa60488be033cd642cb4 to your computer and use it in GitHub Desktop.
JS snippet to delete PII
This file contains 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
function Pii(string){ | |
var piiRegex = [{ | |
name: 'EMAIL', | |
regex: /(\&|\?|\#)(email|e-mail|mail)=[^&#]+/gi | |
},{ | |
name: 'EMAIL', | |
regex: /[^&?=#]+(@|%40)[^@&?=#]+\.[^@&?=#]+/gi | |
},{ | |
name: 'ADDRESS', | |
regex: /(\&|\?|\#)address=[^&#]+/gi | |
},{ | |
name: 'NAME', | |
regex: /(\&|\?|\#)(firstname|surname|prenom|lastname|name|nom|username)=[^&#]+/gi | |
},{ | |
name: 'PASSWORD', | |
regex: /(\&|\?|\#)(password|pwd)=[^&#]+/gi | |
},{ | |
name: 'PHONE', | |
regex: /(\&|\?|\#)phone=[^&#]+/gi | |
}]; | |
try { | |
var val = decodeURIComponent(decodeURIComponent(string)); | |
} catch(e) { | |
val = decodeURIComponent(string); | |
} | |
piiRegex.forEach(function(pii) { | |
if(val.match(pii.regex) !== null && val.match(pii.regex)[0].split('=').length > 1){ | |
val = val.replace(pii.regex, val.match(pii.regex)[0].split('=')[0] + '=[DELETED ' + pii.name + ']'); | |
} | |
else{ | |
val = val.replace(pii.regex, '[DELETED ' + pii.name + ']'); | |
} | |
}); | |
return val | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment