Skip to content

Commit fdda8f5

Browse files
nadavofitocker
authored andcommitted
Decode string to sign before creating the signature (#167)
1 parent 0a54a2d commit fdda8f5

File tree

4 files changed

+22
-2
lines changed

4 files changed

+22
-2
lines changed

lib/utils.js

Lines changed: 10 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/utils.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/utils.coffee

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,13 @@ exports.url = (public_id, options = {}) ->
492492
transformation = transformation.replace(/([^:])\/\//g, '$1/')
493493
if sign_url && _.isEmpty(auth_token)
494494
to_sign = [transformation, source_to_sign].filter((part) -> part? && part != '').join('/')
495+
i = 0;
496+
try
497+
while (to_sign != decodeURIComponent(to_sign) && i<10)
498+
to_sign = decodeURIComponent(to_sign)
499+
i++
500+
catch
501+
495502
shasum = crypto.createHash('sha1')
496503
shasum.update(utf8_encode(to_sign + api_secret), 'binary')
497504
signature = shasum.digest('base64').replace(/\//g, '_').replace(/\+/g, '-').substring(0, 8)

test/utils_spec.coffee

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ describe "utils", ->
104104
expected_signature = utils.url("test", format:"jpg", angle:0, sign_url:true).match(/s--[0-9A-Za-z_-]{8}--/).toString()
105105
test_cloudinary_url("test", {url_suffix:"hello", private_cdn:true, format:"jpg", angle:0, sign_url:true}, "http://#{cloud_name}-res.cloudinary.com/images/#{expected_signature}/a_0/test/hello.jpg", {})
106106

107+
it "should sign the decoded form of a url" , ->
108+
expected_signature = utils.url("%25a%20(b)", format:"jpg", sign_url:true).match(/s--[0-9A-Za-z_-]{8}--/).toString()
109+
test_cloudinary_url("%25a%20(b)", {format:"jpg", sign_url:true}, "http://res.cloudinary.com/#{cloud_name}/image/upload/#{expected_signature}/%25a%20(b).jpg", {})
110+
107111
it "should support url_suffix for raw uploads" , ->
108112
test_cloudinary_url("test", {url_suffix:"hello", private_cdn:true, resource_type:'raw'}, "http://#{cloud_name}-res.cloudinary.com/files/test/hello", {})
109113

0 commit comments

Comments
 (0)