/usr/share/doc/libowasp-java-html-sanitizer-java/api/org/owasp/html/HtmlPolicyBuilder.html is in libowasp-java-html-sanitizer-java-doc 0.1+r88-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 | <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<!--NewPage-->
<HTML>
<HEAD>
<!-- Generated by javadoc (build 1.6.0_24) on Tue Mar 27 12:05:03 UTC 2012 -->
<META http-equiv="Content-Type" content="text/html; charset=UTF-8">
<TITLE>
HtmlPolicyBuilder (OWASP Java HTML Sanitizer r88 API)
</TITLE>
<META NAME="date" CONTENT="2012-03-27">
<LINK REL ="stylesheet" TYPE="text/css" HREF="../../../stylesheet.css" TITLE="Style">
<SCRIPT type="text/javascript">
function windowTitle()
{
if (location.href.indexOf('is-external=true') == -1) {
parent.document.title="HtmlPolicyBuilder (OWASP Java HTML Sanitizer r88 API)";
}
}
</SCRIPT>
<NOSCRIPT>
</NOSCRIPT>
</HEAD>
<BODY BGCOLOR="white" onload="windowTitle();">
<HR>
<!-- ========= START OF TOP NAVBAR ======= -->
<A NAME="navbar_top"><!-- --></A>
<A HREF="#skip-navbar_top" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_top_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/HtmlPolicyBuilder.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../org/owasp/html/Handler.html" title="interface in org.owasp.html"><B>PREV CLASS</B></A>
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html" title="class in org.owasp.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?org/owasp/html/HtmlPolicyBuilder.html" target="_top"><B>FRAMES</B></A>
<A HREF="HtmlPolicyBuilder.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: <A HREF="#nested_class_summary">NESTED</A> | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_top"></A>
<!-- ========= END OF TOP NAVBAR ========= -->
<HR>
<!-- ======== START OF CLASS DATA ======== -->
<H2>
<FONT SIZE="-1">
org.owasp.html</FONT>
<BR>
Class HtmlPolicyBuilder</H2>
<PRE>
java.lang.Object
<IMG SRC="../../../resources/inherit.gif" ALT="extended by "><B>org.owasp.html.HtmlPolicyBuilder</B>
</PRE>
<HR>
<DL>
<DT><PRE><FONT SIZE="-1">@NotThreadSafe
</FONT>public class <B>HtmlPolicyBuilder</B><DT>extends java.lang.Object</DL>
</PRE>
<P>
Conveniences for configuring policies for the <A HREF="../../../org/owasp/html/HtmlSanitizer.html" title="class in org.owasp.html"><CODE>HtmlSanitizer</CODE></A>.
<h3>Usage</h3>
<p>
To create a policy, first construct an instance of this class; then call
<code>allow…</code> methods to turn on tags, attributes, and other
processing modes; and finally call <code>build()</code> or
<code>toFactory()</code>.
</p>
<pre class="prettyprint lang-java">
// Define the policy.
Function<HtmlStreamEventReceiver, HtmlSanitizer.Policy> policyDefinition
= new HtmlPolicyBuilder()
.allowElements("a", "p")
.allowAttributes("href").onElements("a")
.toFactory();
// Sanitize your output.
HtmlSanitizer.sanitize(myHtml. policyDefinition.apply(myHtmlStreamRenderer));
</pre>
<h3>Embedded Content</h3>
<p>
Embedded URLs are filtered by
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowUrlProtocols(java.lang.String...)"><CODE>protocol</CODE></A>.
There is a <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowStandardUrlProtocols()"><CODE>canned policy</CODE></A>
so you can easily white-list widely used policies that don't violate the
current pages origin. See "Customization" below for ways to do further
filtering. If you allow links it might be worthwhile to
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#requireRelNofollowOnLinks()"><CODE>require</CODE></A>
<code>rel=nofollow</code>.
</p>
<p>
This class simply throws out all embedded JS.
Use a custom element or attribute policy to allow through
signed or otherwise known-safe code.
Check out the Caja project if you need a way to contain third-party JS.
</p>
<p>
This class does not attempt to faithfully parse and sanitize CSS.
It does provide <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowStyling()"><CODE>one</CODE></A> styling option
that allows through a few CSS properties that allow textual styling, but that
disallow image loading, history stealing, layout breaking, code execution,
etc.
</p>
<h3>Customization</h3>
<p>
You can easily do custom processing on tags and attributes by supplying your
own <A HREF="../../../org/owasp/html/ElementPolicy.html" title="interface in org.owasp.html"><CODE>element policy</CODE></A> or
<A HREF="../../../org/owasp/html/AttributePolicy.html" title="interface in org.owasp.html"><CODE>attribute policy</CODE></A> when calling
<code>allow…</code>.
E.g. to convert headers into <code><div></code>s, you could use an element policy
</p>
<pre class="prettyprint lang-java">
new HtmlPolicyBuilder
.allowElement(
new ElementPolicy() {
public String apply(String elementName, List<String> attributes) {
attributes.add("class");
attributes.add("header-" + elementName);
return "div";
}
},
"h1", "h2", "h3", "h4", "h5", "h6")
.build(outputChannel)
</pre>
<h3>Rules of Thumb</h3>
<p>
Throughout this class, several rules hold:
<ul>
<li>Everything is denied by default. There are
<code>disallow…</code> methods, but those reverse
allows instead of rolling back overly permissive defaults.
<li>The order of allows and disallows does not matter.
Disallows trump allows whether they occur before or after them.
The only method that needs to be called in a particular place is
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#build(org.owasp.html.HtmlStreamEventReceiver)"><CODE>build(org.owasp.html.HtmlStreamEventReceiver)</CODE></A>.
Allows or disallows after <code>build</code> is called have no
effect on the already built policy.
<li>Element and attribute policies are applied in the following order:
element specific attribute policy, global attribute policy, element
policy.
Element policies come last so they can observe all the post-processed
attributes, and so they can add attributes that are exempt from
attribute policies.
Element specific policies go first, so they can normalize content to
a form that might be acceptable to a more simplistic global policy.
</ul>
<h3>Thread safety and efficiency</h3>
<p>
This class is not thread-safe. The resulting policy will not violate its
security guarantees as a result of race conditions, but is not thread safe
because it maintains state to track whether text inside disallowed elements
should be suppressed.
<p>
The resulting policy can be reused, but if you use the
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#toFactory()"><CODE>toFactory()</CODE></A> method instead of <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#build(org.owasp.html.HtmlStreamEventReceiver)"><CODE>build(org.owasp.html.HtmlStreamEventReceiver)</CODE></A>, then
binding policies to output channels is cheap so there's no need.
</p>
<P>
<P>
<DL>
<DT><B>Author:</B></DT>
<DD>Mike Samuel <mikesamuel@gmail.com></DD>
</DL>
<HR>
<P>
<!-- ======== NESTED CLASS SUMMARY ======== -->
<A NAME="nested_class_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Nested Class Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> class</CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder.AttributeBuilder</A></B></CODE>
<BR>
Builds the relationship between attributes, the values that they may have,
and the elements on which they may appear.</TD>
</TR>
</TABLE>
<!-- =========== FIELD SUMMARY =========== -->
<A NAME="field_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Field Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE>static com.google.common.collect.ImmutableSet<java.lang.String></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#DEFAULT_SKIP_IF_EMPTY">DEFAULT_SKIP_IF_EMPTY</A></B></CODE>
<BR>
The default set of elements that are removed if they have no attributes.</TD>
</TR>
</TABLE>
<!-- ======== CONSTRUCTOR SUMMARY ======== -->
<A NAME="constructor_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Constructor Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#HtmlPolicyBuilder()">HtmlPolicyBuilder</A></B>()</CODE>
<BR>
</TD>
</TR>
</TABLE>
<!-- ========== METHOD SUMMARY =========== -->
<A NAME="method_summary"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="2"><FONT SIZE="+2">
<B>Method Summary</B></FONT></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder.AttributeBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowAttributes(java.lang.String...)">allowAttributes</A></B>(java.lang.String... attributeNames)</CODE>
<BR>
Returns an object that lets you associate policies with the given
attributes, and allow them globally or on specific elements.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowCommonBlockElements()">allowCommonBlockElements</A></B>()</CODE>
<BR>
A canned policy that allows a number of common block elements.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowCommonInlineFormattingElements()">allowCommonInlineFormattingElements</A></B>()</CODE>
<BR>
A canned policy that allows a number of common formatting elements.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowElements(org.owasp.html.ElementPolicy, java.lang.String...)">allowElements</A></B>(<A HREF="../../../org/owasp/html/ElementPolicy.html" title="interface in org.owasp.html">ElementPolicy</A> policy,
java.lang.String... elementNames)</CODE>
<BR>
Allow the given elements with the given policy.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowElements(java.lang.String...)">allowElements</A></B>(java.lang.String... elementNames)</CODE>
<BR>
Allows the named elements.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowStandardUrlProtocols()">allowStandardUrlProtocols</A></B>()</CODE>
<BR>
A canned URL protocol policy that allows <code>http</code>,
<code>https</code>, and <code>mailto</code>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowStyling()">allowStyling</A></B>()</CODE>
<BR>
Convert <code>style="<CSS>"</code> to simple non-JS containing
<code><font></code> tags to allow color, font-size, typeface, and
other styling.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowUrlProtocols(java.lang.String...)">allowUrlProtocols</A></B>(java.lang.String... protocols)</CODE>
<BR>
Adds to the set of protocols that are allowed in URL attributes.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowWithoutAttributes(java.lang.String...)">allowWithoutAttributes</A></B>(java.lang.String... elementNames)</CODE>
<BR>
Assuming the given elements are allowed, allows them to appear without
attributes.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlSanitizer.Policy.html" title="interface in org.owasp.html">HtmlSanitizer.Policy</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#build(org.owasp.html.HtmlStreamEventReceiver)">build</A></B>(<A HREF="../../../org/owasp/html/HtmlStreamEventReceiver.html" title="interface in org.owasp.html">HtmlStreamEventReceiver</A> out)</CODE>
<BR>
Produces a policy based on the allow and disallow calls previously made.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder.AttributeBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#disallowAttributes(java.lang.String...)">disallowAttributes</A></B>(java.lang.String... attributeNames)</CODE>
<BR>
Reverse an earlier attribute <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowAttributes(java.lang.String...)"><CODE>allow</CODE></A>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#disallowElements(java.lang.String...)">disallowElements</A></B>(java.lang.String... elementNames)</CODE>
<BR>
Disallows the named elements.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#disallowUrlProtocols(java.lang.String...)">disallowUrlProtocols</A></B>(java.lang.String... protocols)</CODE>
<BR>
Reverses a decision made by <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowUrlProtocols(java.lang.String...)"><CODE>allowUrlProtocols(java.lang.String...)</CODE></A>.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#disallowWithoutAttributes(java.lang.String...)">disallowWithoutAttributes</A></B>(java.lang.String... elementNames)</CODE>
<BR>
Disallows the given elements from appearing without attributes.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#requireRelNofollowOnLinks()">requireRelNofollowOnLinks</A></B>()</CODE>
<BR>
Adds <a href="http://en.wikipedia.org/wiki/Nofollow"><code>rel=nofollow</code></a>
to links.</TD>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD ALIGN="right" VALIGN="top" WIDTH="1%"><FONT SIZE="-1">
<CODE> <A HREF="../../../org/owasp/html/PolicyFactory.html" title="class in org.owasp.html">PolicyFactory</A></CODE></FONT></TD>
<TD><CODE><B><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#toFactory()">toFactory</A></B>()</CODE>
<BR>
Like <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#build(org.owasp.html.HtmlStreamEventReceiver)"><CODE>build(org.owasp.html.HtmlStreamEventReceiver)</CODE></A> but can be reused to create many different policies
each backed by a different output channel.</TD>
</TR>
</TABLE>
<A NAME="methods_inherited_from_class_java.lang.Object"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#EEEEFF" CLASS="TableSubHeadingColor">
<TH ALIGN="left"><B>Methods inherited from class java.lang.Object</B></TH>
</TR>
<TR BGCOLOR="white" CLASS="TableRowColor">
<TD><CODE>clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait</CODE></TD>
</TR>
</TABLE>
<P>
<!-- ============ FIELD DETAIL =========== -->
<A NAME="field_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Field Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="DEFAULT_SKIP_IF_EMPTY"><!-- --></A><H3>
DEFAULT_SKIP_IF_EMPTY</H3>
<PRE>
public static final com.google.common.collect.ImmutableSet<java.lang.String> <B>DEFAULT_SKIP_IF_EMPTY</B></PRE>
<DL>
<DD>The default set of elements that are removed if they have no attributes.
Since <code><img></code> is in this set, by default, a policy will remove
<code><img src=javascript:alert(1337)></code> because its URL is not allowed
and it has no other attributes that would warrant it appearing in the
output.
<P>
<DL>
</DL>
</DL>
<!-- ========= CONSTRUCTOR DETAIL ======== -->
<A NAME="constructor_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Constructor Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="HtmlPolicyBuilder()"><!-- --></A><H3>
HtmlPolicyBuilder</H3>
<PRE>
public <B>HtmlPolicyBuilder</B>()</PRE>
<DL>
</DL>
<!-- ============ METHOD DETAIL ========== -->
<A NAME="method_detail"><!-- --></A>
<TABLE BORDER="1" WIDTH="100%" CELLPADDING="3" CELLSPACING="0" SUMMARY="">
<TR BGCOLOR="#CCCCFF" CLASS="TableHeadingColor">
<TH ALIGN="left" COLSPAN="1"><FONT SIZE="+2">
<B>Method Detail</B></FONT></TH>
</TR>
</TABLE>
<A NAME="allowElements(java.lang.String...)"><!-- --></A><H3>
allowElements</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowElements</B>(java.lang.String... elementNames)</PRE>
<DL>
<DD>Allows the named elements.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="disallowElements(java.lang.String...)"><!-- --></A><H3>
disallowElements</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>disallowElements</B>(java.lang.String... elementNames)</PRE>
<DL>
<DD>Disallows the named elements. Elements are disallowed by default, so
there is no need to disallow elements, unless you are making an exception
based on an earlier allow.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="allowElements(org.owasp.html.ElementPolicy, java.lang.String...)"><!-- --></A><H3>
allowElements</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowElements</B>(<A HREF="../../../org/owasp/html/ElementPolicy.html" title="interface in org.owasp.html">ElementPolicy</A> policy,
java.lang.String... elementNames)</PRE>
<DL>
<DD>Allow the given elements with the given policy.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>policy</CODE> - May remove or add attributes, change the element name, or
deny the element.</DL>
</DD>
</DL>
<HR>
<A NAME="allowCommonInlineFormattingElements()"><!-- --></A><H3>
allowCommonInlineFormattingElements</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowCommonInlineFormattingElements</B>()</PRE>
<DL>
<DD>A canned policy that allows a number of common formatting elements.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="allowCommonBlockElements()"><!-- --></A><H3>
allowCommonBlockElements</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowCommonBlockElements</B>()</PRE>
<DL>
<DD>A canned policy that allows a number of common block elements.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="allowWithoutAttributes(java.lang.String...)"><!-- --></A><H3>
allowWithoutAttributes</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowWithoutAttributes</B>(java.lang.String... elementNames)</PRE>
<DL>
<DD>Assuming the given elements are allowed, allows them to appear without
attributes.
<P>
<DD><DL>
<DT><B>See Also:</B><DD><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#DEFAULT_SKIP_IF_EMPTY"><CODE>DEFAULT_SKIP_IF_EMPTY</CODE></A>,
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#disallowWithoutAttributes(java.lang.String...)"><CODE>disallowWithoutAttributes(java.lang.String...)</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="disallowWithoutAttributes(java.lang.String...)"><!-- --></A><H3>
disallowWithoutAttributes</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>disallowWithoutAttributes</B>(java.lang.String... elementNames)</PRE>
<DL>
<DD>Disallows the given elements from appearing without attributes.
<P>
<DD><DL>
<DT><B>See Also:</B><DD><A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#DEFAULT_SKIP_IF_EMPTY"><CODE>DEFAULT_SKIP_IF_EMPTY</CODE></A>,
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowWithoutAttributes(java.lang.String...)"><CODE>allowWithoutAttributes(java.lang.String...)</CODE></A></DL>
</DD>
</DL>
<HR>
<A NAME="allowAttributes(java.lang.String...)"><!-- --></A><H3>
allowAttributes</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder.AttributeBuilder</A> <B>allowAttributes</B>(java.lang.String... attributeNames)</PRE>
<DL>
<DD>Returns an object that lets you associate policies with the given
attributes, and allow them globally or on specific elements.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="disallowAttributes(java.lang.String...)"><!-- --></A><H3>
disallowAttributes</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder.AttributeBuilder</A> <B>disallowAttributes</B>(java.lang.String... attributeNames)</PRE>
<DL>
<DD>Reverse an earlier attribute <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowAttributes(java.lang.String...)"><CODE>allow</CODE></A>.
<p>
For this to have an effect you must call at least one of
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html#globally()"><CODE>HtmlPolicyBuilder.AttributeBuilder.globally()</CODE></A> and <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html#onElements(java.lang.String...)"><CODE>HtmlPolicyBuilder.AttributeBuilder.onElements(java.lang.String...)</CODE></A>.
<p>
Attributes are disallowed by default, so there is no need to call this
with a laundry list of attribute/element pairs.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="requireRelNofollowOnLinks()"><!-- --></A><H3>
requireRelNofollowOnLinks</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>requireRelNofollowOnLinks</B>()</PRE>
<DL>
<DD>Adds <a href="http://en.wikipedia.org/wiki/Nofollow"><code>rel=nofollow</code></a>
to links.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="allowUrlProtocols(java.lang.String...)"><!-- --></A><H3>
allowUrlProtocols</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowUrlProtocols</B>(java.lang.String... protocols)</PRE>
<DL>
<DD>Adds to the set of protocols that are allowed in URL attributes.
For each URL attribute that is allowed, we further constrain it by
only allowing the value through if it specifies no protocol, or if it
specifies one in the allowedProtocols white-list.
This is done regardless of whether any protocols have been allowed, so
allowing the attribute "href" globally with the identity policy but
not white-listing any protocols, effectively disallows the "href"
attribute globally.
<p>
Do not allow any <code>*script</code> such as <code>javascript</code>
protocols if you might use this policy with untrusted code.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="disallowUrlProtocols(java.lang.String...)"><!-- --></A><H3>
disallowUrlProtocols</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>disallowUrlProtocols</B>(java.lang.String... protocols)</PRE>
<DL>
<DD>Reverses a decision made by <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#allowUrlProtocols(java.lang.String...)"><CODE>allowUrlProtocols(java.lang.String...)</CODE></A>.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="allowStandardUrlProtocols()"><!-- --></A><H3>
allowStandardUrlProtocols</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowStandardUrlProtocols</B>()</PRE>
<DL>
<DD>A canned URL protocol policy that allows <code>http</code>,
<code>https</code>, and <code>mailto</code>.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="allowStyling()"><!-- --></A><H3>
allowStyling</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html" title="class in org.owasp.html">HtmlPolicyBuilder</A> <B>allowStyling</B>()</PRE>
<DL>
<DD>Convert <code>style="<CSS>"</code> to simple non-JS containing
<code><font></code> tags to allow color, font-size, typeface, and
other styling.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<HR>
<A NAME="build(org.owasp.html.HtmlStreamEventReceiver)"><!-- --></A><H3>
build</H3>
<PRE>
public <A HREF="../../../org/owasp/html/HtmlSanitizer.Policy.html" title="interface in org.owasp.html">HtmlSanitizer.Policy</A> <B>build</B>(<A HREF="../../../org/owasp/html/HtmlStreamEventReceiver.html" title="interface in org.owasp.html">HtmlStreamEventReceiver</A> out)</PRE>
<DL>
<DD>Produces a policy based on the allow and disallow calls previously made.
<P>
<DD><DL>
<DT><B>Parameters:</B><DD><CODE>out</CODE> - receives calls to open only tags allowed by
previous calls to this object.
Typically a <A HREF="../../../org/owasp/html/HtmlStreamRenderer.html" title="class in org.owasp.html"><CODE>HtmlStreamRenderer</CODE></A>.</DL>
</DD>
</DL>
<HR>
<A NAME="toFactory()"><!-- --></A><H3>
toFactory</H3>
<PRE>
public <A HREF="../../../org/owasp/html/PolicyFactory.html" title="class in org.owasp.html">PolicyFactory</A> <B>toFactory</B>()</PRE>
<DL>
<DD>Like <A HREF="../../../org/owasp/html/HtmlPolicyBuilder.html#build(org.owasp.html.HtmlStreamEventReceiver)"><CODE>build(org.owasp.html.HtmlStreamEventReceiver)</CODE></A> but can be reused to create many different policies
each backed by a different output channel.
<P>
<DD><DL>
</DL>
</DD>
</DL>
<!-- ========= END OF CLASS DATA ========= -->
<HR>
<!-- ======= START OF BOTTOM NAVBAR ====== -->
<A NAME="navbar_bottom"><!-- --></A>
<A HREF="#skip-navbar_bottom" title="Skip navigation links"></A>
<TABLE BORDER="0" WIDTH="100%" CELLPADDING="1" CELLSPACING="0" SUMMARY="">
<TR>
<TD COLSPAN=2 BGCOLOR="#EEEEFF" CLASS="NavBarCell1">
<A NAME="navbar_bottom_firstrow"><!-- --></A>
<TABLE BORDER="0" CELLPADDING="0" CELLSPACING="3" SUMMARY="">
<TR ALIGN="center" VALIGN="top">
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../overview-summary.html"><FONT CLASS="NavBarFont1"><B>Overview</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-summary.html"><FONT CLASS="NavBarFont1"><B>Package</B></FONT></A> </TD>
<TD BGCOLOR="#FFFFFF" CLASS="NavBarCell1Rev"> <FONT CLASS="NavBarFont1Rev"><B>Class</B></FONT> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="class-use/HtmlPolicyBuilder.html"><FONT CLASS="NavBarFont1"><B>Use</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="package-tree.html"><FONT CLASS="NavBarFont1"><B>Tree</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../deprecated-list.html"><FONT CLASS="NavBarFont1"><B>Deprecated</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../index-all.html"><FONT CLASS="NavBarFont1"><B>Index</B></FONT></A> </TD>
<TD BGCOLOR="#EEEEFF" CLASS="NavBarCell1"> <A HREF="../../../help-doc.html"><FONT CLASS="NavBarFont1"><B>Help</B></FONT></A> </TD>
</TR>
</TABLE>
</TD>
<TD ALIGN="right" VALIGN="top" ROWSPAN=3><EM>
</EM>
</TD>
</TR>
<TR>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../org/owasp/html/Handler.html" title="interface in org.owasp.html"><B>PREV CLASS</B></A>
<A HREF="../../../org/owasp/html/HtmlPolicyBuilder.AttributeBuilder.html" title="class in org.owasp.html"><B>NEXT CLASS</B></A></FONT></TD>
<TD BGCOLOR="white" CLASS="NavBarCell2"><FONT SIZE="-2">
<A HREF="../../../index.html?org/owasp/html/HtmlPolicyBuilder.html" target="_top"><B>FRAMES</B></A>
<A HREF="HtmlPolicyBuilder.html" target="_top"><B>NO FRAMES</B></A>
<SCRIPT type="text/javascript">
<!--
if(window==top) {
document.writeln('<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>');
}
//-->
</SCRIPT>
<NOSCRIPT>
<A HREF="../../../allclasses-noframe.html"><B>All Classes</B></A>
</NOSCRIPT>
</FONT></TD>
</TR>
<TR>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
SUMMARY: <A HREF="#nested_class_summary">NESTED</A> | <A HREF="#field_summary">FIELD</A> | <A HREF="#constructor_summary">CONSTR</A> | <A HREF="#method_summary">METHOD</A></FONT></TD>
<TD VALIGN="top" CLASS="NavBarCell3"><FONT SIZE="-2">
DETAIL: <A HREF="#field_detail">FIELD</A> | <A HREF="#constructor_detail">CONSTR</A> | <A HREF="#method_detail">METHOD</A></FONT></TD>
</TR>
</TABLE>
<A NAME="skip-navbar_bottom"></A>
<!-- ======== END OF BOTTOM NAVBAR ======= -->
<HR>
Copyright © 2012 <a href="http://www.owasp.org/">OWASP</a>. All Rights Reserved.
</BODY>
</HTML>
|