Skip to content

Instantly share code, notes, and snippets.

@ssp
Created March 7, 2010 15:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ssp/324414 to your computer and use it in GitHub Desktop.
Save ssp/324414 to your computer and use it in GitHub Desktop.
Kill bad cookies in WebKit. Uses poor and incomplete heuristics to achieve its goal. Includes a LaunchAgent to run the script every night (path in that must be adapted for your account).
#!/usr/bin/env python
"""
COOKIE KILLER
2010 by Sven-S. Porst <ssp-web@earthlingsoft.net>
Script with simple heuristics to kill the most obviously crap cookies in WebKit.
Available at http://gist.github.com/324414
Better quit cookie users before running the script.
Perhaps run it at login and nightly with a LaunchAgent?
"""
from Foundation import *
evilNames = ["__u", "CFID", "CFTOKEN", "CoreID", ".ASPXANONYMOUS", "ACOOKIE", "AdUserID", "AVPUID", "AWSUSER_ID", "awpopup", "Apache", "bitt", "BX", "CP", "Conversion", "DM", "FC", "GUID", "HstC", "HumanClickID", "ID", "IXA", "JEB2", "LE", "NGUserID", "OAID", "OASIS", "OAX", "POPUPCHECK", "RM", "SID", "TC", "TID", "TRUID", "UID", "UUID", "VISITOR", "VISID", "VisID", "VisitorID", "WEBTRENDS_ID", "WSS_GW", "WT_FPC", "_SUPERFLY", "_OA", "__a", "_bit", "__c", "_dw", "__g", "__k", "__q", "__r", "_c", "_m", "ad", "anon", "bblast", "c1", "eid", "exp_", "emos_", "mds", "meta", "etcnt_", "fpc", "globid", "gmv", "goo", "i00", "iCmpro", "jehiah", "mojo", "OA", "omniID", "omniUserID", "otp", "pb", "phpAds", "pid", "piwik", "re_ret", "ref", "s1", "sUnique", "s_", "ss_lastvisit", "stat_", "suid", "TLTUID", "tu", "um", "v1st", "vid", "VWCUK", "WEBTRENDS", "_w", "wlid", "woo", "wpgb_", "wt_", "XCLGF", "zF" ]
evilDomains = ["googleadservices.com", ".adlink.net", "advertising.com", ".ad", ".doubleclick", "ad", ".statcounter", "track", ".hoc-technology", ".Adjug", ".pubmatic", ".webmaster" ]
path = NSString.stringWithString_("~/Library/Cookies/Cookies.plist").stringByExpandingTildeInPath()
array = NSArray.arrayWithContentsOfFile_(path)
resultCookies = NSMutableArray.array()
count = 0
for cookie in array:
kill = False
name = cookie["Name"]
domain = cookie["Domain"]
for evilName in evilNames:
if name.startswith(evilName):
kill = True
count = count + 1
break
for evilDomain in evilDomains:
if domain.startswith(evilDomain):
kill = True
count = count + 1
break
if kill is False:
resultCookies.addObject_(cookie)
resultCookies.writeToFile_atomically_(path, True)
print "Killed " + str(count) + " of " + str(len(array)) + " cookies."
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>net.earthlingsoft.cookiekiller</string>
<key>ProgramArguments</key>
<array>
<string>/Users/ssp/bin/cookiekiller.py</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StartCalendarInterval</key>
<dict>
<key>Hour</key>
<integer>5</integer>
<key>Minute</key>
<integer>0</integer>
</dict>
</dict>
</plist>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment