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
21 <LINK REL="STYLESHEET" TYPE="text/css" HREF="p_doc.css">
33 SUMMARY="Header navigation table"
42 >Privoxy 3.0.4 User Manual</TH
50 HREF="actions-file.html"
82 > On-the-fly text substitutions that can be invoked through the
86 HREF="actions-file.html#FILTER"
90 to be defined in a <SPAN
94 can then be invoked as an <SPAN
97 >. Mulitple filter files can be
98 defined through the <TT
101 HREF="config.html#FILTERFILE"
104 > config directive. The filters
105 as supplied by the developers will be found in
109 >. It is recommended that any locally
110 defined or modified filters go in a separately defined file such as
117 > Typical reasons for doing these kinds of substitutions are to eliminate
118 common annoyances in HTML and JavaScript, such as pop-up windows,
119 exit consoles, crippled windows without navigation tools, the
120 infamous <BLINK> tag etc, to suppress images with certain
121 width and height attributes (standard banner sizes or web-bugs),
122 or just to have fun. The possibilities are endless.</P
124 > Filtering works on any text-based document type, including
125 HTML, JavaScript, CSS etc. (all <TT
139 Substitutions are made at the source level, so if you want to <SPAN
143 > filters, you should first be familiar with HTML syntax,
144 and, of course, regular expressions. By default, filters are only applied
145 to the document content, but can be extended to the headers with
146 the supplemental actions:
148 HREF="actions-file.html#FILTER-CLIENT-HEADERS"
149 >filter-client-headers</A
152 HREF="actions-file.html#FILTER-SERVER-HEADERS"
153 >filter-server-headers</A
157 HREF="actions-file.html"
160 filter file is organized in sections, which are called <SPAN
167 here. Each filter consists of a heading line, that starts with the
184 >, and a short (one line)
191 > of what it does. Below that line
198 >, i.e. lines that define the actual
199 text substitutions. By convention, the name of a filter
200 should describe what the filter <SPAN
207 comment is used in the <A
208 HREF="http://config.privoxy.org/"
214 > Once a filter called <TT
220 in the filter file, it can be invoked by using an action of the form
224 HREF="actions-file.html#FILTER"
234 HREF="actions-file.html"
238 > A filter header line for a filter called <SPAN
252 >FILTER: foo Replace all "foo" with "bar"</PRE
258 > Below that line, and up to the next header line, come the jobs that
259 define what text replacements the filter executes. They are specified
260 in a syntax that imitates <A
261 HREF="http://www.perl.org/"
268 > operator. If you are familiar with Perl, you
269 will find this to be quite intuitive, and may want to look at the
270 PCRS documentation for the subtle differences to Perl behaviour. Most
271 notably, the non-standard option letter <TT
275 which turns the default to ungreedy matching.</P
277 > If you are new to regular expressions, you might want to take a look at
279 HREF="appendix.html#REGEX"
280 >Appendix on regular expressions</A
283 HREF="http://perldoc.perl.org/perlre.html"
289 HREF="http://perldoc.perl.org/perlop.html"
295 > operator's syntax</A
297 HREF="http://perldoc.perl.org/perlre.html"
302 The below examples might also help to get you started.</P
310 >9.1. Filter File Tutorial</H2
312 > Now, let's complete our <SPAN
315 > filter. We have already defined
316 the heading, but the jobs are still missing. Since all it does is to replace
323 >, there is only one (trivial) job
340 > But wait! Didn't the comment say that <SPAN
350 > should be replaced? Our current job will only take
351 care of the first <SPAN
354 > on each page. For global substitution,
355 we'll need to add the <TT
374 > Our complete filter now looks like this:</P
384 >FILTER: foo Replace all "foo" with "bar"
391 > Let's look at some real filters for more interesting examples. Here you see
392 a filter that protects against some common annoyances that arise from JavaScript
393 abuse. Let's look at its jobs one after the other:</P
403 >FILTER: js-annoyances Get rid of particularly annoying JavaScript abuse
405 # Get rid of JavaScript referrer tracking. Test page: http://www.randomoddness.com/untitled.htm
407 s|(<script.*)document\.referrer(.*</script>)|$1"Not Your Business!"$2|Usg</PRE
413 > Following the header line and a comment, you see the job. Note that it uses
417 > as the delimiter instead of <TT
421 the pattern contains a forward slash, which would otherwise have to be escaped
427 > Now, let's examine the pattern: it starts with the text <TT
431 enclosed in parentheses. Since the dot matches any character, and <TT
437 >"Match an arbitrary number of the element left of myself"</SPAN
449 it matches the whole page, from the start of the first <script> tag.</P
451 > That's more than we want, but the pattern continues: <TT
453 >document\.referrer</TT
455 matches only the exact string <SPAN
457 >"document.referrer"</SPAN
465 >, i.e. preceded by a backslash, to take away its
466 special meaning as a joker, and make it just a regular dot. So far, the meaning is:
467 Match from the start of the first <script> tag in a the page, up to, and including,
470 >"document.referrer"</SPAN
478 in the page (and appear in that order).</P
480 > But there's still more pattern to go. The next element, again enclosed in parentheses,
483 >.*</script></TT
484 >. You already know what <TT
488 means, so the whole pattern translates to: Match from the start of the first <script>
489 tag in a page to the end of the last <script> tag, provided that the text
492 >"document.referrer"</SPAN
493 > appears somewhere in between.</P
495 > This is still not the whole story, since we have ignored the options and the parentheses:
496 The portions of the page matched by sub-patterns that are enclosed in parentheses, will be
497 remembered and be available through the variables <TT
501 the substitute. The <TT
504 > option switches to ungreedy matching, which means
508 > in the pattern will only <SPAN
512 text in between <SPAN
524 >"document.referrer"</SPAN
525 >, and that the second <TT
529 only span the text up to the <SPAN
537 >"</script>"</SPAN
539 tag. Furthermore, the <TT
542 > option says that the match may span
543 multiple lines in the page, and the <TT
546 > option again means that the
547 substitution is global.</P
549 > So, to summarize, the pattern means: Match all scripts that contain the text
552 >"document.referrer"</SPAN
553 >. Remember the parts of the script from
554 (and including) the start tag up to (and excluding) the string
557 >"document.referrer"</SPAN
561 >, and the part following
562 that string, up to and including the closing tag, as <TT
567 > Now the pattern is deciphered, but wasn't this about substituting things? So
568 lets look at the substitute: <TT
570 >$1"Not Your Business!"$2</TT
572 easy to read: The text remembered as <TT
578 >"Not Your Business!"</TT
586 the quotation marks!), followed by the text remembered as <TT
590 This produces an exact copy of the original string, with the middle part
593 >"document.referrer"</SPAN
600 > The whole job now reads: Replace <SPAN
602 >"document.referrer"</SPAN
606 >"Not Your Business!"</TT
607 > wherever it appears inside a
608 <script> tag. Note that this job won't break JavaScript syntax,
609 since both the original and the replacement are syntactically valid
610 string objects. The script just won't have access to the referrer
611 information anymore.</P
613 > We'll show you two other jobs from the JavaScript taming department, but
614 this time only point out the constructs of special interest:</P
624 ># The status bar is for displaying link targets, not pointless blahblah
626 s/window\.status\s*=\s*(['"]).*?\1/dUmMy=1/ig</PRE
635 > stands for whitespace characters (space, tab, newline,
636 carriage return, form feed), so that <TT
642 or more whitespace"</SPAN
650 makes this matching of arbitrary text ungreedy. (Note that the <TT
654 option is not set). The <TT
657 > construct means: <SPAN
666 > a double quote"</SPAN
671 a backreference to the first parenthesis just like <TT
675 with the difference that in the <SPAN
681 >, a backslash indicates
682 a backreference, whereas in the <SPAN
688 >, it's the dollar.</P
690 > So what does this job do? It replaces assignments of single- or double-quoted
693 >"window.status"</SPAN
694 > object with a dummy assignment
695 (using a variable name that is hopefully odd enough not to conflict with
696 real variables in scripts). Thus, it catches many cases where e.g. pointless
697 descriptions are displayed in the status bar instead of the link target when
698 you move your mouse over links.</P
708 ># Kill OnUnload popups. Yummy. Test: http://www.zdnet.com/zdsubs/yahoo/tree/yfs.html
710 s/(<body [^>]*)onunload(.*>)/$1never$2/iU</PRE
718 HREF="http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-eventgroupings-htmlevents"
722 > in the HTML DOM was a <SPAN
729 When I close a browser window, I want it to close and die. Basta.
730 This job replaces the <SPAN
736 >"<body>"</SPAN
737 > tags with the dummy word <TT
744 > option makes the pattern matching
745 case-insensitive. Also note that ungreedy matching alone doesn't always guarantee
746 a minimal match: In the first parenthesis, we had to use <TT
753 > to prevent the match from exceeding the
754 <body> tag if it doesn't contain <SPAN
760 > The last example is from the fun department:</P
770 >FILTER: fun Fun text replacements
772 # Spice the daily news:
774 s/microsoft(?!\.com)/MicroSuck/ig</PRE
783 > part (a so-called negative lookahead)
784 in the job's pattern, which means: Don't match, if the string
788 > appears directly following <SPAN
792 in the page. This prevents links to microsoft.com from being trashed, while
793 still replacing the word everywhere else.</P
803 ># Buzzword Bingo (example for extended regex syntax)
805 s* industry[ -]leading \
807 | customer[ -]focused \
809 | award[ -]winning # Comments are OK, too! \
810 | high[ -]performance \
811 | solutions[ -]based \
815 *<font color="red"><b>BINGO!</b></font> \
825 > option in this job turns on extended syntax, and allows for
826 e.g. the liberal use of (non-interpreted!) whitespace for nicer formatting. </P
828 > You get the idea?</P
835 NAME="PREDEFINED-FILTERS"
837 >9.2. The Pre-defined Filters</H2
839 >The distribution <TT
842 > file contains a selection of
843 pre-defined filters for your convenience:</P
859 > The purpose of this filter is to get rid of particularly annoying JavaScript abuse.
866 > replaces JavaScript references to the browser's referrer information
867 with the string "Not Your Business!". This compliments the <TT
870 HREF="actions-file.html#HIDE-REFERRER"
873 > action on the content level.
878 > removes the bindings to the DOM's
880 HREF="http://www.w3.org/TR/2000/REC-DOM-Level-2-Events-20001113/events.html#Events-eventgroupings-htmlevents"
884 > which we feel has no right to exist and is responsible for most <SPAN
886 >"exit consoles"</SPAN
888 nasty windows that pop up when you close another one.
893 > removes code that causes new windows to be opened with undesired properties, such as being
894 full-screen, non-resizable, without location, status or menu bar etc.
911 > This is a very radical measure. It removes virtually all JavaScript event bindings, which
912 means that scripts can not react to user actions such as mouse movements or clicks, window
913 resizing etc, anymore.
920 >strongly discourage</I
922 > using this filter as a default since it breaks
923 many legitimate scripts. It is meant for use only on extra-nasty sites (should you really
937 > This filter will undo many common instances of HTML based abuse.
947 are neutralized (yeah baby!), and browser windows will be created as
948 resizable (as of course they should be!), and will have location,
949 scroll and menu bars -- even if specified otherwise.
962 > Most cookies are set in the HTTP dialogue, where they can be intercepted
967 HREF="actions-file.html#CRUNCH-INCOMING-COOKIES"
968 >crunch-incoming-cookies</A
974 HREF="actions-file.html#CRUNCH-OUTGOING-COOKIES"
975 >crunch-outgoing-cookies</A
978 actions. But web sites increasingly make use of HTML meta tags and JavaScript
979 to sneak cookies to the browser on the content level.
982 > This filter disables HTML and JavaScript code that reads or sets cookies. Use
983 it wherever you would also use the cookie crunch actions.
996 > Disable any refresh tags if the interval is greater than nine seconds (so
997 that redirections done via refresh tags are not destroyed). This is useful
998 for dial-on-demand setups, or for those who find this HTML feature
1007 >unsolicited-popups</I
1012 > This filter attempts to prevent only <SPAN
1014 >"unsolicited"</SPAN
1016 windows from opening, yet still allow pop-up windows that the user
1017 has explicitly chosen to open. It was added in version 3.0.1,
1018 as an improvement over earlier such filters.
1021 > Technical note: The filter works by redefining the window.open JavaScript
1022 function to a dummy function during the loading and rendering phase of each
1023 HTML page access, and restoring the function afterwards.
1036 > Attempt to prevent <SPAN
1042 > pop-up windows from opening.
1043 Note this should be used with more discretion than the above, since it is
1044 more likely to break some sites that require pop-ups for normal usage. Use
1058 > This is a helper filter that has no value if used alone. It makes the
1061 >banners-by-size</TT
1064 >banners-by-link</TT
1066 (see below) filters more effective and should be enabled together with them.
1079 > This filter removes image tags purely based on what size they are. Fortunately
1080 for us, many ads and banner images tend to conform to certain standardized
1081 sizes, which makes this filter quite effective for ad stripping purposes.
1084 > Occasionally this filter will cause false positives on images that are not ads,
1085 but just happen to be of one of the standard banner sizes.
1098 > This is an experimental filter that attempts to kill any banners if
1099 their URLs seem to point to known or suspected click trackers. It is currently
1100 not of much value and is not recommended for use by default.
1113 > Webbugs are small, invisible images (technically 1X1 GIF images), that
1114 are used to track users across websites, and collect information on them.
1115 As an HTML page is loaded by the browser, an embedded image tag causes the
1116 browser to contact a third-party site, disclosing the tracking information
1117 through the requested URL and/or cookies for that third-party domain, without
1118 the use ever becoming aware of the interaction with the third-party site.
1119 HTML-ized spam also uses a similar technique to verify email addresses.
1122 > This filter removes the HTML code that loads such <SPAN
1138 > A rather special-purpose filter that can be used to enlarge textareas (those
1139 multi-line text boxes in web forms) and turn off hard word wrap in them.
1140 It was written for the sourceforge.net tracker system where such boxes are
1141 a nuisance, but it can be handy on other sites, too.
1144 > It is not recommended to use this filter as a default.
1157 > Many consider windows that move, or resize themselves to be abusive. This filter
1158 neutralizes the related JavaScript code. Note that some sites might not display
1159 or behave as intended when using this filter.
1167 >frameset-borders</I
1172 > Some web designers seem to assume that everyone in the world will view their
1173 web sites using the same browser brand and version, screen resolution etc,
1174 because only that assumption could explain why they'd use static frame sizes,
1175 yet prevent their frames from being resized by the user, should they be too
1176 small to show their whole content.
1179 > This filter removes the related HTML code. It should only be applied to sites
1193 > Many Microsoft products that generate HTML use non-standard extensions (read:
1194 violations) of the ISO 8859-1 aka Latin-1 character set. This can cause those
1195 HTML documents to display with errors on standard-compliant platforms.
1198 > This filter translates the MS-only characters into Latin-1 equivalents.
1199 It is not necessary when using MS products, and will cause corruption of
1200 all documents that use 8-bit character sets other than Latin-1. It's mostly
1201 worthwhile for Europeans on non-MS platforms, if wierd garbage characters
1202 sometimes appear on some pages, or user agents that don't correct for this on
1217 > A filter for shockwave haters. As the name suggests, this filter strips code
1218 out of web pages that is used to embed shockwave flash objects.
1228 >quicktime-kioskmode</I
1233 > Change HTML code that embeds Quicktime objects so that kioskmode, which
1234 prevents saving, is disabled.
1247 > Text replacements for subversive browsing fun. Make fun of your favorite
1248 Monopolist or play buzzword bingo.
1261 > A demonstration-only filter that shows how <SPAN
1265 can be used to delete web content on a keyword basis.
1278 > A collection of text replacements to disable malicious HTML and JavaScript
1279 code that exploits known security holes in Internet Explorer.
1282 > Presently, it only protects against Nimda and a cross-site scripting bug, and
1283 would need active maintenance to provide more substantial protection.
1296 > Some web sites have very specific problems, the cure for which doesn't apply
1297 anywhere else, or could even cause damage on other sites.
1300 > This is a collection of such site-specific cures which should only be applied
1301 to the sites they were intended for, which is what the supplied
1305 > file does. Users shouldn't need to change
1306 anything regarding this filter.
1318 SUMMARY="Footer navigation table"
1329 HREF="actions-file.html"
1347 HREF="templates.html"