473,396 Members | 1,921 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

sending http requests without cookies

Say I wrote an ajax script to send out HTTP requests via ajax. Any
cookies that I have associated with that site will be sent along with
this HTTP request. Is there a way to prevent this from happening? I
tried the following to no avail:

http.setRequestHeader('Cookie','');

Feb 14 '06 #1
13 13699
VK

yawnmoth wrote:
Say I wrote an ajax script to send out HTTP requests via ajax. Any
cookies that I have associated with that site will be sent along with
this HTTP request. Is there a way to prevent this from happening? I
tried the following to no avail:

http.setRequestHeader('Cookie','');


var tmp = document.cookie;
document.cookie = '';
sendRequest();
document.cookie = tmp;

( ? )

Feb 14 '06 #2
VK wrote:
yawnmoth wrote:
Say I wrote an ajax script to send out HTTP requests via ajax. Any
cookies that I have associated with that site will be sent along with
this HTTP request. Is there a way to prevent this from happening?
I don't think so. Why would that be necessary anyway?
I tried the following to no avail:

http.setRequestHeader('Cookie','');

This cannot work because the Cookie header value must not be empty.
See RFC2965, 3.3.4.
var tmp = document.cookie;
document.cookie = '';
sendRequest();
document.cookie = tmp;

( ? )


Definitely not. As can be proven easily, assigning the empty string to
document.cookie does not delete all cookies for this resource.

It merely adds a new session cookie with empty name and value for the
current domain and path -- although that particular behavior may be
UA-dependent (I tested with Firefox 1.5.0.1/Linux).

Tests with that UA also indicate that since it is not possible to determine
what the domain and path components were when a cookie was set, it is not
possible to delete it reliably using the value of document.cookies only as
it is not possible to delete a cookie when domain and path component do not
match (implicitly).
PointedEars
Feb 14 '06 #3
VK

Thomas 'PointedEars' Lahn wrote:
VK wrote:
yawnmoth wrote:
Say I wrote an ajax script to send out HTTP requests via ajax. Any
cookies that I have associated with that site will be sent along with
this HTTP request. Is there a way to prevent this from happening?
I don't think so. Why would that be necessary anyway?
I tried the following to no avail:

http.setRequestHeader('Cookie','');


This cannot work because the Cookie header value must not be empty.
See RFC2965, 3.3.4.
var tmp = document.cookie;
document.cookie = '';
sendRequest();
document.cookie = tmp;

( ? )


Definitely not. As can be proven easily, assigning the empty string to
document.cookie does not delete all cookies for this resource.


Right. I forgot (it was a while I played with cookies client-side) that
cookie property works like an electric diod: it has different
"resistance" depending on what side of expression it is used.

On the right side it has "zero resistance" so by saying:
var foo = document.cookie;
you are grabbing all cookies with all attributes available for the
given document.

On the left side it has "high resistance" so you can address only one
cookie at time, so by saying:
document.cookie = foo;
document.cookie = bar;
you are not overriding foo by bar, but setting two separate cookies
(foo and bar).

So the proposed algorithm, if it's indeed the only way (I don't know
and actually I hope not) must be adjusted into a much more complicated
way:

1) grab all cookies by
var foo = document.cookie;

2) Parse cookie string "foo", extract each separate cookie and make it
expired (or override it with empty string):
document.cookie = cookie1;
document.cookie = cookie2;
etc.

3) Send request.

4) Restore all cookies back using the same algorithm as on step 2.

For one of these "update every 10ms" :-) ajaxoids this approach is very
questionnable to work. For a single or rare requests it is doable:
again if there is nothing better than that.

Feb 14 '06 #4
VK wrote:
Thomas 'PointedEars' Lahn wrote:
VK wrote:
> yawnmoth wrote:
>> Say I wrote an ajax script to send out HTTP requests via ajax. Any
>> cookies that I have associated with that site will be sent along with
>> this HTTP request. Is there a way to prevent this from happening?

