Munge and restore Cookie on both frontend and backend

Factor this out to an include file common to front and backend

Change-Id: Ib72648d2def4e4fb18e8ea9b4dbdd7bee676ae09