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

Issues with decoding rails 3.2 cookie - only string ivars are supported #15

Closed
simonbowen opened this issue Feb 22, 2017 · 1 comment
Closed

Comments

@simonbowen
Copy link

I'm trying to use ExMarshal to decode the contents of a cookie set by rails. This is the ruby structure that is stored in the cookie in a marshal format.

{"session_id"=>"c0a56012635b795b0f6bd6a522fe3fae",
 "after_sign_up_redirect_to"=>"/",
 "after_sign_in_redirect_to"=>"/",
 "omniauth.is_abode"=>false,
 "warden.user.user.key"=>[[70989], "$2a$10$D4Msl4T4JHfkFOQHi0fKTe"],
 "warden.user.user.session"=>{"last_request_at"=>2017-02-22 20:44:16 UTC},
 "foo"=>"bar",
 "_csrf_token"=>"QUBPx+eyL2deFkAo3pA+xxMZmVso7hfLutVJlJoT8kg="}

The base64 of the Marshal object looks like..

BAh7DUkiD3Nlc3Npb25faWQGOgZFVEkiJWMwYTU2MDEyNjM1Yjc5NWIwZjZiZDZhNTIyZmUzZmFlBjsAVEkiHmFmdGVyX3NpZ25fdXBfcmVkaXJlY3RfdG8GOwBGSSIGLwY7AFRJIh5hZnRlcl9zaWduX2luX3JlZGlyZWN0X3RvBjsARkkiBi8GOwBUSSIWb21uaWF1dGguaXNfYWJvZGUGOwBURkkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsHWwZpA00VAUkiIiQyYSQxMCRENE1zbDRUNEpIZmtGT1FIaTBmS1RlBjsAVEkiHXdhcmRlbi51c2VyLnVzZXIuc2Vzc2lvbgY7AFR7BkkiFGxhc3RfcmVxdWVzdF9hdAY7AFRJdToJVGltZQ3URh3A2pgMsQY6CXpvbmVJIghVVEMGOwBGSSIIZm9vBjsARkkiCGJhcgY7AFRJIhBfY3NyZl90b2tlbgY7AEZJIjFRVUJQeCtleUwyZGVGa0FvM3BBK3h4TVptVnNvN2hmTHV0VkpsSm9UOGtnPQY7AEY=

I'm then decoding this on the Elixir end with

iex> {:ok, r} = Base.decode64("BAh7DUkiD3Nlc3Npb25faWQGOgZFVEkiJWMwYTU2MDEyNjM1Yjc5NWIwZjZiZDZhNTIyZmUzZmFlBjsAVEkiHmFmdGVyX3NpZ25fdXBfcmVkaXJlY3RfdG8GOwBGSSIGLwY7AFRJIh5hZnRlcl9zaWduX2luX3JlZGlyZWN0X3RvBjsARkkiBi8GOwBUSSIWb21uaWF1dGguaXNfYWJvZGUGOwBURkkiGXdhcmRlbi51c2VyLnVzZXIua2V5BjsAVFsHWwZpA00VAUkiIiQyYSQxMCRENE1zbDRUNEpIZmtGT1FIaTBmS1RlBjsAVEkiHXdhcmRlbi51c2VyLnVzZXIuc2Vzc2lvbgY7AFR7BkkiFGxhc3RfcmVxdWVzdF9hdAY7AFRJdToJVGltZQ3URh3A2pgMsQY6CXpvbmVJIghVVEMGOwBGSSIIZm9vBjsARkkiCGJhcgY7AFRJIhBfY3NyZl90b2tlbgY7AEZJIjFRVUJQeCtleUwyZGVGa0FvM3BBK3h4TVptVnNvN2hmTHV0VkpsSm9UOGtnPQY7AEY=")
iex> ExMarshal.decode(r)

However I get this error

** (ExMarshal.DecodeError) only string ivars are supported: <<58, 9, 84, 105, 109, 101, 13, 212, 70, 29, 192, 218, 152, 12, 177, 6, 58, 9, 122, 111, 110, 101, 73, 34, 8, 85, 84, 67, 6, 59, 0, 70, 73, 34, 8, 102, 111, 111, 6, 59, 0, 70, 73, 34, 8, 98, 97, 114, 6, 59, ...>>                                                                                       lib/ex_marshal/decoder.ex:109: ExMarshal.Decoder.decode_ivar/2
                         lib/ex_marshal/decoder.ex:248: ExMarshal.Decoder.decode_hash/4
                         lib/ex_marshal/decoder.ex:4: ExMarshal.Decoder.decode/1
                (stdlib) erl_eval.erl:670: :erl_eval.do_apply/6
                   (iex) lib/iex/evaluator.ex:182: IEx.Evaluator.handle_eval/6
                   (iex) lib/iex/evaluator.ex:175: IEx.Evaluator.do_eval/4
                   (iex) lib/iex/evaluator.ex:155: IEx.Evaluator.eval/4
                   (iex) lib/iex/evaluator.ex:61: IEx.Evaluator.loop/3
                   (iex) lib/iex/evaluator.ex:21: IEx.Evaluator.init/4
                   (iex) lib/iex.ex:471: IEx.pry/3
    (infabode_analytics) web/controllers/dashboard_controller.ex:9: InfabodeAnalytics.DashboardController.index/2
    (infabode_analytics) web/controllers/dashboard_controller.ex:1: InfabodeAnalytics.DashboardController.action/2
    (infabode_analytics) web/controllers/dashboard_controller.ex:1: InfabodeAnalytics.DashboardController.phoenix_controller_pipeline/2
    (infabode_analytics) lib/infabode_analytics/endpoint.ex:1: InfabodeAnalytics.Endpoint.instrument/4
    (infabode_analytics) lib/phoenix/router.ex:261: InfabodeAnalytics.Router.dispatch/2
    (infabode_analytics) web/router.ex:1: InfabodeAnalytics.Router.do_call/2
    (infabode_analytics) lib/infabode_analytics/endpoint.ex:1: InfabodeAnalytics.Endpoint.phoenix_pipeline/1
    (infabode_analytics) lib/plug/debugger.ex:123: InfabodeAnalytics.Endpoint."call (overridable 3)"/2

I'm at a bit of loss since I've been manually creating objects in the ruby console encoding them with marshal and then base64 encoding it. Copying the base64 string across to the Elixir console, base64 decoding and decoding with ExMarshal and it works.

Is there something in my cookie structure that is causing ExMarshal to throw this error?

@simonbowen
Copy link
Author

Duh, it's because my marshal serialization has a date type in, I didn't fully read the docs and see that this isn't supported by ExMarshal.

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

1 participant