Skip to content

Url base 64 is broken #6

Description

@lud-gfi

Hello,

I ported the code to an old version of CFML. I don't know if you face this problem, but the padding function was broken :

	function convertToBase64( input ) {
		input = replace( input, "-", "+", "all" );
		input = replace( input, "_", "/", "all" );
		var paddingLength = ( 4 - ( len( input ) mod 4 ) );
		return( input & repeatString( "=", paddingLength ) );
	}

When the input length is a multiple of 4, the modulo yields 0, so 4 - 0 yields 4, and we have a useless padding ==== added to the string.

If figured out with this simple payload : 'payload' (i.e. the simple word "payload" as a string. The JSON version ("payload") will be transformed to "payload when decoding (so there is a missing quote), and the JSON unserialize will just yield null.

I'm not 100% sure wether this behaviour is because of the unwanted padding, but the problem disappears with this dumb version of the function :

	function convertToBase64( input ) {
		input = replace( input, "-", "+", "all" );
		input = replace( input, "_", "/", "all" );
		switch(len( input ) mod 4) {
			case 1: return input & '===';
			case 2: return input & '==';
			case 3: return input & '=';
			default: return input;
		}
	}

I will not make a pull request because of the old version of the code we are using and because I'm not sure of what is the deep truth about this :)

Cheers.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions