title: How does Phoenix conglomerate cookie data?
body: <p>I'm attempting to store some data into the session storage and I'm getting the same cookie error as <a href="https://stackoverflow.com/questions/44583511/phoenix-framework-send-me-cookie-named-todolistmaster-key-exceeds-maximum-si">this guy</a>, the cookie is over the system byte limit of 4096.</p>
  <p>This seems pretty straight forward, don't attempt to store more than the system limit in the session. Right, but I'm not attempting to do that.  Clearly, the cookie is over 4096 bytes and my additions have caused it to overflow, but that doesn't explain where the data is.</p>
  <p>The data I'm attempting to store is only 1500 bytes.  In fact, the entire session that is being saved is 1500 bytes (the errored session).  Thats nowhere near the overflow limit.  So that means one thing for certain:  The data stored in <code>:plug_session</code> inside of <code>conn</code> is not the only data being stored inside of the session cookie.</p>
  <p>This is the session that's throwing the CookieOverflowError:</p>
  <pre><code>:plug_session =&gt; %{
        &quot;_csrf_token&quot; =&gt; &quot;XmE4kgdxk4D0NwwlfTL77Ic62t123123sdfh1s&quot;,
        &quot;page_trail&quot; =&gt; [{&quot;/&quot;, &quot;Catalog&quot;}, {'/', &quot;Catalog&quot;}],
        &quot;shopping_cart_changeset&quot; =&gt; #Ecto.Changeset&lt;
          action: nil,
          changes: %{
            order: #Ecto.Changeset&lt;
              action: :insert,
              changes: %{
                address: #Ecto.Changeset&lt;
                  action: :insert,
                  changes: %{
                    address_one: &quot;800 Arola Drive, apt 321, apt 321&quot;,
                    address_two: &quot;apt 321&quot;,
                    city: &quot;Wooster&quot;,
                    company: &quot;Thomas&quot;,
                    country: &quot;US&quot;,
                    name: &quot;user one&quot;,
                    phone: &quot;3305551111&quot;,
                    state: &quot;WV&quot;,
                    zip_code: &quot;44691&quot;
                  },
                  errors: [],
                  data: #FulfillmentCart.Addresses.Address&lt;&gt;,
                  valid?: true
                &gt;,
                priority: false,
                shipping_method: #Ecto.Changeset&lt;
                  action: :insert,
                  changes: %{id: 2, is_priority?: false, name: &quot;3 Day Select&quot;},
                  errors: [],
                  data: #FulfillmentCart.ShippingMethods.ShippingMethod&lt;&gt;,
                  valid?: true
                &gt;
              },
              errors: [],
              data: #FulfillmentCart.Orders.Order&lt;&gt;,
              valid?: true
            &gt;
          },
          errors: [],
          data: #FulfillmentCart.ShoppingCarts.ShoppingCart&lt;&gt;,
          valid?: true
        &gt;,
        &quot;user_id&quot; =&gt; 8
      },
  </code></pre>
  <p>I actually followed this guide on <a href="https://bitcrowd.dev/decoding-phoenix-session-cookies" rel="nofollow noreferrer">decoding a phoenix session cookie</a>, and I get the session before the error.</p>
  <p>Which gives me:</p>
  <pre><code>iex(8)&gt; [_, payload, _] = String.split(cookie, &quot;.&quot;, parts: 3)
  [&quot;SFMyNTY&quot;,
   &quot;g3QAAAADbQAAAAtfY3NyZl90b2tlbm0AAAAYWU92dkRfVDh5UXlRTUh4TGlpRTQxOFREbQAAAApwYWdlX3RyYWlsbAAAAAJoAm0AAAABL20AAAAHQ2F0YWxvZ2gCawABL20AAAAHQ2F0YWxvZ2ptAAAAB3VzZXJfaWRhCA&quot;,
   &quot;Ytg5oklzyWMvtu1vyXVvQ2xBzdtMnS9zVth7LIRALsU&quot;]
  iex(9)&gt; {:ok, encoded_term } = Base.url_decode64(payload, padding: false)
  {:ok,
   &lt;&lt;131, 116, 0, 0, 0, 3, 109, 0, 0, 0, 11, 95, 99, 115, 114, 102, 95, 116, 111,
     107, 101, 110, 109, 0, 0, 0, 24, 89, 79, 118, 118, 68, 95, 84, 56, 121, 81,
     121, 81, 77, 72, 120, 76, 105, 105, 69, 52, 49, ...&gt;&gt;}
  iex(10)&gt; :erlang.binary_to_term(encoded_term)
  %{
    &quot;_csrf_token&quot; =&gt; &quot;YOvvD_T8yQyQMHxLiiE418TD&quot;,
    &quot;page_trail&quot; =&gt; [{&quot;/&quot;, &quot;Catalog&quot;}, {'/', &quot;Catalog&quot;}],
    &quot;user_id&quot; =&gt; 8
  }
  iex(11)&gt;
  </code></pre>
  <p>This is 127 bytes, so the addition of the 1500 bytes isn't the problem.  It's the other allocation of storage that isn't represented inside of the session.  What is that?</p>