Introduced modular filters
[privoxy.git] / re_filterfile
1 # ********************************************************************
2
3 #  File        :  $Source: /cvsroot/ijbswa/current/re_filterfile,v $
4
5 #  Purpose     :  Rules to process the content of web pages
6
7 #  Copyright   :  Written by and Copyright (C) 2001 the SourceForge
8 #                 IJBSWA team.  http://ijbswa.sourceforge.net
9
10 #                 This program is free software; you can redistribute it
11 #                 and/or modify it under the terms of the GNU General
12 #                 Public License as published by the Free Software
13 #                 Foundation; either version 2 of the License, or (at
14 #                 your option) any later version.
15
16 #                 This program is distributed in the hope that it will
17 #                 be useful, but WITHOUT ANY WARRANTY; without even the
18 #                 implied warranty of MERCHANTABILITY or FITNESS FOR A
19 #                 PARTICULAR PURPOSE.  See the GNU General Public
20 #                 License for more details.
21
22 #                 The GNU General Public License should be included with
23 #                 this file.  If not, you can view it at
24 #                 http://www.gnu.org/copyleft/gpl.html
25 #                 or write to the Free Software Foundation, Inc., 59
26 #                 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27
28 #  Revisions   :
29 #     $Log: re_filterfile,v $
30 #     Revision 1.19  2002/03/10 19:49:24  oes
31 #     Added expression to kill referer tracking in JavaScripts
32 #
33 #     Revision 1.18  2002/03/08 17:14:12  oes
34 #     PNG -> image in comments
35 #
36 #     Revision 1.17  2002/03/07 03:50:54  oes
37 #     Adapted comments to new built-in images
38 #
39 #     Revision 1.16  2002/02/21 00:12:19  jongfoster
40 #     Modifying the banner regexps to use long URLS and to autodetect
41 #     whether to show a logo or a transparent GIF, based on actionsfile
42 #     setting.
43 #
44 #     Revision 1.15  2001/12/28 23:54:20  steudten
45 #     Fix for feature Req #495374: http-equiv problem
46 #
47 #     Revision 1.14  2001/12/09 18:55:11  david__schmidt
48 #     Updated CODE_STATUS to beta, commented out microsuck line in re_filterfile
49 #     for 2.9.10 beta
50 #
51 #     Revision 1.13  2001/10/13 13:11:20  joergs
52 #     Fixed WebBug filter.
53 #
54 #     Revision 1.12  2001/10/07 15:46:42  oes
55 #     Followed Guy's proposal to change the document.cookie job
56 #
57 #     Revision 1.11  2001/09/21 12:34:00  joergs
58 #     Added filter to replace "Nimda" code by a warning.
59 #
60 #     Revision 1.10  2001/07/20 11:04:26  oes
61 #     Added Rodneys javascript cookie filter
62 #
63 #     Revision 1.9  2001/07/13 14:03:48  oes
64 #     Elimiated yet another bug in the banner-by-size jobs. Shame on me!
65 #
66 #     Revision 1.8  2001/06/29 13:34:00  oes
67 #     - Added explanation for U and T options
68 #     - Added hint on image replacement by CGI call
69 #     - Fixed bug in banner-by-size jobs
70 #
71 #     Revision 1.7  2001/06/19 14:21:56  oes
72 #     Fixed microsuck line
73 #
74 #     Revision 1.6  2001/06/09 14:01:57  swa
75 #     header. cosmetics. default: no messing ala microsuck.
76 #
77 #
78
79
80 #################################################################################
81 #
82 # Syntax:
83 #
84 # Filters start with a line "FILTER: name". They are then referrable
85 # from the actionsfile with +filter{name}
86 #
87 # Inside the filters, write one Perl-Style substitution per line.
88 #
89 # For Details see the pcrs manpage contained in this distribution.
90 # (and the perlre, perlop and pcre manpages)
91 #
92 # Note that you are free to choose the delimter as you see fit.
93 #
94 # Note2: In addidion to the Perl options gimsx, the following nonstandard
95 # options are supported:
96
97 # 'U' turns the default to ungreedy matching.  Add ? to quantifiers to
98 #     switch back to greedy.
99 # 'T' (trivial) prevents parsing for backreferences in the substitute.
100 #     Use if you want to include text like '$&' in your substitute without
101 #     quoting.
102
103 #################################################################################
104
105
106 #################################################################################
107 #
108 # html-annoyances: Get rid of particularly annoying HTML abuse
109 #
110 #################################################################################
111 FILTER: html-annoyances
112
113 # New browser windows should be resizeable and have a location and status bar
114 #
115 s/resizable="?(no|0)"?/resizable=1/ig s/noresize/yesresize/ig
116 s/location="?(no|0)"?/location=1/ig s/status="?(no|0)"?/status=1/ig
117 s/scrolling="?(no|0|Auto)"?/scrolling=1/ig
118 s/menubar="?(no|0)"?/menubar=1/ig 
119
120 # The <BLINK> tag was a crime!
121 #
122 s*<blink>|</blink>**ig
123
124 # Is this evil? 
125 #
126 #s/framespacing="?(no|0)"?//ig
127 #s/margin(height|width)=[0-9]*//gi
128
129
130 #################################################################################
131 #
132 # js-annoyances: Get rid of particularly annoying JavaScript abuse
133 #
134 #################################################################################
135 FILTER: js-annoyances
136
137 # JS cookies, like found on privacy.net:
138 #
139 s|(document\.cookie)([ \t\r\n]*=)|documenZapCooky$2|g
140
141 # Get rid of Javascript referrer tracking. Test page: http://www.randomoddness.com/untitled.htm
142 #
143 s|(<script.*)document\.referrer(.*</script>)|$1"Not Your Business!"$2|Usg
144
145 # The status bar is for displaying link targets, not pointless blahblah
146 #
147 s/status='.*?';*//ig
148
149 # Kill OnUnload popups. Yummy. Test: http://www.zdnet.com/zdsubs/yahoo/tree/yfs.html
150 #
151 s/(<body .*)onunload(.*>)/$1never$2/iU
152
153
154 ##################################################################################
155 #
156 # no-poups: Kill all popups in JS and HTML
157 #
158 #################################################################################
159 FILTER: no-poups
160
161 s/window\.open\(/1;''\.concat\(/ig      # JavaScript
162 s/target=['"]?_blank['"]?/target_who/g  # HTML
163
164
165 #################################################################################
166 #
167 # frameset-borders: Give frames a border
168 #
169 #################################################################################
170 FILTER: frameset-borders
171
172 s/(<frameset[^>]+?)border=['"]?(no|0)['"]?/$1/ig
173 s/(<frameset[^>]+?)frameborder=['"]?(no|0)['"]?/$1/ig
174
175
176 #################################################################################
177 #
178 # webbugs: Squish WebBugs (1x1 invisible GIFs used for user tracking)
179 #
180 #################################################################################
181 FILTER: webbugs
182
183 s/<img\s+[^>]*?(width|height)\s*=\s*['"]?1\D[^>]*?(width|height)\s*=\s*['"]?1(\D[^>]*?)?>/<!-- Squished WebBug -->/sig
184
185
186 #################################################################################
187 #
188 # no-refresh: Automatic refresh sucks on auto-dialup lines
189 #
190 #################################################################################
191 FILTER: no-refresh
192
193 # FIXME: second line like first line for content value
194 #
195 s/<meta[^>]*http-equiv[^>]*refresh.*([0-9]+[0-9]|"[2-9]);URL=([^>]*?)"?>/<link rev="x-refresh" href=$2>/i
196 s/<meta[^>]*http-equiv="?page-enter"?[^>]*content=[^>]*>/<!--no page enter for me-->/i
197
198
199 #################################################################################
200 #
201 # fun: Text replacements for subversive browsing fun!
202 #
203 #################################################################################
204 FILTER: fun
205
206 s/microsoft(?!.com)/MicroSuck/ig
207
208 # Buzzword Bingo:
209 #
210 s/industry-leading|cutting-edge|award-winning/<font color=red><b>BINGO!</b></font>/ig
211
212
213 #################################################################################
214 #
215 # nimda: Remove Nimda (virus) code
216 #
217 #################################################################################
218 FILTER: nimda
219
220 s%<script language="JavaScript">(window\.open|1;''\.concat)\("readme\.eml", null, "resizable=no,top=6000,left=6000"\)</script>%<br><hr><font size=7><b>Internet J</b></font><b><font size=6>UNK</font><font size=5 color="red"><i>BUSTER</i></font></b><font size=7> WARNING: This Server is infected with <a href="http://www.cert.org/advisories/CA-2001-26.html">Nimda</a>!</font>%g
221
222
223 #################################################################################
224 #
225 # banners-by-size: Kill banners by size
226 #
227 #################################################################################
228 #
229 # Standard banner sizes taken from http://www.iab.net/iab_banner_standards/bannersizes.html
230 #
231 # Note: Use http://ijbswa.sourceforge.net/config/send-banner?type=trans for a transparent 1x1 image
232 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=logo  for the logo image
233 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=logo  for a grey/white pattern image
234 #       Use http://ijbswa.sourceforge.net/config/send-banner?type=auto  to auto-select.
235 #
236 #################################################################################
237 FILTER: banners-by-size
238
239 s|<img\s+[^>]*?(width=['"]?468\D)[^>]*(height=['"]?60[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
240 s|<img\s+[^>]*?(width=['"]?234\D)[^>]*(height=['"]?60[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
241 s|<img\s+[^>]*?(width=['"]?88\D)[^>]*(height=['"]?31[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
242 s|<img\s+[^>]*?(width=['"]?120\D)[^>]*(height=['"]?90[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
243 s|<img\s+[^>]*?(width=['"]?120\D)[^>]*(height=['"]?600[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
244 s|<img\s+[^>]*?(width=['"]?120\D)[^>]*(height=['"]?60[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
245 s|<img\s+[^>]*?(width=['"]?160\D)[^>]*(height=['"]?600[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
246 s|<img\s+[^>]*?(width=['"]?125\D)[^>]*(height=['"]?125[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
247 s|<img\s+[^>]*?(width=['"]?120\D)[^>]*(height=['"]?240[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
248 s|<img\s+[^>]*?(width=['"]?180\D)[^>]*(height=['"]?150[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
249 s|<img\s+[^>]*?(width=['"]?300\D)[^>]*(height=['"]?250[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
250 s|<img\s+[^>]*?(width=['"]?250\D)[^>]*(height=['"]?250[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
251 s|<img\s+[^>]*?(width=['"]?240\D)[^>]*(height=['"]?400[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
252 s|<img\s+[^>]*?(width=['"]?336\D)[^>]*(height=['"]?280[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
253
254 # One more. (Where is 200x50 from?)
255 #
256 s|<img\s+[^>]*?(width=['"]?200\D)[^>]*(height=['"]?50[^>]*?)>|<img src=http://ijbswa.sourceforge.net/config/send-banner?type=auto $1 $2>|sig
257
258
259 #################################################################################
260 #
261 # crude-parental: Crude parental filtering?  (Use along with a suitable blocklist).
262 #                 Shows how to deny access to whole page based on a keyword.
263 #
264 #################################################################################
265 #
266 # (Note: Middlesex, Sussex and Essex are counties in the UK, not rude words)
267 # (Note #2: Is 'sex' a rude word?!)
268 #
269 #################################################################################
270 FILTER: crude-parental
271
272 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
273 s+^.*warez.*$+<html><head><title>No Warez</title></head><body><h3>You're not searching for illegal stuff, are you?</h3></body></html>+is