• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Cookie object return incorrect value

 
Karup Mew
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

Sometimes the cookie object returns incorrect value because the cookie contains value like "YWRtaW5pc3RyYXRvcg=="
but the cookie object getValue method returns like this "YWRtaW5pc3RyYXRvcg" without equal sign. Kindly provide solution for this
problem.

>
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well I think you are using Base 64 encoding here. I also used it in one of my projects to encode parameters but never used it with cookies. Try your program on a different servlet container. If you still get the same behavior than I think this is the default behavior and you'll have to use some different encoding...
 
Karup Mew
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, I have used base64 and its working in other servlet container .Is this servlet container version problem ?
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Which servlet container is creating problems??
 
Karup Mew
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Both are Tomcat5.5 but the size of servletapi.jar is different
 
Ankit Garg
Sheriff
Posts: 9495
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is strange . I think you should use Tomcat 6 or the Tomcat 5.5 which is working . maybe this is a tomcat bug or something but I have no idea ...
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suspect that = equals signs are not supposed to be part of cookie values.

Digging around in various RFCs it looks like equals signs are treated as separators if they are not in a quoted string.

Base64 encoding may use = as a padding character. See this wikipedia artice for more confusion.

Bill
 
Bauke Scholtz
Ranch Hand
Posts: 2458
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's take a step back: why base64?
 
Piyush Jain
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am facing the same problem.

Has anyone found a solution to this?
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13045
6
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you trim any = signs out of the base64 string before setting the cookie.

Since they only exist to pad to a fixed length the absence should not cause a problem. See the wikipedia article i cited before.

Bill
 
Piyush Jain
Ranch Hand
Posts: 60
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That will not work in this scenario:

I have a service middleware, which passes this cookie, which is a siteminder authentication cookie, and if it does not contain the trailing "=", the authentication fails.
 
senthil doraiswamy
Greenhorn
Posts: 9
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It might be notate the boundary [ CR / LF ] per base64 convention. Take a look at this ---> link and search for two equal sign (=) characters. You can also do some research on base64 boundary characters.

good luck, sen.
 
Kah Tang
Ranch Hand
Posts: 58
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
We were facing the same problem in our company. What we did to resolve this problem was to use the UrlEncoder to encode the cookie value before setting. This will encode all equals signs. And when retrieving the cookie we use UrlDecoder before using the value.

Both UrlEncoder and UrlDecoder can be found in the java.net package.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic