# Rescue\_from TamperedWithCookie error?

**URL:** <https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537>\
**Category:** Rails\
**Created:** [December 9, 2007, 12:48am UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537 "2007-12-09T00:48:04Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [December 9, 2007, 12:48am UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/1 "2007-12-09T00:48:04Z")

</div>

I submitted a ticket about this, but I thought perhaps I should ping  
this mailing list as well.

When deploying an an app that was upgraded to run on Rails 2.0 and use  
cookie sessions, users that are logged into the site receive an error:  
CGI::Session::CookieStore::TamperedWithCookie when they first visit the  
site. When they refresh once, this error will no longer appear. However,  
I can’t figure out how to work around them seeing an Application Error  
screen the first time. Is there any way to rescue\_from this error, or  
otherwise avoid encountering it all together?

[http://dev.rubyonrails.org/ticket/10427](http://dev.rubyonrails.org/ticket/10427)

---

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [December 9, 2007, 12:26pm UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/2 "2007-12-09T12:26:27Z")

</div>

On 8 Dec 2007, at 23:48, Trevor T. wrote:

> I can’t figure out how to work around them seeing an Application Error  
> screen the first time. Is there any way to rescue\_from this error, or  
> otherwise avoid encountering it all together?

If you change the name of the cookie used then the app won’t see the  
old cookie at all, which should handle things.

---

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [December 10, 2007, 2:10am UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/3 "2007-12-10T02:10:22Z")

</div>

Frederick C. wrote:

> If you change the name of the cookie used then the app won’t see the  
> old cookie at all, which should handle things.

I’m still not able to work around this issue. The problem occurs when I  
change the “secret” used by cookie sessions in config/environment.rb:

config.action\_controller.session = { :session\_key =\> x, :secret =\> y }

That seems to trigger the TamperedWithCookie, which resolves itself  
after one refresh. Changing the session\_key and the secret at the same  
time still triggers the error. So, I don’t know what to do!

Again, any further help would be much appreciated.

Thanks,

- Trevor

---

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [December 10, 2007, 4:07pm UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/4 "2007-12-10T16:07:10Z")

</div>

On Dec 10, 2007, at 2:10 AM, Trevor T. wrote:

> That seems to trigger the TamperedWithCookie, which resolves itself  
> after one refresh. Changing the session\_key and the secret at the same  
> time still triggers the error. So, I don’t know what to do!

It should work, change the value associated to :session\_key (which is  
the name of the cookie) in environment.rb and restart the server.

– fxn

---

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [December 13, 2007, 2:54am UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/5 "2007-12-13T02:54:09Z")

</div>

Xavier N. wrote:

> On Dec 10, 2007, at 2:10 AM, Trevor T. wrote:  
> It should work, change the value associated to :session\_key (which is  
> the name of the cookie) in environment.rb and restart the server.

I’ve added more detail to a Rails Trac ticket, including an example of  
the error. I’m doing what you suggested, Xavier, and I’m still getting  
this error.

[http://dev.rubyonrails.org/ticket/10427](http://dev.rubyonrails.org/ticket/10427)

Thanks,

- Trevor

---

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [December 13, 2007, 3:33pm UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/6 "2007-12-13T15:33:54Z")

</div>

Hi, Trevor.

I had the same problem when I upgraded to 2.0.1 and I got around it by  
deleting the contents of my tmp/sessions directory. Hope that helps!

Katie

On Dec 12, 7:54 pm, Trevor T. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [December 14, 2007, 12:19am UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/7 "2007-12-14T00:19:02Z")

</div>

Katie Kelly wrote:

> I had the same problem when I upgraded to 2.0.1 and I got around it by  
> deleting the contents of my tmp/sessions directory. Hope that helps!

I was using the database for sessions, so that’s not the problem. Thanks  
for the reply, though!

---

<div class="post-metadata">

**Author:** ![trevorturk](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/278dde/32.png) [@trevorturk](https://www.ruby-forum.com/u/trevorturk)\
**Post date:** [April 19, 2008, 8:43am UTC](https://www.ruby-forum.com/t/rescue-from-tamperedwithcookie-error/122537/8 "2008-04-19T08:43:47Z")

</div>

Trevor T. wrote:

> Katie Kelly wrote:
> 
> > I had the same problem when I upgraded to 2.0.1 and I got around it by  
> > deleting the contents of my tmp/sessions directory. Hope that helps!
> 
> I was using the database for sessions, so that’s not the problem. Thanks  
> for the reply, though!

I had the same problem then I got around it by  
deleting the contents from sessions table.
