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

Change custom policy documents in getPrivateUrl to be base64-encoded #5

Closed
wants to merge 1 commit into from
Closed

Conversation

bsorbo
Copy link

@bsorbo bsorbo commented Oct 3, 2012

Hi, I noticed that AWS rejects URL's generated by getPrivateUrl when custom policy parameters are used, such as 'IpAddress'.

It looks like the policy document is supposed to be encoded in base64 prior to being added to the URL (which makes sense). The documentation is actually pretty vague on this, but the PHP code example clearly shows this happening:

..
$canned_policy = '{"Statement":[{"Resource":"' . $video_path . '","Condition":{"DateLessThan":{"AWS:EpochTime":'. $expires . '}}}]}';
// the policy contains characters that cannot be part of a URL,
// so we Base64 encode it
$encoded_policy = url_safe_base64_encode($canned_policy);
..

http://docs.amazonwebservices.com/AmazonCloudFront/latest/DeveloperGuide/CreateURL_PHP.html

Let me know if there's a better way to implement this (small) change, thanks.

@tellnes
Copy link
Owner

tellnes commented Oct 4, 2012

Looks like I forgot the base64 part. But the rest of the line is correct. If you look at the implementation of url_safe_base64_encode, it does little more than just base64 encode the string. It also replaces the characters +, = and / with -, _ and ~.

When i tests a little, it does not look like it is nessesary to replacing those characters, but the php example code does that, so I think we should do it also.

What I probably intended to write was something like this:

policy = new Buffer(policy).toString('base64');
query["Policy"] = policy.replace(/\+/g, '-').replace(/\=/g, '_').replace(/\//g, '~');

Can you update the code to include the replacing part?

@mr-mig
Copy link

mr-mig commented Sep 7, 2013

Would you be so kind to merge this pull request?

@tellnes
Copy link
Owner

tellnes commented Sep 11, 2013

@mr-mig Sorry for the delay. I've fixed it now and published a new version to npm.

@tellnes tellnes closed this Sep 11, 2013
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

Successfully merging this pull request may close these issues.

3 participants