techservicesillinois / vcrpy-cleaner

Sensitive data cleaners for network cassettes captured by the VCR.py testing library.
0 stars 0 forks source link

Arbitrary string cleaner #11

Closed edthedev closed 1 year ago

edthedev commented 1 year ago

Context

Would be helpful to have a function that replaces any given string (ideally set in an environment variable, so that sensitive strings can be added) from response and body text.

  clean_strings = os.environ.get('CLEAN_STRINGS', "").split(',')
 for clean_me in clean_strings:
     response['body']['string'] = response['body']['string'].replace(clean_me, 'CLEANED')
edthedev commented 1 year ago

Here's code that's working in secops-soar-tdx:

# TODO: Move clean_env_string into the vcr_cleaner library for shared use.
def clean_env_strings(request: dict, response: dict):
    clean_strings = os.environ.get('CLEAN_STRINGS', "").split(',')
    if 'bytes' in str(type(response['body']['string'])):
        return
    body = response['body']['string']
    for clean_me in clean_strings:
        body = body.replace(clean_me, 'CLEANED')
    response['body']['string'] = body