Geddy Router issue with base64 param #556

Closed
hamzazar opened this Issue Feb 26, 2014 · 8 comments

4 participants

@hamzazar

When I pass a json object in base64 as a url parameter I got error route not found.. I think that due to the "=" in the end of this param. If I encode the parameter "url encode" the % also generate the same error

@mde

This sounds like a bug with our router, which is https://github.com/kieran/barista -- @kieran, can you take a quick look at this?

@kieran

Interesting, will take a look!

@kieran

I can't seem to reproduce - can you provide steps?

tried with a base64 encoded string that ended in =, as well as various strings that ended in %

@hamzazar

First I define my router

router.get(routing_prefix+'/gogetthecart/:data').to('Main.gogetthecart');

after that in a client side, here I use javascript, I generated a base64 variable from the json

this is my json
params = {
"identification": "26edb510-072b-b944-25b1-6f0a148a2d42",
"cart": [
{
"id_fiche": "1b7940f2f4d88",
"sku": "2394ed0c2ac59a2c6829d8df202e23cd",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "119862119ee1142b15c39455d69e9372",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "7a3bdac360792a27d0ca8dcf2c5076a8",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "baf78e2e34be2c76b1bd4c76d3e7988e",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "23fbe7458f951e6e23aa1e7ed038f3b4",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "6d982b97239bc92460d7299b6aff0450",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "39451b8bfbae2506f1630a25f591d6fa",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "6fbc21af3085819eb30529a12ce0f246",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "b679a60426632ec5ff982ec6b4309f07",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "1f2219183f21a54c285468634e2a9817",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "9c6aa3f1c216320f255eab275cda6a1a",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "8035757dc4414f845fae08d61676d59b",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "1951dd4ba3c069f10d09a172548e4530",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "4056badadefdcf02c74c58ca3d61c253",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "6d3f78a6c912ddbe2362a7e9df0599c4",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "b2d54987984e8736320d956aafee939c",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "3b3d3427627af22bfbc4def40983d179",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "022290d0f947e4c418499c28bed326ef",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "4d241248657287b1f5ed6b3ef965daee",
"quantity": "0"
},
{
"id_fiche": "1b7940f2f4d88",
"sku": "2c64b1568ebc8caeec34eb180bc204e0",
"quantity": "0"
}
]
}

var jsonb64 = btoa(JSON.stringify(params));
location.href = "<%= base_url %>/gogetthecart/"+jsonb64;

I got the error below, If I manually delete the "=" in the end, that work..

Error: 404 Not Found

/gogetthecart/eyJpZGVudGlmaWNhdGlvbiI6ImNhOWRlOTJhLTBjNTYtOTIxMS00YjgyLTA0M2JhMTVhYjI0ZCIsImNhcnQiOlt7ImlkX2ZpY2hlIjoiMWI3OTQwZjJmNGQ4OCIsInNrdSI6IjIzOTRlZDBjMmFjNTlhMmM2ODI5ZDhkZjIwMmUyM2NkIiwicXVhbnRpdHkiOiIwIn0seyJpZF9maWNoZSI6IjFiNzk0MGYyZjRkODgiLCJza3UiOiIxMTk4NjIxMTllZTExNDJiMTVjMzk0NTVkNjllOTM3MiIsInF1YW50aXR5IjoiMCJ9LHsiaWRfZmljaGUiOiIxYjc5NDBmMmY0ZDg4Iiwic2t1IjoiN2EzYmRhYzM2MDc5MmEyN2QwY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WFudGl0eSI6IjAifSx7ImlkX2ZpY2hlIjoiMWI3OTQwZjJmNGQ4OCIsInNrdSI6IjE5NTFkZDRiYTNjMDY5ZjEwZDA5YTE3MjU0OGU0NTMwIiwicXVhbnRpdHkiOiIwIn0seyJpZF9maWNoZSI6IjFiNzk0MGYyZjRkODgiLCJza3UiOiI0MDU2YmFkYWRlZmRjZjAyYzc0YzU4Y2EzZDYxYzI1MyIsInF1YW50aXR5IjoiMCJ9LHsiaWRfZmljaGUiOiIxYjc5NDBmMmY0ZDg4Iiwic2t1IjoiNmQzZjc4YTZjOTEyZGRiZTIzNjJhN2U5ZGYwNTk5YzQiLCJxdWFudGl0eSI6IjAifSx7ImlkX2ZpY2hlIjoiMWI3OTQwZjJmNGQ4OCIsInNrdSI6ImIyZDU0OTg3OTg0ZTg3MzYzMjBkOTU2YWFmZWU5MzljIiwicXVhbnRpdHkiOiIwIn0seyJpZF9maWNoZSI6IjFiNzk0MGYyZjRkODgiLCJza3UiOiIzYjNkMzQyNzYyN2FmMjJiZmJjNGRlZjQwOTgzZDE3OSIsInF1YW50aXR5IjoiMCJ9LHsiaWRfZmljaGUiOiIxYjc5NDBmMmY0ZDg4Iiwic2t1IjoiMDIyMjkwZDBmOTQ3ZTRjNDE4NDk5YzI4YmVkMzI2ZWYiLCJxdWFudGl0eSI6IjAifSx7ImlkX2ZpY2hlIjoiMWI3OTQwZjJmNGQ4OCIsInNrdSI6IjRkMjQxMjQ4NjU3Mjg3YjFmNWVkNmIzZWY5NjVkYWVlIiwicXVhbnRpdHkiOiIwIn0seyJpZF9maWNoZSI6IjFiNzk0MGYyZjRkODgiLCJza3UiOiIyYzY0YjE1NjhlYmM4Y2FlZWMzNGViMTgwYmMyMDRlMCIsInF1YW50aXR5IjoiMCJ9XX0= not found.

@kieran

I looked into adding support for base64 encoded vars to Barista directly, but some characters in the b64 spec are reserved in the URI spec. I don't feel comfortable making that the default behaviour.

However! You can simply override the behaviour to support this use case:

router
.get( routing_prefix+'/gogetthecart/:data')
.to('Main.gogetthecart')
.where({
  data: /[\w\-\/+]+={0,2}/ // base64-safe regex condition
})

and that should do the trick!

I added a test here: https://github.com/kieran/barista/blob/master/tests/barista.test.js#L812

@kieran kieran closed this Feb 28, 2014
@mde

Excellent, thanks!

@hamzazar

Thanks @kieran and @mde the solution of

.where({
data: /[\w-\/+]+={0,2}/ // base64-safe regex condition
})

solve the problem. But also when I url encoded the b64 parameter, I get the same problem. In javascript I

jsonb64 = encodeURIComponent(jsonb64);

and I pass it to the url.. The problem that the "=" transformed to "%3D" after encode and seems Like the "%" character also not allowed because I get the same Error: 404 Not Found. But If I manually delete "%" I get a response!!

@molda

Hi just a thought but couldn't you simply use

localhost:4000/routing_prefix/gogetthecart?data=yourBase64JsonWithEqualSign=

you get your data in params.data even with your current route

  this.gogetthecart = function (req, resp, params) {
    console.log(params.data);
    // => yourBase64JsonWithEqualSign=
  };

it doesn't work with % => URIError: URI malformed

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