Syncing with 3.0. Added support to nbsp entity (needed for man page).
[privoxy.git] / default.filter
1 # ********************************************************************
2
3 #  File        :  $Source: /cvsroot/ijbswa//current/default.filter,v $
4
5 #  $Id: default.filter,v 1.11.2.6 2002/08/23 14:12:26 oes Exp $
6 #
7 #  Purpose     :  Rules to process the content of web pages
8
9 #  Copyright   :  Written by and Copyright
10 #                 Privoxy team. http://www.privoxy.org/
11 #
12 # We value your feedback. However, to provide you with the best support,
13 # please note:
14 #  
15 #  * Use the support forum to get help:
16 #    http://sourceforge.net/tracker/?group_id=11118&atid=211118
17 #  * Submit bugs only thru our bug forum:
18 #    http://sourceforge.net/tracker/?group_id=11118&atid=111118 
19 #    Make sure that the bug has not already been submitted. Please try
20 #    to verify that it is a Privoxy bug, and not a browser or site
21 #    bug first. If you are using your own custom configuration, please
22 #    try the stock configs to see if the problem is a configuration
23 #    related bug. And if not using the latest development snapshot,
24 #    please try the latest one. Or even better, CVS sources.
25 #  * Submit feature requests only thru our feature request forum:
26 #    http://sourceforge.net/tracker/?atid=361118&group_id=11118&func=browse
27 #      
28 # For any other issues, feel free to use the mailing lists:
29 # http://sourceforge.net/mail/?group_id=11118
30 #    
31 # Anyone interested in actively participating in development and related
32 # discussions can join the appropriate mailing list here:
33 # http://sourceforge.net/mail/?group_id=11118. Archives are available
34 # here too.
35
36 #################################################################################
37 #
38 # Syntax:
39 #
40 # Filters start with a line "FILTER: name description". They are then referrable
41 # from the actionsfile with +filter{name}
42 #
43 # Inside the filters, write one Perl-Style substitution (job) per line.
44 # Jobs that precede the first FILTER: line are ignored.
45 #
46 # For Details see the pcrs manpage contained in this distribution.
47 # (and the perlre, perlop and pcre manpages)
48 #
49 # Note that you are free to choose the delimter as you see fit.
50 #
51 # Note2: In addidion to the Perl options gimsx, the following nonstandard
52 # options are supported:
53
54 # 'U' turns the default to ungreedy matching.  Add ? to quantifiers to
55 #     switch back to greedy.
56 # 'T' (trivial) prevents parsing for backreferences in the substitute.
57 #     Use if you want to include text like '$&' in your substitute without
58 #     quoting.
59
60 #################################################################################
61
62
63 #################################################################################
64 #
65 # js-annoyances: Get rid of particularly annoying JavaScript abuse
66 #
67 #################################################################################
68 FILTER: js-annoyances Get rid of particularly annoying JavaScript abuse
69
70 # Note: Most of these jobs would be safer if restricted to a
71 # <script> context as in:
72 #
73 # s/(<script.*)nasty-item(?=.*<\/script>)/$1replacement/sigU
74 #
75 # but that would make them match only the first occurance of
76 # nasty-item in each <script>. We need nestable jobs!
77
78 # Get rid of Javascript referrer tracking. 
79 # Test page: http://www.javascript-page.com/referrer.html
80 #
81 s|document\.referrer|"Not Your Business!"|gisU
82
83 # The status bar is for displaying link targets, not pointless blahblah
84 #
85 s/([\n =;{}]|window\.)(default)?status\s*=/$1dUmMy=/ig
86
87 # Kill OnUnload popups. Yummy.
88 # Test: http://www.zdnet.com/zdsubs/yahoo/tree/yfs.html
89 #
90 s/(<body\s+[^>]*)onunload(.*>)/$1never$2/siU
91 s|(<script.*)window\.onunload(?=.*</script>)|$1never|sigU
92
93 # If we allow window.open, we want normal window features: 
94 # Test: http://www.htmlgoodies.com/beyond/notitle.html
95 #
96 s/(open\s*\([^\)]+resizable=)(["']?)(?:no|0)\2/$1$2yes$2/sigU
97 s/(open\s*\([^\)]+location=)(["']?)(?:no|0)\2/$1$2yes$2/sigU 
98 s/(open\s*\([^\)]+status=)(["']?)(?:no|0)\2/$1$2yes$2/sigU 
99 s/(open\s*\([^\)]+scroll(?:ing|bars)=)(["']?)(?:no|0)\2/$1$2auto$2/sigU 
100 s/(open\s*\([^\)]+menubar=)(["']?)(?:no|0)\2/$1$2yes$2/sigU 
101 s/(open\s*\([^\)]+toolbar=)(["']?)(?:no|0)\2/$1$2yes$2/sigU 
102 s/(open\s*\([^\)]+directories=)(["']?)(?:no|0)\2/$1$2yes$2/sigU 
103 s/(open\s*\([^\)]+fullscreen=)(["']?)(?:yes|1)\2/$1$2no$2/sigU
104 s/(open\s*\([^\)]+always(?:raised|lowered)=)(["']?)(?:yes|1)\2/$1$2no$2/sigU
105 s/(open\s*\([^\)]+zlock=)(["']?)(?:yes|1)\2/$1$2no$2/sigU
106 s/(open\s*\([^\)]+hotkeys=)(["']?)(?:yes|1)\2/$1$2no$2/sigU
107 s/(open\s*\([^\)]+titlebar=)(["']?)(?:yes|1)\2/$1$2yes$2/sigU
108
109
110 #################################################################################
111 #
112 # html-annoyances: Get rid of particularly annoying HTML abuse
113 #
114 #################################################################################
115 FILTER: html-annoyances Get rid of particularly annoying HTML abuse
116
117 # New browser windows (if allowed -- see no-popups filter below) should be
118 # resizeable and have a location and status bar
119 #
120 s/(<a\s+href[^>]+resizable=)(['"]?)(?:no|0)\2/$1$2yes$2/igU 
121 s/(<a\s+href[^>]+location=)(['"]?)(?:no|0)\2/$1$2yes$2/igU 
122 s/(<a\s+href[^>]+status=)(['"]?)(?:no|0)\2/$1$2yes1$2/igU
123 s/(<a\s+href[^>]+scrolling=)(['"]?)(?:no|0)\2/$1$2auto$2/igU
124 s/(<a\s+href[^>]+menubar=)(['"]?)(?:no|0)\2/$1$2yes$2/igU
125
126 # The <BLINK> tag was a crime!
127 #
128 s*<blink>|</blink>**ig
129
130
131 #################################################################################
132 #
133 # content-cookies: Kill cookies that come in the HTML or JS content
134 #
135 #################################################################################
136 FILTER: content-cookies Kill cookies that come in the HTML or JS content
137
138 # JS cookies, like found on privacy.net:
139 #
140 s|document\.cookie(?=[ \t\r\n]*=)|ZappedCookie|ig
141
142 # HTML cookies:
143 #
144 s|<meta\s+http-equiv=['"]?set-cookie.*>|<!-- ZappedCookie -->|igU
145
146
147 #################################################################################
148 #
149 # webbugs: Squish WebBugs (1x1 invisible GIFs used for user tracking)
150 #
151 #################################################################################
152 FILTER: webbugs Squish WebBugs (1x1 invisible GIFs used for user tracking)
153
154 s/<img\s+[^>]*(?:width|height)\s*=\s*['"]?1(?=\D)[^>]*(?:width|height)\s*=\s*['"]?1(?=\D)[^>]*?>//siUg
155
156
157 ##################################################################################
158 #
159 # popups: Kill all popups in JS and HTML
160 #
161 #################################################################################
162 FILTER: popups Kill all popups in JS and HTML
163
164 s/([\n =;{}]|window\.)open\s*\\?\(/$1concat(/ig      # JavaScript
165 s/ target\s*=\s*(['"]?)(_blank|_new)\1?/ notarget/ig # HTML
166
167
168 #################################################################################
169 #
170 # frameset-borders: Give frames a border, make them resizable and scrollable
171 #
172 #################################################################################
173 FILTER: frameset-borders Give frames a border and make them resizable
174
175 s/(<frameset\s+[^>]*)framespacing=(['"]?)(no|0)\2/$1/igU
176 s/(<frameset\s+[^>]*)frameborder=(['"]?)(no|0)\2/$1/igU
177 s/(<frameset\s+[^>]*)border=(['"]?)(no|0)\2/$1/igU
178 s/(<frame\s+[^>]*)noresize/$1/igU
179 s/(<frame\s+[^>]*)frameborder=(['"]?)(no|0)\2/$1/igU 
180 s/(<frame\s+[^>]*)scrolling=(['"]?)(no|0)\2/$1/igU
181
182
183 #################################################################################
184 #
185 # refresh-tags: Kill automatic refresh tags (for dial-on-demand setups)
186 #
187 #################################################################################
188 FILTER: refresh-tags Kill automatic refresh tags (for dial-on-demand setups)
189
190 # Note: Only deactivates refreshes with more than 9 seconds delay to
191 #       preserve monster-stupid but common redirections via meta tags.
192 #
193 s/<meta\s+http-equiv\s*=\s*(['"]?)refresh\1\s+content\s*=\s*(['"]?)\d{2,}\s*(;\s*url\s*=\s*([^>\2]*))?\2\s*>/<link rev="x-refresh" href="$4">/iU
194
195
196 #################################################################################
197 #
198 # img-reorder: Reorder attributes in <img> tags to make the banners-by-* filters more effective
199 #
200 #################################################################################
201 FILTER: img-reorder Reorder attributes in <img> tags to make the banners-by-* filters more effective
202
203 # In the first step src is moved to the start, then width is moved to the second
204 # place to guarantee an order of src, width, height.
205 # This makes banners-by-size more effective and allows both banners-by-size
206 # and banners-by-link to preserve the original image URL in the alt attribute.
207
208 s|<img\s+([^\\>]*)src\s*=\s*(['"])([^>\\\2]+)\2(.*)>|<img src="$3" $1$4>|siUg
209 s|<img\s+([^\\>]*)src\s*=\s*([^'">\\\s]+?)([^\\>]*)>|<img src="$2" $1$3>|siUg
210
211 s|<img (src="[^"]*") ([^>]*)width\s*=\s*?(["']?)(\d+?)\3(.*)>|<img $1 width="$4" $2$5>|siUg
212
213
214 #################################################################################
215 #
216 # banners-by-size: Kill banners by size
217 #
218 #################################################################################
219 #
220 # Standard banner sizes taken from http://www.iab.net/iab_banner_standards/bannersizes.html
221 #
222 # Note: Use http://config.privoxy.org/send-banner?type=trans for a transparent 1x1 image
223 #       Use http://config.privoxy.org/send-banner?type=pattern for a grey/white pattern image
224 #       Use http://config.privoxy.org/send-banner?type=auto  to auto-select.
225 #
226 #################################################################################
227 FILTER: banners-by-size Kill banners by size
228
229 # 88*31
230 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)88\3)[^>]*(height=(['"]?)31\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
231 # 120*60, 120*90, 120*240, 120*600
232 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)120\3)[^>]*(height=(['"]?)(?:600?|90|240)\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
233 # 125*125
234 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)125\3)[^>]*(height=(['"]?)125\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
235 # 160*600
236 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)160\3)[^>]*(height=(['"]?)600\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
237 # 180*150
238 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)180\3)[^>]*(height=(['"]?)150\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
239 # 234*60, 468*60 (Most Banners!)
240 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)(?:234|468)\3)[^>]*(height=(['"]?)60\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
241 # 240*400
242 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)240\3)[^>]*(height=(['"]?)400\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
243 # 250*250, 300*250
244 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)(?:250|300)\3)[^>]*(height=(['"]?)250\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
245 # 336*280
246 s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)336\3)[^>]*(height=(['"]?)280\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
247
248 # Note: 200*50 was also proposed, but it probably causes too much collateral damage:
249 #
250 #s@<img(?: src="([^"]*)")??[^>]*(width=(['"]?)200\3)[^>]*(height=(['"]?)50\5)[^>]*>@<img src=http://config.privoxy.org/send-banner?type=auto alt=Killed-$1-by-size $2 $4>@sigU
251
252
253 #################################################################################
254 #
255 # banners-by-link: Kill banners by their links to known clicktrackers
256 #
257 #################################################################################
258 FILTER: banners-by-link Kill banners by their links to known clicktrackers
259
260 # Common case with width and height attributes:
261 #
262 s@<a\s+href\s*=\s*(['"]??)([^>\1]*(?:\
263   adclick                             # See www.dn.se \
264 | atwola\.com/(?:link|redir)          # see www.cnn.com \
265 | /jump/                              # redirs for doublecklick.net ads \
266 | tracker | counter                   # common \
267 | adlog\.pl                           # see sf.net \
268 )[^>\1]*)\1[^>]*>\s*<img(?: src="([^"]*)")??[^>]*((?:width|height)\s*=\s*(['"]?)\d+?\5)[^>]*((?:width|height)\s*=\s*(['"]?)\d+?\7)[^>]*>\
269 @<img $4 $6 src="http://config.privoxy.org/send-banner?type=auto" alt="Killed $3 by hwlink to $2">@siUgx
270
271 # Rare case w/o explicit dimensions:
272 #
273 s@<a\s+href\s*=\s*(['"]??)([^>\1]*(?:adclick|atwola\.com/(?:link|redir)|doubleclick\.net/jump)[^>\1]*)\1[^>]*>\s*<img(?: src="([^"]*)")??[^>]*>@<img src="http://config.privoxy.org/send-banner?type=auto" alt="Killed $3 by link to $2">@siUg
274
275 #################################################################################
276 #
277 # fun: Text replacements for subversive browsing fun!
278 #
279 #################################################################################
280 FILTER: fun Text replacements for subversive browsing fun!
281
282 s/microsoft(?!.com)/MicroSuck/ig
283
284 # Buzzword Bingo (example for extended regex syntax)
285 #
286 s* industry[ -]leading \
287 |  cutting[ -]edge \
288 |  customer[ -]focused \
289 |  market[ -]driven \
290 |  award[ -]winning # Comments are OK, too! \
291 |  high[ -]performance \
292 |  solutions[ -]based \
293 |  unmatched \
294 |  unparalleled \
295 |  unrivalled \
296 *<font color="red"><b>BINGO!</b></font> \
297 *igx
298
299
300 #################################################################################
301 #
302 # nimda: Remove Nimda (virus) code
303 #
304 #################################################################################
305 FILTER: nimda Remove Nimda (virus) code
306
307 s%<script language="JavaScript">(window\.open|1;''\.concat)\("readme\.eml", null, "resizable=no,top=6000,left=6000"\)</script>%<br><font size="7"> WARNING: This Server is infected with <a href="http://www.cert.org/advisories/CA-2001-26.html">Nimda</a>!</font>%g
308
309
310 #################################################################################
311 #
312 # shockwave-flash: Kill embedded Shockwave Flash objects
313 #
314 #################################################################################
315 FILTER: shockwave-flash Kill embedded Shockwave Flash objects
316
317 s|<embed [^>]*application/x-shockwave-flash.*</embed>|<!-- Squished Shockwave Flash Embed -->|sigU
318
319
320 #################################################################################
321 #
322 # quicktime-kioskmode: Make Quicktime movies saveable
323 #
324 #################################################################################
325 FILTER: quicktime-kioskmode Make Quicktime movies saveable
326
327 s/(<embed\s+[^>]*)kioskmode\s*=\s*(["']?)true\2/$1/ig 
328
329
330 #################################################################################
331 #
332 # js-events: Kill all JS event bindings (Radically destructive! Only for extra nasty sites)
333 #
334 #################################################################################
335 FILTER: js-events Kill all JS event bindings (Radically destructive! Only for extra nasty sites)
336
337 s/(on|event\.)((mouse(over|out|down|up|move))|(un)?load|contextmenu|selectstart)/never/ig
338 # Not events, but abused on the same type of sites:
339 s/(alert|confirm)\s*\(/concat(/ig
340
341
342 #################################################################################
343 #
344 # crude-parental: Crude parental filtering?  (Use along with a suitable blocklist).
345 #                 Shows how to deny access to whole page based on a keyword.
346 #
347 #################################################################################
348 FILTER: crude-parental Crude parental filtering (demo only)
349
350 # (Note: Middlesex, Sussex and Essex are counties in the UK, not rude words)
351 # (Note #2: Is 'sex' a rude word?!)
352
353 s%^.*(?<!middle)(?<!sus)(?<!es)sex.*$%<html><head><title>Blocked</title></head><body><h3>Blocked due to possible adult content. Please see <a href="http://dmoz.org/Kids_and_Teens/">this site</a>.</h3></body></html>%is
354 s+^.*warez.*$+<html><head><title>No Warez</title></head><body><h3>You're not searching for illegal stuff, are you?</h3></body></html>+is
355
356
357 ############################################################################## 
358 #
359 #  Revisions   :
360 #     $Log: default.filter,v $
361 #     Revision 1.11  2002/05/24 00:57:18  oes
362 #     Made WeBugs job ungreedy; Fixes bug 559190
363 #
364 #     Revision 1.10  2002/04/18 10:14:19  oes
365 #     renamed some filters
366 #
367 #     Revision 1.9  2002/04/11 07:36:35  oes
368 #     Generalized js-popup filter
369 #
370 #     Revision 1.8  2002/04/10 17:07:21  oes
371 #     Fixed potentially desctructive jobs, added noflash filter
372 #
373 #     Revision 1.7  2002/04/09 18:34:51  oes
374 #     Fixed HTML syntax in replacements
375 #
376 #     Revision 1.6  2002/04/03 19:49:52  swa
377 #     name change
378 #
379 #     Revision 1.5  2002/03/27 15:30:26  swa
380 #     have a consistent appearance
381 #
382 #     Revision 1.4  2002/03/26 22:29:54  swa
383 #     we have a new homepage!
384 #
385 #     Revision 1.3  2002/03/24 16:08:03  jongfoster
386 #     Fixing banners-by-size for new config URLs
387 #
388 #     Revision 1.2  2002/03/24 13:02:18  swa
389 #     name change related issues.
390 #
391 #     Revision 1.1  2002/03/24 11:37:39  jongfoster
392 #     Name change
393 #
394 #     Revision 1.24  2002/03/16 20:39:54  oes
395 #      - Added descriptions to the filters so users will know what they select in the cgi editor
396 #      - Added content-cookies filter
397 #      - Bugfixed many jobs (Thanks to Al for some hints)
398 #
399 #     Revision 1.22  2002/03/12 13:42:50  oes
400 #     Fixing & Optimizing REs
401 #
402 #     Revision 1.21  2002/03/12 11:59:20  oes
403 #     Beefed up Buzzword Bingo
404 #
405 #     Revision 1.20  2002/03/12 01:42:50  oes
406 #     Introduced modular filters
407 #
408 #     Revision 1.19  2002/03/10 19:49:24  oes
409 #     Added expression to kill referer tracking in JavaScripts
410 #
411 #     Revision 1.18  2002/03/08 17:14:12  oes
412 #     PNG -> image in comments
413 #
414 #     Revision 1.17  2002/03/07 03:50:54  oes
415 #     Adapted comments to new built-in images
416 #
417 #     Revision 1.16  2002/02/21 00:12:19  jongfoster
418 #     Modifying the banner regexps to use long URLS and to autodetect
419 #     whether to show a logo or a transparent GIF, based on actionsfile
420 #     setting.
421 #
422 #     Revision 1.15  2001/12/28 23:54:20  steudten
423 #     Fix for feature Req #495374: http-equiv problem
424 #
425 #     Revision 1.14  2001/12/09 18:55:11  david__schmidt
426 #     Updated CODE_STATUS to beta, commented out microsuck line in re_filterfile
427 #     for 2.9.10 beta
428 #
429 #     Revision 1.13  2001/10/13 13:11:20  joergs
430 #     Fixed WebBug filter.
431 #
432 #     Revision 1.12  2001/10/07 15:46:42  oes
433 #     Followed Guy's proposal to change the document.cookie job
434 #
435 #     Revision 1.11  2001/09/21 12:34:00  joergs
436 #     Added filter to replace "Nimda" code by a warning.
437 #
438 #     Revision 1.10  2001/07/20 11:04:26  oes
439 #     Added Rodneys javascript cookie filter
440 #
441 #     Revision 1.9  2001/07/13 14:03:48  oes
442 #     Elimiated yet another bug in the banner-by-size jobs. Shame on me!
443 #
444 #     Revision 1.8  2001/06/29 13:34:00  oes
445 #     - Added explanation for U and T options
446 #     - Added hint on image replacement by CGI call
447 #     - Fixed bug in banner-by-size jobs
448 #
449 #     Revision 1.7  2001/06/19 14:21:56  oes
450 #     Fixed microsuck line
451 #
452 #     Revision 1.6  2001/06/09 14:01:57  swa
453 #     header. cosmetics. default: no messing ala microsuck.
454 #
455 #
456