7 CONTENT="Modular DocBook HTML Stylesheet Version 1.76b+
10 TITLE="Privoxy 3.0.4 User Manual"
11 HREF="index.html"><LINK
14 HREF="actions-file.html"><LINK
17 HREF="templates.html"><LINK
20 HREF="../p_doc.css"></HEAD
31 SUMMARY="Header navigation table"
40 >Privoxy 3.0.4 User Manual</TH
48 HREF="actions-file.html"
80 > On-the-fly text substitutions that can be invoked through the
84 HREF="actions-file.html#FILTER"
88 to be defined in a <SPAN
92 can then be invoked as an <SPAN
95 >. Mulitple filter files can be
96 defined through the <TT
99 HREF="config.html#FILTERFILE"
102 > config directive. The filters
103 as supplied by the developers will be found in
107 >. It is recommended that any locally
108 defined or modified filters go in a separately defined file such as
115 > Typical reasons for doing these kinds of substitutions are to eliminate
116 common annoyances in HTML and JavaScript, such as pop-up windows,
117 exit consoles, crippled windows without navigation tools, the
118 infamous <BLINK> tag etc, to suppress images with certain
119 width and height attributes (standard banner sizes or web-bugs),
120 or just to have fun. The possibilities are endless.</P
122 > Filtering works on any text-based document type, including
123 HTML, JavaScript, CSS etc. (all <TT
137 Substitutions are made at the source level, so if you want to <SPAN
141 > filters, you should first be familiar with HTML syntax,
142 and, of course, regular expressions. By default, filters are only applied
143 to the document content, but can be extended to the headers with
144 the supplemental actions:
146 HREF="actions-file.html#FILTER-CLIENT-HEADERS"
147 >filter-client-headers</A
150 HREF="actions-file.html#FILTER-SERVER-HEADERS"
151 >filter-server-headers</A
155 HREF="actions-file.html"
158 filter file is organized in sections, which are called <SPAN
165 here. Each filter consists of a heading line, that starts with the
182 >, and a short (one line)
189 > of what it does. Below that line
196 >, i.e. lines that define the actual
197 text substitutions. By convention, the name of a filter
198 should describe what the filter <SPAN
205 comment is used in the <A
206 HREF="http://config.privoxy.org/"
212 > Once a filter called <TT
218 in the filter file, it can be invoked by using an action of the form
222 HREF="actions-file.html#FILTER"
232 HREF="actions-file.html"
236 > A filter header line for a filter called <SPAN
250 >FILTER: foo Replace all "foo" with "bar"</PRE
256 > Below that line, and up to the next header line, come the jobs that
257 define what text replacements the filter executes. They are specified
258 in a syntax that imitates <A
259 HREF="http://www.perl.org/"
266 > operator. If you are familiar with Perl, you
267 will find this to be quite intuitive, and may want to look at the
268 PCRS documentation for the subtle differences to Perl behaviour. Most
269 notably, the non-standard option letter <TT
273 which turns the default to ungreedy matching.</P
275 > If you are new to regular expressions, you might want to take a look at
277 HREF="appendix.html#REGEX"
278 >Appendix on regular expressions</A
281 HREF="http://perldoc.com/perl5.6.1/pod/perl.html"
287 HREF="http://perldoc.com/perl5.6.1/pod/perlop.html#s-PATTERN-REPLACEMENT-egimosx"
293 > operator's syntax</A
295 HREF="http://perldoc.com/perl5.6.1/pod/perlre.html"
300 The below examples might also help to get you started.</P
308 >9.1. Filter File Tutorial</H2
310 > Now, let's complete our <SPAN
313 > filter. We have already defined
314 the heading, but the jobs are still missing. Since all it does is to replace
321 >, there is only one (trivial) job
338 > But wait! Didn't the comment say that <SPAN
348 > should be replaced? Our current job will only take
349 care of the first <SPAN
352 > on each page. For global substitution,
353 we'll need to add the <TT
372 > Our complete filter now looks like this:</P
382 >FILTER: foo Replace all "foo" with "bar"
389 > Let's look at some real filters for more interesting examples. Here you see
390 a filter that protects against some common annoyances that arise from JavaScript
391 abuse. Let's look at its jobs one after the other:</P
401 >FILTER: js-annoyances Get rid of particularly annoying JavaScript abuse
403 # Get rid of JavaScript referrer tracking. Test page: http://www.randomoddness.com/untitled.htm
405 s|(<script.*)document\.referrer(.*</script>)|$1"Not Your Business!"$2|Usg</PRE
411 > Following the header line and a comment, you see the job. Note that it uses
415 > as the delimiter instead of <TT
419 the pattern contains a forward slash, which would otherwise have to be escaped
425 > Now, let's examine the pattern: it starts with the text <TT
429 enclosed in parentheses. Since the dot matches any character, and <TT
435 >"Match an arbitrary number of the element left of myself"</SPAN
447 it matches the whole page, from the start of the first <script> tag.</P
449 > That's more than we want, but the pattern continues: <TT
451 >document\.referrer</TT
453 matches only the exact string <SPAN
455 >"document.referrer"</SPAN
463 >, i.e. preceded by a backslash, to take away its
464 special meaning as a joker, and make it just a regular dot. So far, the meaning is:
465 Match from the start of the first <script> tag in a the page, up to, and including,
468 >"document.referrer"</SPAN
476 in the page (and appear in that order).</P
478 > But there's still more pattern to go. The next element, again enclosed in parentheses,
481 >.*</script></TT
482 >. You already know what <TT
486 means, so the whole pattern translates to: Match from the start of the first <script>
487 tag in a page to the end of the last <script> tag, provided that the text
490 >"document.referrer"</SPAN
491 > appears somewhere in between.</P
493 > This is still not the whole story, since we have ignored the options and the parentheses:
494 The portions of the page matched by sub-patterns that are enclosed in parentheses, will be
495 remembered and be available through the variables <TT
499 the substitute. The <TT
502 > option switches to ungreedy matching, which means
506 > in the pattern will only <SPAN
510 text in between <SPAN
522 >"document.referrer"</SPAN
523 >, and that the second <TT
527 only span the text up to the <SPAN
535 >"</script>"</SPAN
537 tag. Furthermore, the <TT
540 > option says that the match may span
541 multiple lines in the page, and the <TT
544 > option again means that the
545 substitution is global.</P
547 > So, to summarize, the pattern means: Match all scripts that contain the text
550 >"document.referrer"</SPAN
551 >. Remember the parts of the script from
552 (and including) the start tag up to (and excluding) the string
555 >"document.referrer"</SPAN
559 >, and the part following
560 that string, up to and including the closing tag, as <TT
565 > Now the pattern is deciphered, but wasn't this about substituting things? So
566 lets look at the substitute: <TT
568 >$1"Not Your Business!"$2</TT
570 easy to read: The text remembered as <TT
576 >"Not Your Business!"</TT
584 the quotation marks!), followed by the text remembered as <TT
588 This produces an exact copy of the original string, with the middle part
591 >"document.referrer"</SPAN
598 > The whole job now reads: Replace <SPAN
600 >"document.referrer"</SPAN
604 >"Not Your Business!"</TT
605 > wherever it appears inside a
606 <script> tag. Note that this job won't break JavaScript syntax,
607 since both the original and the replacement are syntactically valid
608 string objects. The script just won't have access to the referrer
609 information anymore.</P
611 > We'll show you two other jobs from the JavaScript taming department, but
612 this time only point out the constructs of special interest:</P
622 ># The status bar is for displaying link targets, not pointless blahblah
624 s/window\.status\s*=\s*(['"]).*?\1/dUmMy=1/ig</PRE
633 > stands for whitespace characters (space, tab, newline,
634 carriage return, form feed), so that <TT
640 or more whitespace"</SPAN
648 makes this matching of arbitrary text ungreedy. (Note that the <TT
652 option is not set). The <TT
655 > construct means: <SPAN
664 > a double quote"</SPAN
669 a backreference to the first parenthesis just like <TT
673 with the difference that in the <SPAN
679 >, a backslash indicates
680 a backreference, whereas in the <SPAN
686 >, it's the dollar.</P
688 > So what does this job do? It replaces assignments of single- or double-quoted
691 >"window.status"</SPAN
692 > object with a dummy assignment
693 (using a variable name that is hopefully odd enough not to conflict with
694 real variables in scripts). Thus, it catches many cases where e.g. pointless
695 descriptions are displayed in the status bar instead of the link target when
696 you move your mouse over links.</P
706 ># Kill OnUnload popups. Yummy. Test: http://www.zdnet.com/zdsubs/yahoo/tree/yfs.html
708 s/(<body [^>]*)onunload(.*>)/$1never$2/iU</PRE
716 HREF="http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-eventgroupings-htmlevents"
720 > in the HTML DOM was a <SPAN
727 When I close a browser window, I want it to close and die. Basta.
728 This job replaces the <SPAN
734 >"<body>"</SPAN
735 > tags with the dummy word <TT
742 > option makes the pattern matching
743 case-insensitive. Also note that ungreedy matching alone doesn't always guarantee
744 a minimal match: In the first parenthesis, we had to use <TT
751 > to prevent the match from exceeding the
752 <body> tag if it doesn't contain <SPAN
758 > The last example is from the fun department:</P
768 >FILTER: fun Fun text replacements
770 # Spice the daily news:
772 s/microsoft(?!\.com)/MicroSuck/ig</PRE
781 > part (a so-called negative lookahead)
782 in the job's pattern, which means: Don't match, if the string
786 > appears directly following <SPAN
790 in the page. This prevents links to microsoft.com from being trashed, while
791 still replacing the word everywhere else.</P
801 ># Buzzword Bingo (example for extended regex syntax)
803 s* industry[ -]leading \
805 | customer[ -]focused \
807 | award[ -]winning # Comments are OK, too! \
808 | high[ -]performance \
809 | solutions[ -]based \
813 *<font color="red"><b>BINGO!</b></font> \
823 > option in this job turns on extended syntax, and allows for
824 e.g. the liberal use of (non-interpreted!) whitespace for nicer formatting. </P
826 > You get the idea?</P
833 NAME="PREDEFINED-FILTERS"
835 >9.2. The Pre-defined Filters</H2
837 >The distribution <TT
840 > file contains a selection of
841 pre-defined filters for your convenience:</P
857 > The purpose of this filter is to get rid of particularly annoying JavaScript abuse.
864 > replaces JavaScript references to the browser's referrer information
865 with the string "Not Your Business!". This compliments the <TT
868 HREF="actions-file.html#HIDE-REFERRER"
871 > action on the content level.
876 > removes the bindings to the DOM's
878 HREF="http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-eventgroupings-htmlevents"
882 > which we feel has no right to exist and is responsible for most <SPAN
884 >"exit consoles"</SPAN
886 nasty windows that pop up when you close another one.
891 > removes code that causes new windows to be opened with undesired properties, such as being
892 full-screen, non-resizable, without location, status or menu bar etc.
909 > This is a very radical measure. It removes virtually all JavaScript event bindings, which
910 means that scripts can not react to user actions such as mouse movements or clicks, window
911 resizing etc, anymore.
918 >strongly discourage</I
920 > using this filter as a default since it breaks
921 many legitimate scripts. It is meant for use only on extra-nasty sites (should you really
935 > This filter will undo many common instances of HTML based abuse.
945 are neutralized (yeah baby!), and browser windows will be created as
946 resizable (as of course they should be!), and will have location,
947 scroll and menu bars -- even if specified otherwise.
960 > Most cookies are set in the HTTP dialogue, where they can be intercepted
965 HREF="actions-file.html#CRUNCH-INCOMING-COOKIES"
966 >crunch-incoming-cookies</A
972 HREF="actions-file.html#CRUNCH-OUTGOING-COOKIES"
973 >crunch-outgoing-cookies</A
976 actions. But web sites increasingly make use of HTML meta tags and JavaScript
977 to sneak cookies to the browser on the content level.
980 > This filter disables HTML and JavaScript code that reads or sets cookies. Use
981 it wherever you would also use the cookie crunch actions.
994 > Disable any refresh tags if the interval is greater than nine seconds (so
995 that redirections done via refresh tags are not destroyed). This is useful
996 for dial-on-demand setups, or for those who find this HTML feature
1005 >unsolicited-popups</I
1010 > This filter attempts to prevent only <SPAN
1012 >"unsolicited"</SPAN
1014 windows from opening, yet still allow pop-up windows that the user
1015 has explicitly chosen to open. It was added in version 3.0.1,
1016 as an improvement over earlier such filters.
1019 > Technical note: The filter works by redefining the window.open JavaScript
1020 function to a dummy function during the loading and rendering phase of each
1021 HTML page access, and restoring the function afterwards.
1034 > Attempt to prevent <SPAN
1040 > pop-up windows from opening.
1041 Note this should be used with more discretion than the above, since it is
1042 more likely to break some sites that require pop-ups for normal usage. Use
1056 > This is a helper filter that has no value if used alone. It makes the
1059 >banners-by-size</TT
1062 >banners-by-link</TT
1064 (see below) filters more effective and should be enabled together with them.
1077 > This filter removes image tags purely based on what size they are. Fortunately
1078 for us, many ads and banner images tend to conform to certain standardized
1079 sizes, which makes this filter quite effective for ad stripping purposes.
1082 > Occasionally this filter will cause false positives on images that are not ads,
1083 but just happen to be of one of the standard banner sizes.
1096 > This is an experimental filter that attempts to kill any banners if
1097 their URLs seem to point to known or suspected click trackers. It is currently
1098 not of much value and is not recommended for use by default.
1111 > Webbugs are small, invisible images (technically 1X1 GIF images), that
1112 are used to track users across websites, and collect information on them.
1113 As an HTML page is loaded by the browser, an embedded image tag causes the
1114 browser to contact a third-party site, disclosing the tracking information
1115 through the requested URL and/or cookies for that third-party domain, without
1116 the use ever becoming aware of the interaction with the third-party site.
1117 HTML-ized spam also uses a similar technique to verify email addresses.
1120 > This filter removes the HTML code that loads such <SPAN
1136 > A rather special-purpose filter that can be used to enlarge textareas (those
1137 multi-line text boxes in web forms) and turn off hard word wrap in them.
1138 It was written for the sourceforge.net tracker system where such boxes are
1139 a nuisance, but it can be handy on other sites, too.
1142 > It is not recommended to use this filter as a default.
1155 > Many consider windows that move, or resize themselves to be abusive. This filter
1156 neutralizes the related JavaScript code. Note that some sites might not display
1157 or behave as intended when using this filter.
1165 >frameset-borders</I
1170 > Some web designers seem to assume that everyone in the world will view their
1171 web sites using the same browser brand and version, screen resolution etc,
1172 because only that assumption could explain why they'd use static frame sizes,
1173 yet prevent their frames from being resized by the user, should they be too
1174 small to show their whole content.
1177 > This filter removes the related HTML code. It should only be applied to sites
1191 > Many Microsoft products that generate HTML use non-standard extensions (read:
1192 violations) of the ISO 8859-1 aka Latin-1 character set. This can cause those
1193 HTML documents to display with errors on standard-compliant platforms.
1196 > This filter translates the MS-only characters into Latin-1 equivalents.
1197 It is not necessary when using MS products, and will cause corruption of
1198 all documents that use 8-bit character sets other than Latin-1. It's mostly
1199 worthwhile for Europeans on non-MS platforms, if wierd garbage characters
1200 sometimes appear on some pages, or user agents that don't correct for this on
1215 > A filter for shockwave haters. As the name suggests, this filter strips code
1216 out of web pages that is used to embed shockwave flash objects.
1226 >quicktime-kioskmode</I
1231 > Change HTML code that embeds Quicktime objects so that kioskmode, which
1232 prevents saving, is disabled.
1245 > Text replacements for subversive browsing fun. Make fun of your favorite
1246 Monopolist or play buzzword bingo.
1259 > A demonstration-only filter that shows how <SPAN
1263 can be used to delete web content on a keyword basis.
1276 > A collection of text replacements to disable malicious HTML and JavaScript
1277 code that exploits known security holes in Internet Explorer.
1280 > Presently, it only protects against Nimda and a cross-site scripting bug, and
1281 would need active maintenance to provide more substantial protection.
1294 > Some web sites have very specific problems, the cure for which doesn't apply
1295 anywhere else, or could even cause damage on other sites.
1298 > This is a collection of such site-specific cures which should only be applied
1299 to the sites they were intended for, which is what the supplied
1303 > file does. Users shouldn't need to change
1304 anything regarding this filter.
1316 SUMMARY="Footer navigation table"
1327 HREF="actions-file.html"
1345 HREF="templates.html"