Skip to content

Cloudwatch log custom data identifier not masking the data

0

Hi,

I'm trying to mask lastName using a custom data identifier for the below JSON data and it doesn't work as the entire data including the identifier lastName is getting masked. Any guidance on this please ?

{ "ifsUuid": "123abc", "experienceType": null, "ifsAppID": null, "email": "abc@abc.org", "firstName": "123456789", "lastName": "ABC", "title": null, "jobTitle": null, "organisation": { "name": "ABC", "registrationNumber": "123", "registeredAddress": { "buildingName": "ABC", "street": "", "locality": "", "town": "ABC", "postcode": "123", "country": "" }, "srcSysOrgId": "138" }, "sourceSystem": "IFS", "srcSysContactId": "396", "phoneNumber": "01234567899", "Address": null }

AWS

asked 10 months ago113 views

2 Answers
0

The issue is that CloudWatch is masking the entire matched text. You need to structure it so only part of the match is masked. CloudWatch data identifiers don't have fine-grained control over partial masking.

You can possibly pre-process Before Logging. Mask the data in your application before it reaches CloudWatch:

def mask_sensitive_data(data):
    """Mask sensitive fields before logging"""
    if 'lastName' in data:
        data['lastName'] = '***'
    return data

def lambda_handler(event, context):
    test_data = {
        "ifsUuid": "123abc",
        "email": "abc@abc.org",
        "firstName": "123456789",
        "lastName": "ABC",
        "phoneNumber": "01234567899"
    }
    
    # Mask before logging
    safe_data = mask_sensitive_data(test_data.copy())
    logger.info(json.dumps(safe_data))
    
    return {'statusCode': 200}

this should result it

{"lastName": "***", "firstName": "123456789"}

answered 10 months ago

0

Hi, thanks for the response. If I don't want pre-mask, what is the structure expected by CW to mask the data ? I'm using a regular expression which should ideally mask after it finds the text lastName.

AWS

answered 10 months ago

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.