[...]
> var tmp = document.cookie;
> document.cookie = '';
> sendRequest();
> document.cookie = tmp;
>
> ( ? )

Definitely not. As can be proven easily, assigning the empty string to
document.cookie does not delete all cookies for this resource.


[...]
So the proposed algorithm, if it's indeed the only way (I don't know
and actually I hope not) must be adjusted into a much more complicated
way:

1) grab all cookies by
var foo = document.cookie;

2) Parse cookie string "foo", extract each separate cookie and make it
expired (or override it with empty string):
document.cookie = cookie1;
document.cookie = cookie2;
etc.


As I said, step 2 is not possible. Once in a while you should read what
you reply to.
PointedEars
Feb 14 '06 #5
VK

Thomas 'PointedEars' Lahn wrote:
2) Parse cookie string "foo", extract each separate cookie and make it
expired (or override it with empty string):
document.cookie = cookie1;
document.cookie = cookie2;
etc.


As I said, step 2 is not possible. Once in a while you should read what
you reply to.


What do you mean "impossible"? How do you think all JavaScript cookie
management systems work?

Read some manual like
<http://www.netspade.com/articles/2005/11/16/javascript-cookies/>

Feb 14 '06 #6
VK wrote:
Thomas 'PointedEars' Lahn wrote:
> 2) Parse cookie string "foo", extract each separate cookie
> and make it expired (or override it with empty string):
> document.cookie = cookie1;
> document.cookie = cookie2;
> etc. As I said, step 2 is not possible. Once in a while you should
read what you reply to.


What do you mean "impossible"?


Impossible as in "not possible".
How do you think all JavaScript cookie management systems work?
I do not know. Why do you think that is relevant? The reference
implementation does not support it already.
Read some manual like
<http://www.netspade.com/articles/2005/11/16/javascript-cookies/>


Read the comments for the deleteCookie() method there, then see my
signature. Did I mention that you should read what you reply to?
PointedEars
--
Learn to think clearly.
Learn to distinguish: What is, and what seems to be.
-- Surak
Feb 14 '06 #7
On 14/02/2006 19:00, VK wrote:
Thomas 'PointedEars' Lahn wrote:
VK wrote:
2) Parse cookie string "foo", extract each separate cookie and
make it expired [...]
As I said, step 2 is not possible. Once in a while you should read
what you reply to.


What do you mean "impossible"?


Not possible.
How do you think all JavaScript cookie management systems work?
Thomas clearly has a greater understanding than you do, but that is
hardly a surprise, is it?

When a cookie is created, it is possible to specify path and domain
parameters to explicitly define the scope of that cookie. In order to
modify a particular cookie, this extra information needs to be resupplied.

Example:
Set-Cookie: name=value; expires=Tue, 14-Feb-2005 20:00:00 GMT;
path=/foo

Expected:
Cookie: name=value

Actual:
Cookie: name=value
Your suggestion:
Set-Cookie: name=value; expires=Thu, 01-Jan-1970 00:00:00 GMT

You expect:
<no Cookie header>

Actual:
Cookie: name=value

The two cookies do not match. The second Set-Cookie header (or
document.cookie property equivalent) effectively creates a second cookie
that has already expired.

If user agents implemented RFC 2965 (and I know of none that do), this
necessary information would be supplied in the Cookie request header,
along with the cookie values, and it could indeed be parsed out and used
for deletion.
Read some manual
Pot. Kettle. Black.
like
<http://www.netspade.com/articles/2005/11/16/javascript-cookies/>


That isn't a manual, and it doesn't support your assertions (quite the
opposite, in fact).

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Feb 14 '06 #8
VK

Michael Winter wrote:
On 14/02/2006 19:00, VK wrote:
Thomas 'PointedEars' Lahn wrote:
VK wrote:

2) Parse cookie string "foo", extract each separate cookie and
make it expired [...]

As I said, step 2 is not possible. Once in a while you should read
what you reply to.
What do you mean "impossible"?


Not possible.
How do you think all JavaScript cookie management systems work?


Thomas clearly has a greater understanding than you do, but that is
hardly a surprise, is it?


Not really - specially as I'm getting more and more hard to be
surprised recently :-)

Thomas doesn't have better understanding, but he's already getting what
attitude (atop of his regular one :-) which may infect you if stay
regularly on clj.
Namely when someone is asking "I have situation A there I would like to
accomplish the action X" one doesn't think about the practical answer
first:- but she thinks first of situations B, C, ...Z where the action
X may fail or not possible or not blessed etc. That's should be the
secondary thinking one is welcome to place at the postscriptum of the
solution. And if you have no solution, then do not post at all (a
letter consisting of a postscriptum only is a rather strange thing).
It's all IMHighlyHO and off-topic.

Now reading OP's original question once over: "Any cookies that I have
associated with that site will be sent along with this HTTP request".
*I have associated*
From my (possibly wrong) reading of this sentence I concluded that OP

knows what cookies, for what domain and what path did he set.

name/domain/path exact match was implemented for exactly the opposite
situation: when someone wants to destroy cookie set by someone else.
Again it might be my mistake but I did not read this situation out of
the post.

Feb 14 '06 #9

VK wrote:
<snip>
From my (possibly wrong) reading of this sentence I concluded that OP

knows what cookies, for what domain and what path did he set.

That is indeed the case.

Feb 14 '06 #10

TerraFrost wrote:
VK wrote:
<snip>
From my (possibly wrong) reading of this sentence I concluded that OP

knows what cookies, for what domain and what path did he set.

That is indeed the case.

Grr... the previous poster was me. Google Groups (shame on me for
using it) had me logged in with my gmail account - not the account I
prefer using on usenet...

Feb 14 '06 #11
VK

yawnmoth wrote:
Grr... the previous poster was me. Google Groups (shame on me for
using it) had me logged in with my gmail account - not the account I
prefer using on usenet...


For Google post: Show options > Remove

We shall pretend we've never seen the previous one :-D

Feb 14 '06 #12
VK wrote:
Michael Winter wrote:
On 14/02/2006 19:00, VK wrote:
> Thomas 'PointedEars' Lahn wrote:
>> VK wrote:
>>> 2) Parse cookie string "foo", extract each separate cookie and
>>> make it expired [...]
>> As I said, step 2 is not possible. Once in a while you should read
>> what you reply to.
> What do you mean "impossible"? Not possible.
> How do you think all JavaScript cookie management systems work?

Thomas clearly has a greater understanding than you do, but that is
hardly a surprise, is it?


Not really - specially as I'm getting more and more hard to be
surprised recently :-)

Thomas doesn't have better understanding, but he's already getting what
attitude (atop of his regular one :-) which may infect you if stay
regularly on clj.
[...]


What are you babbling about again? Read it from my fingertips: It is _not
possible_ to delete all cookies that apply to a resource because either of
the cookies retrieved with document.cookies may be set for a domain of the
resource of a higher level (say a resource on bla.example.com reading the
cookie set for .example.com) or a path of a higher level (say a resource on
example.com/foo/bar/ to retrieve a cookie set for example.com/foo/) or a
combination of both. Then you have _no chance_ to set this cookie to
expire (read: to delete it) as you have no chance to retrieve that kind of
information and so you cannot set the exact domain or path component of the
string that needs to be assigned. And using the second-level domain of the
resource or the root path does not modify the corresponding cookie, so
cannot delete it.
Now reading OP's original question once over: "Any cookies that I have
associated with that site will be sent along with this HTTP request".
*I have associated*
A Web site usually consists of more than one resource.
From my (possibly wrong) reading of this sentence I concluded that OP
knows what cookies, for what domain and what path did he set.
Perhaps, perhaps not. For example, session cookies ("session" referring
to server-side sessions here, not necessarily also to client-side ones),
are often set/sent automatically by server-side applications.
name/domain/path exact match was implemented for exactly the opposite
situation: when someone wants to destroy cookie set by someone else.


Utter nonsense. It was implemented to allow cookies to be accessible
throughout a Web site, especially sub-level domains and subpaths, and
accessible in a sub-level domain (and its sub-level domains) and subpaths
but not in the domain or path of higher level.
PointedEars
Feb 14 '06 #13
On 14/02/2006 20:59, VK wrote:

[snip]
Now reading OP's original question once over: "Any cookies that I have
associated with that site will be sent along with this HTTP request".
*I have associated*

From my (possibly wrong) reading of this sentence I concluded that OP
knows what cookies, for what domain and what path did he set.
One should certainly hope that, given a particular cookie, code that
deals with this cookie should know the conditions under which is was
created. However, if there were, for example, two cookies used across a
site, code that uses only one shouldn't need to know about the other.

What you proposed - removing and then restoring the cookies - would mean
that the client-side code would need to know everything about both, and
would need to be maintained in parallel to the code that creates and
uses them. Even then, the client-side code still may not be able to
restore the cookies properly as it will not know the original expiration
time and date.
name/domain/path exact match was implemented for exactly the opposite
situation: when someone wants to destroy cookie set by someone else.
Not at all. The domain and path parameters allow an application to
control where within a site the state information will apply (I already
said that). The required matching algorithm, insofar as matching name,
domain and path, is in place to ensure that the correct cookie is
modified as cookies with the same name can co-exist. It does have the
side-effect of making modification difficult unless the this data is
known, but it's not the reason (otherwise RFC 2965 wouldn't specify
behaviour that exposes it).
Again it might be my mistake but I did not read this situation out of
the post.


To be fair to you, it isn't your responsibility to try to infer
information about a situation that cannot reasonably be known: the OP
should make the circumstances clear. However, you cannot espouse
practicality and then go on to propose something that is clearly not
practical under a reasonable scenario.

Mike

--
Michael Winter
Prefix subject with [News] before replying by e-mail.
Feb 15 '06 #14

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Steve Edwards | last post by:
I maintain a site for an athletic club, and on it I have a form that people can submit that requests a free guest pass. The form contents are sent to an address at the club, and then the club...
7
by: Michael Foord | last post by:
#!/usr/bin/python -u # 15-09-04 # v1.0.0 # auth_example.py # A simple script manually demonstrating basic authentication. # Copyright Michael Foord # Free to use, modify and relicense. #...
5
by: fochie | last post by:
Greetings, I'm trying to send data to my server using xmlhttp POST. The data being sent is actually an HTML page that is built with javascript in the browser. The HTML code contains a small...
9
by: Michael Evanchik | last post by:
Hello all, since i wanted to use ssl and its seems easy to do so with this object. Im trying to login to a webserver (aol) for this example. But for some reason, im packet sniffing with ethreal...
2
by: Andres | last post by:
I am creating a web request (HttpWebRequest) from a web page in order to retrieve the Html from another page and embed it in the calling page. When you create a HttpWebRequest the request is...
2
by: junOnline | last post by:
Hi, I am developing an asp.net 2.0 application using visual studio 2005 on my computer and I am getting very inconsistent results when I test on my computer versus from other computers. The...
4
by: yawnmoth | last post by:
Is it possible to send http requests with curl but not have curl wait for the response? The reason I ask is because I'd like to code a web app that can sorta start time consuming processes...
2
by: barrybevel | last post by:
Hi, I have a very small simple program below which does the following: 1) post a username & password to a website - THIS WORKS 2) follow a link - THIS WORKS 3) update values of 2 fields and...
13
by: ofiras | last post by:
Hello everyone, How can I sand a post to a web page? I want that when the page is trying to fetch a post variable, it will be something the program defined first. Please help, Ofir.
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.