Author Topic: Make JavaScript Cookies session only  (Read 1444 times)

Admin

  • Forum Admin
  • Administrator
  • Jr. Member
  • *****
  • Posts: 62
    • ICQ Messenger - 1448105
    • AOL Instant Messenger -
    • Yahoo Instant Messenger -
    • View Profile
    • Email
Make JavaScript Cookies session only
« on: July 30, 2001, 10:24:13 PM »
Hi all,

The new $NEST() command in beta 5 makes it easier to match a JavaScript
expression.  Here's the latest version of my filter that makes all
Javascript cookies session only.  I've been using it for a while, along
with similar filters for Set-Cookie headers and <meta> tags and so
far all cookies disappear when I close my browser.  Let me know if you
run across a cookie that doesn't.

Copy and paste into the [Patterns] section of your config file.

>---- Begin copy --------------
Name = "Make All JavaScript Cookies Session Only"
Active = TRUE
URL = "(^$LST(CookieList))"
Limit = 256
Match = ".cookie(+|)1="
        "((s|"*'|+|?|:"
        "|$NEST((,))"
        "|$NEST([,])"
        "|[a-z0-9._]+"
        ")+)2 (;|(^?))"
Replace = ".cookie1=(2).replace(/; *expires=[^;]+/i,'');"
>---- End copy ----------------

If you want to know how it works, read on. :)

The match expression looks for ".cookie=" or ".cookie+=" followed by
various pieces of code usually found in JavaScript expressions.

  .cookie(+|)1=
  ((

After the equal sign, there can be

  s           - Space
  "*'          - Strings
  +           - Cancatenation operators
  ? and :     - The shorthand conditional (if ? then : else)
  $NEST((,)) - Stuff in parentheses
  $NEST([,]) - Stuff in array element references
  [a-z0-9._]+  - and variable names (function and array names, too)

The filter will match a chain of the above stuff and put it in 2.
         
  )+)2

It all ends with either a semicolon or the end of the file.

  (;|(^?))

The replace line uses the JavaScript replace() function to filter out
all the expires headers.

  Replace = ".cookie1=(2).replace(/; *expires=[^;]+/i,'');"

I realized that string literals are also objects and have methods and
properties just like variables.  The mess^H^H^H^H version I posted a
while ago chewed up CPU cycles because it tried to get the name of
the document object for use in the replace box.  It's a whole lot
simpler now. :)

ScoJo

With regards from
Admin
With regards from
Admin