Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MaintenanceWindowLambdaParameters Payload incorrect validation. #2004

Open
blade2005 opened this issue Jan 20, 2022 · 3 comments
Open

MaintenanceWindowLambdaParameters Payload incorrect validation. #2004

blade2005 opened this issue Jan 20, 2022 · 3 comments

Comments

@blade2005
Copy link

Per the documents here https://docs.aws.amazon.com/AWSCloudFormation/latest/UserGuide/aws-properties-ssm-maintenancewindowtask-maintenancewindowlambdaparameters.html#cfn-ssm-maintenancewindowtask-maintenancewindowlambdaparameters-payload

"Although Type is listed as "String" for this property, the payload content must be formatted as a Base64-encoded binary data object."

https://github.com/cloudtools/troposphere/blob/main/troposphere/ssm.py#L194 validates that it's proper JSON but the expected value should be base64 encoded JSON string.

@markpeek
Copy link
Member

Interesting. Thanks for highlighting this issue. One solution would be using Fn::Base64 although that would likely break for encoded strings larger than 4096. Perhaps a validator like this? (untested)

def validate_json_base64(payload):
    """
    Property: MaintenanceWindowLambdaParameters.Payload
    """
    import base64
    import json
    from .. import AWSHelperFn

    if isinstance(payload, AWSHelperFn):
        return payload
    elif isinstance(payload, str):
        # Verify it is a valid json string
        payload = json.loads(payload)
    elif isinstance(payload, dict):
        # Convert the dict to a basestring
        payload = json.dumps(payload)
    else:
        raise TypeError("json object must be a str or dict")

    # base64 encode and check length
    payload = base64.b64encode(bytes(payload, 'utf-8')).decode()
    if len(payload) > 4096:
        raise ValueError("payload is greater than 4096 (base64 encoded)")

    return payload

@markpeek
Copy link
Member

@blade2005 have you had a chance to review or try the above?

@blade2005
Copy link
Author

@markpeek somehow I missed this notification. The code looks like it would work. I've not tried it. I'm no longer working on that project anymore.

I'm not sure if the 4096 constraint is on base64 encoded data or the decoded format.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants