├── .github └── workflows │ └── build.yaml ├── .gitignore ├── .java-version ├── LICENSE ├── META-INF └── MANIFEST.MF ├── README.md ├── core ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── encoder │ │ │ ├── ASCIIBits.java │ │ │ ├── CDATAEncoder.java │ │ │ ├── CSSEncoder.java │ │ │ ├── ChainedEncoder.java │ │ │ ├── Encode.java │ │ │ ├── EncodedWriter.java │ │ │ ├── Encoder.java │ │ │ ├── Encoders.java │ │ │ ├── HTMLEncoder.java │ │ │ ├── JavaEncoder.java │ │ │ ├── JavaScriptEncoder.java │ │ │ ├── URIEncoder.java │ │ │ ├── Unicode.java │ │ │ ├── UnsupportedContextException.java │ │ │ ├── XMLCommentEncoder.java │ │ │ └── XMLEncoder.java │ ├── java9 │ │ └── module-info.java │ └── resources │ │ └── META-INF │ │ └── LICENSE │ ├── site │ ├── markdown │ │ └── index.md │ └── site.xml │ └── test │ ├── java │ └── org │ │ └── owasp │ │ └── encoder │ │ ├── BenchmarkTest.java │ │ ├── CDATAEncoderTest.java │ │ ├── CSSEncoderTest.java │ │ ├── ChainedEncoderTest.java │ │ ├── EncodeTest.java │ │ ├── EncoderTestSuiteBuilder.java │ │ ├── EncodersTest.java │ │ ├── HTMLEncoderTest.java │ │ ├── JavaEncoderTest.java │ │ ├── JavaScriptEncoderTest.java │ │ ├── URIEncoderTest.java │ │ ├── XMLCommentEncoderTest.java │ │ └── XMLEncoderTest.java │ └── resources │ └── org │ └── owasp │ └── encoder │ ├── benchmark-data-1.txt │ └── benchmark-data-2.txt ├── esapi ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── encoder │ │ │ └── esapi │ │ │ └── ESAPIEncoder.java │ ├── java9 │ │ └── module-info.java │ └── resources │ │ └── META-INF │ │ └── LICENSE │ ├── site │ └── site.xml │ └── test │ ├── java │ └── org │ │ └── owasp │ │ └── encoder │ │ └── esapi │ │ └── ESAPIEncoderTest.java │ └── resources │ └── .esapi │ └── ESAPI.properties ├── jakarta-test ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── encoder │ │ │ └── testing │ │ │ └── jakarta_test │ │ │ ├── JakartaTestApplication.java │ │ │ ├── controller │ │ │ ├── HomeController.java │ │ │ └── ItemController.java │ │ │ ├── dto │ │ │ └── Item.java │ │ │ └── service │ │ │ ├── ItemService.java │ │ │ └── impl │ │ │ └── ItemServiceImpl.java │ ├── resources │ │ ├── application.properties │ │ └── static │ │ │ ├── css │ │ │ └── common.css │ │ │ └── error │ │ │ └── 4xx.html │ └── webapp │ │ └── WEB-INF │ │ └── jsp │ │ ├── index.jsp │ │ └── view-items.jsp │ └── test │ └── java │ └── org │ └── owasp │ └── encoder │ └── testing │ └── jakarta_test │ ├── ItemControllerTest.java │ ├── JakartaTestApplicationTests.java │ ├── TestJakartaTestApplication.java │ └── TestcontainersConfiguration.java ├── jakarta ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── encoder │ │ │ └── tag │ │ │ ├── EncodingTag.java │ │ │ ├── ForCDATATag.java │ │ │ ├── ForCssStringTag.java │ │ │ ├── ForCssUrlTag.java │ │ │ ├── ForHtmlAttributeTag.java │ │ │ ├── ForHtmlContentTag.java │ │ │ ├── ForHtmlTag.java │ │ │ ├── ForHtmlUnquotedAttributeTag.java │ │ │ ├── ForJavaScriptAttributeTag.java │ │ │ ├── ForJavaScriptBlockTag.java │ │ │ ├── ForJavaScriptSourceTag.java │ │ │ ├── ForJavaScriptTag.java │ │ │ ├── ForUriComponentTag.java │ │ │ ├── ForUriTag.java │ │ │ ├── ForXmlAttributeTag.java │ │ │ ├── ForXmlCommentTag.java │ │ │ ├── ForXmlContentTag.java │ │ │ └── ForXmlTag.java │ ├── java9 │ │ └── module-info.java │ └── resources │ │ └── META-INF │ │ ├── LICENSE │ │ ├── java-encoder-advanced.tld │ │ └── java-encoder.tld │ ├── site │ ├── markdown │ │ └── index.md │ └── site.xml │ └── test │ └── java │ └── org │ └── owasp │ └── encoder │ └── tag │ ├── EncodingTagTest.java │ ├── ForCDATATagTest.java │ ├── ForCssStringTagTest.java │ ├── ForCssUrlTagTest.java │ ├── ForHtmlAttributeTagTest.java │ ├── ForHtmlContentTagTest.java │ ├── ForHtmlTagTest.java │ ├── ForHtmlUnquotedAttributeTagTest.java │ ├── ForJavaScriptAttributeTagTest.java │ ├── ForJavaScriptBlockTagTest.java │ ├── ForJavaScriptSourceTagTest.java │ ├── ForJavaScriptTagTest.java │ ├── ForUriComponentTagTest.java │ ├── ForUriTagTest.java │ ├── ForXmlAttributeTagTest.java │ ├── ForXmlCommentTagTest.java │ ├── ForXmlContentTagTest.java │ └── ForXmlTagTest.java ├── jsp ├── pom.xml └── src │ ├── main │ ├── java │ │ └── org │ │ │ └── owasp │ │ │ └── encoder │ │ │ └── tag │ │ │ ├── EncodingTag.java │ │ │ ├── ForCDATATag.java │ │ │ ├── ForCssStringTag.java │ │ │ ├── ForCssUrlTag.java │ │ │ ├── ForHtmlAttributeTag.java │ │ │ ├── ForHtmlContentTag.java │ │ │ ├── ForHtmlTag.java │ │ │ ├── ForHtmlUnquotedAttributeTag.java │ │ │ ├── ForJavaScriptAttributeTag.java │ │ │ ├── ForJavaScriptBlockTag.java │ │ │ ├── ForJavaScriptSourceTag.java │ │ │ ├── ForJavaScriptTag.java │ │ │ ├── ForUriComponentTag.java │ │ │ ├── ForUriTag.java │ │ │ ├── ForXmlAttributeTag.java │ │ │ ├── ForXmlCommentTag.java │ │ │ ├── ForXmlContentTag.java │ │ │ └── ForXmlTag.java │ ├── java9 │ │ └── module-info.java │ └── resources │ │ └── META-INF │ │ ├── LICENSE │ │ ├── java-encoder-advanced.tld │ │ └── java-encoder.tld │ ├── site │ ├── markdown │ │ └── index.md │ └── site.xml │ └── test │ └── java │ └── org │ └── owasp │ └── encoder │ └── tag │ ├── EncodingTagTest.java │ ├── ForCDATATagTest.java │ ├── ForCssStringTagTest.java │ ├── ForCssUrlTagTest.java │ ├── ForHtmlAttributeTagTest.java │ ├── ForHtmlContentTagTest.java │ ├── ForHtmlTagTest.java │ ├── ForHtmlUnquotedAttributeTagTest.java │ ├── ForJavaScriptAttributeTagTest.java │ ├── ForJavaScriptBlockTagTest.java │ ├── ForJavaScriptSourceTagTest.java │ ├── ForJavaScriptTagTest.java │ ├── ForUriComponentTagTest.java │ ├── ForUriTagTest.java │ ├── ForXmlAttributeTagTest.java │ ├── ForXmlCommentTagTest.java │ ├── ForXmlContentTagTest.java │ └── ForXmlTagTest.java ├── pom.xml └── src ├── main └── config │ ├── checkstyle-header.txt │ └── checkstyle.xml └── site ├── markdown └── index.md ├── resources └── images │ └── owasp.jpg └── site.xml /.github/workflows/build.yaml: -------------------------------------------------------------------------------- 1 | name: Java CI 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | pull_request: 8 | 9 | permissions: 10 | contents: read 11 | 12 | jobs: 13 | build: 14 | runs-on: ubuntu-latest 15 | steps: 16 | - uses: actions/checkout@v4 17 | - name: Set up JDK 17 18 | uses: actions/setup-java@v4 19 | with: 20 | java-version: '17' 21 | distribution: 'temurin' 22 | - name: Run build 23 | run: | 24 | mvn -B install -PtestJakarta 25 | 26 | 27 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | */target/** 2 | /target/** 3 | # Intellij project files 4 | *.iml 5 | *.ipr 6 | *.iws 7 | .idea/ 8 | # Eclipse project files 9 | .classpath 10 | .project 11 | .settings 12 | maven-eclipse.xml 13 | .externalToolBuilders 14 | # Netbeans configuration 15 | nb-configuration.xml 16 | */nbproject/* 17 | 18 | /jsp/target/ 19 | /esapi/target/ 20 | /target/ 21 | /jakarta/target/ 22 | /jakarta-test/target/ 23 | -------------------------------------------------------------------------------- /.java-version: -------------------------------------------------------------------------------- 1 | 17.0 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Jeff Ichnowski 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials 15 | provided with the distribution. 16 | 17 | * Neither the name of the OWASP nor the names of its 18 | contributors may be used to endorse or promote products 19 | derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /META-INF/MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bnd-LastModified: 1533328833261 3 | Bundle-ManifestVersion: 2 4 | Bundle-Name: org.owasp.encoder 5 | Bundle-SymbolicName: org.owasp.encoder 6 | Bundle-Version: 1.2.1 7 | Created-By: 1.8.0_181 (Oracle Corporation) 8 | Export-Package: org.owasp.encoder 9 | Tool: Bnd-1.50.0 10 | -------------------------------------------------------------------------------- /core/src/main/java/org/owasp/encoder/UnsupportedContextException.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder; 36 | 37 | /** 38 | * UnsupportedContextException -- thrown when the encoding context 39 | * specified is not known or supported. 40 | * 41 | * @author Jeff Ichnowski 42 | */ 43 | public class UnsupportedContextException extends RuntimeException { 44 | /** 45 | * Sole constructor. 46 | * 47 | * @param msg the exception message--includes the name of the 48 | * unsupported context 49 | */ 50 | public UnsupportedContextException(String msg) { 51 | super(msg); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /core/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | module owasp.encoder { 2 | exports org.owasp.encoder; 3 | } 4 | -------------------------------------------------------------------------------- /core/src/main/resources/META-INF/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Jeff Ichnowski 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials 15 | provided with the distribution. 16 | 17 | * Neither the name of the OWASP nor the names of its 18 | contributors may be used to endorse or promote products 19 | derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /core/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | ## OWASP Java Encoder 2 | 3 | The OWASP Java Encoder is a collection of high-performance low-overhead 4 | contextual encoders that, when utilized correctly, is an effective tool in 5 | preventing Web Application security vulnerabilities such as Cross-Site 6 | Scripting (XSS). 7 | 8 | Please see the [OWASP XSS Prevention Cheat Sheet](https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet) 9 | for more information on preventing XSS. 10 | 11 | For use within JSP pages consider using the [JSP Encoder](../encoder-jsp/index.html) as it 12 | provides a TLD to make the use of the core encoders easier. 13 | 14 | ### Usage 15 | 16 | The JARs can be found in [Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.owasp.encoder%22). 17 | 18 | ```xml 19 | 20 | org.owasp.encoder 21 | encoder 22 | 1.2.3 23 | 24 | ``` 25 | 26 | Utilize the encoder: 27 | 28 | ```java 29 | import org.owasp.encoder.Encode; 30 | 31 | //... 32 | 33 | PrintWriter out = ....; 34 | out.println(""); 35 | ``` 36 | -------------------------------------------------------------------------------- /core/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /core/src/test/java/org/owasp/encoder/ChainedEncoderTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder; 36 | 37 | import junit.framework.Test; 38 | import junit.framework.TestCase; 39 | 40 | /** 41 | * ChainedEncoderTest -- Tests the ChainedEncoder for all code-points. 42 | * 43 | * @author Jeff Ichnowski 44 | */ 45 | public class ChainedEncoderTest extends TestCase { 46 | public static Test suite() { 47 | return new EncoderTestSuiteBuilder( 48 | new ChainedEncoder( 49 | new JavaScriptEncoder(JavaScriptEncoder.Mode.SOURCE, false), 50 | new XMLEncoder()), "-safe-", "-\\&-") 51 | 52 | // from JavaScriptEncoderTest 53 | .encode("\\\\", "\\") 54 | .encode("\\"", "\"") 55 | .encode("\\'", "\'") 56 | .encode("backspace", "\\b", "\b") 57 | .encode("tab", "\\t", "\t") 58 | .encode("LF", "\\n", "\n") 59 | .encode("vtab", "\\x0b", "\u000b") 60 | .encode("FF", "\\f", "\f") 61 | .encode("CR", "\\r", "\r") 62 | .encode("NUL", "\\x00", "\0") 63 | .encode("abc", "abc") 64 | .encode("ABC", "ABC") 65 | 66 | // from XMLEncoderTest 67 | .encode("&", "&") 68 | .encode(">", ">") 69 | .encode("<", "<") 70 | .build(); 71 | } 72 | } 73 | -------------------------------------------------------------------------------- /core/src/test/java/org/owasp/encoder/EncodersTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder; 36 | 37 | import junit.framework.Test; 38 | import junit.framework.TestCase; 39 | import junit.framework.TestSuite; 40 | 41 | import java.lang.reflect.Field; 42 | import java.lang.reflect.Modifier; 43 | 44 | /** 45 | * EncodersTest -- Tests for the Encoders class. 46 | * 47 | * @author Jeff Ichnowski 48 | */ 49 | public class EncodersTest extends TestCase { 50 | 51 | public static Test suite() throws Exception { 52 | return new TestSuite(EncodersTest.class); 53 | } 54 | 55 | public void testForNameIsNotNull() throws Exception { 56 | Field[] fields = Encoders.class.getFields(); 57 | int count = 0; 58 | for (Field field : fields) { 59 | if (Modifier.isPublic(field.getModifiers()) && 60 | Modifier.isStatic(field.getModifiers()) && 61 | Modifier.isFinal(field.getModifiers()) && 62 | field.getType() == String.class) 63 | { 64 | String contextName = (String) field.get(null); 65 | Encoder encoder = Encoders.forName(contextName); 66 | assertNotNull("Encoder: "+contextName, encoder); 67 | count++; 68 | } 69 | } 70 | 71 | assertTrue(count > 0); 72 | } 73 | } 74 | -------------------------------------------------------------------------------- /esapi/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 37 | 38 | 40 | 4.0.0 41 | 42 | 43 | org.owasp.encoder 44 | encoder-parent 45 | 1.3.1 46 | 47 | 48 | encoder-esapi 49 | jar 50 | 51 | ESAPI Thunk 52 | 53 | The OWASP Encoders ESAPI Thunk provides an easy way to plugin the Encoder 54 | Projects API into an implementation of ESAPI. 55 | 56 | 57 | 58 | org.owasp.encoder.esapi 59 | 60 | 61 | 62 | 63 | org.owasp.encoder 64 | encoder 65 | ${project.parent.version} 66 | 67 | 68 | org.owasp.esapi 69 | esapi 70 | [2.5.1.0,3) 71 | 72 | 73 | 74 | -------------------------------------------------------------------------------- /esapi/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | module owasp.encoder.esapi { 2 | requires owasp.encoder; 3 | 4 | exports org.owasp.encoder.esapi; 5 | } -------------------------------------------------------------------------------- /esapi/src/main/resources/META-INF/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Jeff Ichnowski 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials 15 | provided with the distribution. 16 | 17 | * Neither the name of the OWASP nor the names of its 18 | contributors may be used to endorse or promote products 19 | derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /esapi/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /esapi/src/test/java/org/owasp/encoder/esapi/ESAPIEncoderTest.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.esapi; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.ByteArrayOutputStream; 5 | import java.io.ObjectInputStream; 6 | import java.io.ObjectOutputStream; 7 | import junit.framework.Test; 8 | import junit.framework.TestCase; 9 | import junit.framework.TestSuite; 10 | import org.owasp.esapi.ESAPI; 11 | import org.owasp.esapi.Encoder; 12 | 13 | /** 14 | * ESAPIEncoderTest 15 | * 16 | * @author jeffi 17 | */ 18 | public class ESAPIEncoderTest extends TestCase { 19 | public static Test suite() { 20 | return new TestSuite(ESAPIEncoderTest.class); 21 | } 22 | 23 | public void testEncode() throws Exception { 24 | // Note: ESAPI reference encodes as: "<>&Ω" 25 | // That's 25 characters to OWASP Java Encoder's 14. 26 | assertEquals("<>&\u03a9", ESAPI.encoder().encodeForXML("<>&\u03a9")); 27 | } 28 | 29 | public void testSerialization() throws Exception { 30 | // Note: ESAPI reference implementation is NOT serializable. Maybe 31 | // it will be in the future. Our implementation is however 32 | // guaranteed serializable. 33 | 34 | Encoder encoder = ESAPI.encoder(); 35 | 36 | ByteArrayOutputStream baos = new ByteArrayOutputStream(); 37 | 38 | ObjectOutputStream oos = new ObjectOutputStream(baos); 39 | oos.writeObject(encoder); 40 | oos.close(); 41 | 42 | ObjectInputStream ois = new ObjectInputStream( 43 | new ByteArrayInputStream(baos.toByteArray())); 44 | 45 | Encoder deserializedEncoder = (Encoder)ois.readObject(); 46 | 47 | assertSame(encoder, deserializedEncoder); 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /esapi/src/test/resources/.esapi/ESAPI.properties: -------------------------------------------------------------------------------- 1 | # Properties based on ESAPI 2.2.1.1's configuration/esapi/ESAPI.properties file. 2 | 3 | ESAPI.Encoder=org.owasp.encoder.esapi.ESAPIEncoder 4 | 5 | # Log4JFactory Requires log4j.xml or log4j.properties in classpath - http://www.laliluna.de/log4j-tutorial.html 6 | # Note that this is now considered deprecated! 7 | #ESAPI.Logger=org.owasp.esapi.logging.log4j.Log4JLogFactory 8 | 9 | # To use JUL, you need to obtain ESAPI's esapi-java-logging.properties and drop 10 | # it somewhere into your class path. You can get it from the ESAPI configuration 11 | # jar. (See Release 2.2.1.1 under GitHub for ESAPI/esapi-java-legacy.) 12 | ESAPI.Logger=org.owasp.esapi.logging.java.JavaLogFactory 13 | 14 | # To use the new SLF4J logger in ESAPI (see GitHub issue #129), set 15 | #ESAPI.Logger=org.owasp.esapi.logging.slf4j.Slf4JLogFactory 16 | # and do whatever other normal SLF4J configuration that you normally would do for your application. 17 | 18 | # Note: The uncommented out ones are those needed for SLF4J. Others may be 19 | # needed if you change the ESAPI logger. 20 | #=========================================================================== 21 | # ESAPI Logging 22 | # Set the application name if these logs are combined with other applications 23 | Logger.ApplicationName=ESAPI-Shim-Test 24 | # If you use an HTML log viewer that does not properly HTML escape log data, you can set LogEncodingRequired to true 25 | Logger.LogEncodingRequired=false 26 | # Determines whether ESAPI should log the application name. This might be clutter in some single-server/single-app environments. 27 | Logger.LogApplicationName=true 28 | # Determines whether ESAPI should log the server IP and port. This might be clutter in some single-server environments. 29 | Logger.LogServerIP=false 30 | # LogFileName, the name of the logging file. Provide a full directory path (e.g., C:\\ESAPI\\ESAPI_logging_file) if you 31 | # want to place it in a specific directory. 32 | #Logger.LogFileName=ESAPI_logging_file 33 | # MaxLogFileSize, the max size (in bytes) of a single log file before it cuts over to a new one (default is 10,000,000) 34 | #Logger.MaxLogFileSize=10000000 35 | # Determines whether ESAPI should log the user info. 36 | Logger.UserInfo=false 37 | # Determines whether ESAPI should log the session id and client IP 38 | Logger.ClientInfo=false 39 | -------------------------------------------------------------------------------- /jakarta-test/src/main/java/org/owasp/encoder/testing/jakarta_test/JakartaTestApplication.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | import org.springframework.boot.autoconfigure.SpringBootApplication; 5 | import org.springframework.boot.builder.SpringApplicationBuilder; 6 | import org.springframework.boot.web.servlet.support.SpringBootServletInitializer; 7 | 8 | @SpringBootApplication(scanBasePackages = "org.owasp.encoder.testing.jakarta_test") 9 | public class JakartaTestApplication extends SpringBootServletInitializer { 10 | 11 | @Override 12 | protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) { 13 | return builder.sources(JakartaTestApplication.class); 14 | } 15 | 16 | public static void main(String[] args) { 17 | SpringApplication.run(JakartaTestApplication.class, args); 18 | } 19 | 20 | } 21 | -------------------------------------------------------------------------------- /jakarta-test/src/main/java/org/owasp/encoder/testing/jakarta_test/controller/HomeController.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test.controller; 2 | 3 | import org.springframework.stereotype.Controller; 4 | import org.springframework.web.bind.annotation.GetMapping; 5 | import org.springframework.web.bind.annotation.RequestMapping; 6 | 7 | /** 8 | * 9 | * @author jeremy 10 | */ 11 | @Controller 12 | @RequestMapping("/") 13 | public class HomeController { 14 | 15 | @GetMapping("") 16 | public String index() { 17 | return "index"; 18 | } 19 | } -------------------------------------------------------------------------------- /jakarta-test/src/main/java/org/owasp/encoder/testing/jakarta_test/controller/ItemController.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test.controller; 2 | 3 | import org.owasp.encoder.testing.jakarta_test.service.ItemService; 4 | import org.springframework.stereotype.Controller; 5 | import org.springframework.ui.Model; 6 | import org.springframework.web.bind.annotation.GetMapping; 7 | import org.springframework.web.bind.annotation.RequestMapping; 8 | 9 | /** 10 | * 11 | * @author jeremy 12 | */ 13 | @Controller 14 | @RequestMapping("/item") 15 | public class ItemController { 16 | 17 | private final ItemService itemService; 18 | 19 | public ItemController(ItemService itemService) { 20 | this.itemService = itemService; 21 | } 22 | 23 | @GetMapping("/viewItems") 24 | public String viewItems(Model model) { 25 | model.addAttribute("items", itemService.getItems()); 26 | return "view-items"; 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /jakarta-test/src/main/java/org/owasp/encoder/testing/jakarta_test/dto/Item.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test.dto; 2 | 3 | /** 4 | * 5 | * @author jeremy 6 | */ 7 | public class Item { 8 | 9 | private int id; 10 | 11 | private String name; 12 | 13 | private String description; 14 | 15 | public Item() { 16 | } 17 | 18 | public Item(int id, String name, String description) { 19 | this.id = id; 20 | this.name = name; 21 | this.description = description; 22 | } 23 | 24 | /** 25 | * Get the value of id 26 | * 27 | * @return the value of id 28 | */ 29 | public int getId() { 30 | return id; 31 | } 32 | 33 | /** 34 | * Set the value of id 35 | * 36 | * @param id new value of id 37 | */ 38 | public void setId(int id) { 39 | this.id = id; 40 | } 41 | 42 | /** 43 | * Get the value of name 44 | * 45 | * @return the value of name 46 | */ 47 | public String getName() { 48 | return name; 49 | } 50 | 51 | /** 52 | * Set the value of name 53 | * 54 | * @param name new value of name 55 | */ 56 | public void setName(String name) { 57 | this.name = name; 58 | } 59 | 60 | /** 61 | * Get the value of description 62 | * 63 | * @return the value of description 64 | */ 65 | public String getDescription() { 66 | return description; 67 | } 68 | 69 | /** 70 | * Set the value of description 71 | * 72 | * @param description new value of description 73 | */ 74 | public void setDescription(String description) { 75 | this.description = description; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta-test/src/main/java/org/owasp/encoder/testing/jakarta_test/service/ItemService.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test.service; 2 | 3 | import java.util.Collection; 4 | import org.owasp.encoder.testing.jakarta_test.dto.Item; 5 | 6 | /** 7 | * 8 | * @author jeremy 9 | */ 10 | public interface ItemService { 11 | Collection getItems(); 12 | 13 | Item addItem(Item item); 14 | } 15 | -------------------------------------------------------------------------------- /jakarta-test/src/main/java/org/owasp/encoder/testing/jakarta_test/service/impl/ItemServiceImpl.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test.service.impl; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import org.owasp.encoder.testing.jakarta_test.dto.Item; 6 | import org.owasp.encoder.testing.jakarta_test.service.ItemService; 7 | import org.springframework.stereotype.Service; 8 | 9 | /** 10 | * 11 | * @author jeremy 12 | */ 13 | @Service 14 | public class ItemServiceImpl implements ItemService { 15 | 16 | @Override 17 | public Collection getItems() { 18 | Collection items = new ArrayList<>(); 19 | items.add(new Item(1, "menu", "blob")); 20 | items.add(new Item(2, "top", "fancy ")); 21 | return items; 22 | } 23 | 24 | @Override 25 | public Item addItem(Item item) { 26 | throw new UnsupportedOperationException("Not supported yet."); // Generated from nbfs://nbhost/SystemFileSystem/Templates/Classes/Code/GeneratedMethodBody 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /jakarta-test/src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | spring.application.name=jakarta-test 2 | server.servlet.context-path=/jakarta-test 3 | spring.mvc.view.prefix=/WEB-INF/jsp/ 4 | spring.mvc.view.suffix=.jsp 5 | -------------------------------------------------------------------------------- /jakarta-test/src/main/resources/static/css/common.css: -------------------------------------------------------------------------------- 1 | table { 2 | font-family: arial, sans-serif; 3 | border-collapse: collapse; 4 | } 5 | 6 | td, th { 7 | border: 1px solid #dddddd; 8 | text-align: left; 9 | padding: 8px; 10 | } -------------------------------------------------------------------------------- /jakarta-test/src/main/resources/static/error/4xx.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Error 6 | 7 | 8 | Apparently you don't know what you are looking for?

4xx Error Occurred 9 | 10 | 11 | -------------------------------------------------------------------------------- /jakarta-test/src/main/webapp/WEB-INF/jsp/index.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html" pageEncoding="UTF-8"%> 2 | 3 | 4 | 5 | 6 | OWASP Java Encoder Jakarta JSP Test 7 | 8 | 9 |

Hello World!

10 | You are likely looking for the test page located here. 11 | 12 | 13 | -------------------------------------------------------------------------------- /jakarta-test/src/main/webapp/WEB-INF/jsp/view-items.jsp: -------------------------------------------------------------------------------- 1 | <%@page contentType="text/html;charset=UTF-8" language="java"%> 2 | <%@taglib prefix="c" uri="jakarta.tags.core"%> 3 | <%@taglib prefix="e" uri="owasp.encoder.jakarta"%> 4 | 5 | 6 | View Items 7 | " rel="stylesheet" type="text/css"> 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 |
IDNameDescription
${item.id}${e:forHtml(item.description)}
28 | 29 | -------------------------------------------------------------------------------- /jakarta-test/src/test/java/org/owasp/encoder/testing/jakarta_test/ItemControllerTest.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test; 2 | 3 | import static org.junit.jupiter.api.Assertions.assertEquals; 4 | import static org.junit.jupiter.api.Assertions.assertNotNull; 5 | import org.junit.jupiter.api.BeforeAll; 6 | import org.junit.jupiter.api.Test; 7 | import org.openqa.selenium.By; 8 | import org.openqa.selenium.NoSuchElementException; 9 | import org.openqa.selenium.WebElement; 10 | import org.openqa.selenium.chrome.ChromeOptions; 11 | import org.openqa.selenium.remote.RemoteWebDriver; 12 | import org.springframework.beans.factory.annotation.Autowired; 13 | import org.springframework.boot.test.context.SpringBootTest; 14 | import org.springframework.boot.test.web.server.LocalServerPort; 15 | import org.springframework.core.env.Environment; 16 | import org.testcontainers.Testcontainers; 17 | import org.testcontainers.containers.BrowserWebDriverContainer; 18 | import org.testcontainers.junit.jupiter.Container; 19 | 20 | /** 21 | * 22 | * @author jeremy 23 | */ 24 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 25 | public class ItemControllerTest { 26 | 27 | @Container 28 | static BrowserWebDriverContainer container = new BrowserWebDriverContainer<>(). 29 | withCapabilities(new ChromeOptions()); 30 | 31 | @LocalServerPort 32 | private int port; 33 | 34 | @BeforeAll 35 | static void beforeAll(@Autowired Environment environment) { 36 | Testcontainers.exposeHostPorts(environment.getProperty("local.server.port", Integer.class)); 37 | container.start(); 38 | } 39 | 40 | @Test 41 | void shouldDisplayMessage() { 42 | RemoteWebDriver browser = new RemoteWebDriver(container.getSeleniumAddress(), new ChromeOptions()); 43 | browser.get("http://host.testcontainers.internal:" + port + "/jakarta-test/item/viewItems"); 44 | WebElement first = browser.findElement(By.id("b2")); 45 | WebElement second = browser.findElement(By.id("c2")); 46 | assertEquals("top", first.getText()); 47 | assertEquals("fancy ", second.getText()); 48 | //todo yes - there are much better ways to check for an exception in junit 49 | NoSuchElementException exception = null; 50 | try { 51 | first.findElement(By.tagName("script")); 52 | } catch (NoSuchElementException ex) { 53 | exception = ex; 54 | } 55 | assertNotNull(exception); 56 | 57 | exception = null; 58 | try { 59 | second.findElement(By.tagName("script")); 60 | } catch (NoSuchElementException ex) { 61 | exception = ex; 62 | } 63 | assertNotNull(exception); 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /jakarta-test/src/test/java/org/owasp/encoder/testing/jakarta_test/JakartaTestApplicationTests.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test; 2 | 3 | import org.junit.jupiter.api.Test; 4 | import org.springframework.boot.test.context.SpringBootTest; 5 | import org.springframework.context.annotation.Import; 6 | 7 | @Import(TestcontainersConfiguration.class) 8 | @SpringBootTest 9 | class JakartaTestApplicationTests { 10 | 11 | @Test 12 | void contextLoads() { 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /jakarta-test/src/test/java/org/owasp/encoder/testing/jakarta_test/TestJakartaTestApplication.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test; 2 | 3 | import org.springframework.boot.SpringApplication; 4 | 5 | public class TestJakartaTestApplication { 6 | 7 | public static void main(String[] args) { 8 | SpringApplication.from(JakartaTestApplication::main).with(TestcontainersConfiguration.class).run(args); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /jakarta-test/src/test/java/org/owasp/encoder/testing/jakarta_test/TestcontainersConfiguration.java: -------------------------------------------------------------------------------- 1 | package org.owasp.encoder.testing.jakarta_test; 2 | 3 | import org.springframework.boot.test.context.TestConfiguration; 4 | 5 | @TestConfiguration(proxyBeanMethods = false) 6 | class TestcontainersConfiguration { 7 | 8 | } 9 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/EncodingTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import jakarta.servlet.jsp.tagext.SimpleTagSupport; 38 | 39 | /** 40 | * The base class for the encoding tags within this package. 41 | * 42 | * @author Jeremy Long (jeremy.long@gmail.com) 43 | */ 44 | public abstract class EncodingTag extends SimpleTagSupport { 45 | /** 46 | * The value to be written out by the tag. 47 | */ 48 | protected String _value; 49 | /** 50 | * Sets the value to be written out by the tag. 51 | * @param value the value to be written out by the tag. 52 | */ 53 | public void setValue(String value) { 54 | this._value = value; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForCDATATag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform encoding sufficient to place into a CDATA block. 43 | * This wraps the {@link org.owasp.encoder.Encode#forCDATA(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForCDATATag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forCDATA(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForCssStringTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform CSS encoding for CSS strings. 43 | * This wraps the {@link org.owasp.encoder.Encode#forCssString(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForCssStringTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forCssString(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForCssUrlTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform CSS encoding for CSS URL contexts. 43 | * This wraps the {@link org.owasp.encoder.Encode#forCssUrl(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForCssUrlTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forCssUrl(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForHtmlAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML encoding for HTML text attributes. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtmlAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForHtmlContentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML encoding for text content. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtmlContent(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlContentTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtmlContent(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForHtmlTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtml(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtml(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForHtmlUnquotedAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML Attribute encoding for an unquoted attribute. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtmlUnquotedAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlUnquotedAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtmlUnquotedAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForJavaScriptAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript Attribute encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScriptAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScriptAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForJavaScriptBlockTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript Block encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScriptBlock(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptBlockTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScriptBlock(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForJavaScriptSourceTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript Source encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScriptSource(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptSourceTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScriptSource(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForJavaScriptTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScript(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScript(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForUriComponentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag that performs percent-encoding for a component of a URI, such as a query 43 | * parameter name or value, path, or query-string. 44 | * This wraps the {@link org.owasp.encoder.Encode#forUriComponent(java.lang.String)}. 45 | * 46 | * @author Jeremy Long (jeremy.long@gmail.com) 47 | */ 48 | public class ForUriComponentTag extends EncodingTag { 49 | @Override 50 | public void doTag() throws JspException, IOException { 51 | Encode.forUriComponent(getJspContext().getOut(), _value); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForUriTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform percent-encoding of a URL according to RFC 3986. 43 | * This wraps the {@link org.owasp.encoder.Encode#forUri(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForUriTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forUri(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForXmlAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Attribute Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXmlAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForXmlCommentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Comment Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlCommentTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXmlComment(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForXmlContentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Content Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlContentTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXmlContent(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java/org/owasp/encoder/tag/ForXmlTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import jakarta.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXml(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXml(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jakarta/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | module owasp.encoder.jakarta { 2 | requires owasp.encoder; 3 | 4 | exports org.owasp.encoder.tag; 5 | } -------------------------------------------------------------------------------- /jakarta/src/main/resources/META-INF/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Jeff Ichnowski 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials 15 | provided with the distribution. 16 | 17 | * Neither the name of the OWASP nor the names of its 18 | contributors may be used to endorse or promote products 19 | derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /jakarta/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | ## OWASP JSP 2 | 3 | The OWASP JSP Encoder is a collection of high-performance low-overhead 4 | contextual encoders that, when utilized correctly, is an effective tool in 5 | preventing Web Application security vulnerabilities such as Cross-Site 6 | Scripting (XSS). 7 | 8 | Please see the [OWASP XSS Prevention Cheat Sheet](https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet) 9 | for more information on preventing XSS. 10 | 11 | ### JSP Usage 12 | 13 | The JSP Encoder makes the use of the Java Encoder within JSP simple via a TLD that 14 | includes tags and a set of JSP EL functions: 15 | 16 | ```xml 17 | 18 | org.owasp.encoder 19 | encoder-jsp 20 | 1.2.3 21 | 22 | ``` 23 | 24 | ```JSP 25 | <%@taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" %> 26 | 27 | <%-- ... --%> 28 | 29 |

Dynamic data via EL: ${e:forHtml(param.value)}

30 |

Dynamic data via tag:

31 | ``` 32 | -------------------------------------------------------------------------------- /jakarta/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForCDATATagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForCDATATag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForCDATATagTest extends EncodingTagTest { 44 | 45 | public ForCDATATagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForCDATATag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForCDATATag instance = new ForCDATATag(); 69 | String value = "
]]>
"; 70 | String expected = "
]]]]>
"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForCssStringTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForCssStringTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForCssStringTagTest extends EncodingTagTest { 44 | 45 | public ForCssStringTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForCssStringTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForCssStringTag instance = new ForCssStringTag(); 69 | String value = "
"; 70 | String expected = "\\3c div\\3e"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForCssUrlTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForCssUrlTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForCssUrlTagTest extends EncodingTagTest { 44 | 45 | public ForCssUrlTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForCssUrlTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForCssUrlTag instance = new ForCssUrlTag(); 69 | String value = "\\';"; 70 | String expected = "\\5c\\27;"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected, results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForHtmlAttributeTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForHtmlAttributeTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForHtmlAttributeTagTest extends EncodingTagTest { 44 | 45 | public ForHtmlAttributeTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForHtmlAttributeTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForHtmlAttributeTag instance = new ForHtmlAttributeTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForHtmlContentTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForHtmlContentTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForHtmlContentTagTest extends EncodingTagTest { 44 | 45 | public ForHtmlContentTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForHtmlContentTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForHtmlContentTag instance = new ForHtmlContentTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForHtmlTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForHtmlTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForHtmlTagTest extends EncodingTagTest { 44 | 45 | public ForHtmlTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForHtmlTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForHtmlTag instance = new ForHtmlTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForJavaScriptBlockTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForJavaScriptBlockTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForJavaScriptBlockTagTest extends EncodingTagTest { 44 | 45 | public ForJavaScriptBlockTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForJavaScriptBlockTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForJavaScriptBlockTag instance = new ForJavaScriptBlockTag(); 69 | String value = "'\"\0"; 70 | String expected = "\\'\\\"\\x00"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForJavaScriptSourceTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForJavaScriptSourceTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForJavaScriptSourceTagTest extends EncodingTagTest { 44 | 45 | public ForJavaScriptSourceTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForJavaScriptSourceTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForJavaScriptSourceTag instance = new ForJavaScriptSourceTag(); 69 | String value = "\0'\""; 70 | String expected = "\\x00\\'\\\""; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForJavaScriptTagTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.owasp.encoder.tag; 6 | 7 | /** 8 | * Simple tests for the ForJavaScriptTag. 9 | * 10 | * @author Jeremy Long (jeremy.long@gmail.com) 11 | */ 12 | public class ForJavaScriptTagTest extends EncodingTagTest { 13 | 14 | public ForJavaScriptTagTest(String testName) { 15 | super(testName); 16 | } 17 | 18 | @Override 19 | protected void setUp() throws Exception { 20 | super.setUp(); 21 | } 22 | 23 | @Override 24 | protected void tearDown() throws Exception { 25 | super.tearDown(); 26 | } 27 | 28 | /** 29 | * Test of doTag method, of class ForJavaScriptTag. 30 | * This is a very simple test that doesn't fully 31 | * exercise/test the encoder - only that the 32 | * tag itself works. 33 | * @throws Exception is thrown if the tag fails. 34 | */ 35 | public void testDoTag() throws Exception { 36 | System.out.println("doTag"); 37 | ForJavaScriptTag instance = new ForJavaScriptTag(); 38 | String value = "\0'\""; 39 | String expected = "\\x00\\x27\\x22"; 40 | instance.setJspContext(_pageContext); 41 | instance.setValue(value); 42 | instance.doTag(); 43 | String results = _response.getContentAsString(); 44 | assertEquals(expected,results); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForUriComponentTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForUriComponentTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForUriComponentTagTest extends EncodingTagTest { 44 | 45 | public ForUriComponentTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForUriComponentTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForUriComponentTag instance = new ForUriComponentTag(); 69 | String value = "&=test"; 70 | String expected = "%26amp%3B%3Dtest"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForUriTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForUriTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForUriTagTest extends EncodingTagTest { 44 | 45 | public ForUriTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForUriTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForUriTag instance = new ForUriTag(); 69 | String value = "\\\""; 70 | String expected = "%5C%22"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForXmlAttributeTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForXmlAttributeTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForXmlAttributeTagTest extends EncodingTagTest { 44 | 45 | public ForXmlAttributeTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForXmlAttributeTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForXmlAttributeTag instance = new ForXmlAttributeTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForXmlContentTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForXmlContentTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForXmlContentTagTest extends EncodingTagTest { 44 | 45 | public ForXmlContentTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForXmlContentTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForXmlContentTag instance = new ForXmlContentTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jakarta/src/test/java/org/owasp/encoder/tag/ForXmlTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForXmlTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForXmlTagTest extends EncodingTagTest { 44 | 45 | public ForXmlTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForXmlTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForXmlTag instance = new ForXmlTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/EncodingTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import javax.servlet.jsp.tagext.SimpleTagSupport; 38 | 39 | /** 40 | * The base class for the encoding tags within this package. 41 | * 42 | * @author Jeremy Long (jeremy.long@gmail.com) 43 | */ 44 | public abstract class EncodingTag extends SimpleTagSupport { 45 | /** 46 | * The value to be written out by the tag. 47 | */ 48 | protected String _value; 49 | /** 50 | * Sets the value to be written out by the tag. 51 | * @param value the value to be written out by the tag. 52 | */ 53 | public void setValue(String value) { 54 | this._value = value; 55 | } 56 | 57 | } 58 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForCDATATag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform encoding sufficient to place into a CDATA block. 43 | * This wraps the {@link org.owasp.encoder.Encode#forCDATA(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForCDATATag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forCDATA(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForCssStringTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform CSS encoding for CSS strings. 43 | * This wraps the {@link org.owasp.encoder.Encode#forCssString(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForCssStringTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forCssString(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForCssUrlTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform CSS encoding for CSS URL contexts. 43 | * This wraps the {@link org.owasp.encoder.Encode#forCssUrl(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForCssUrlTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forCssUrl(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForHtmlAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML encoding for HTML text attributes. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtmlAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForHtmlContentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML encoding for text content. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtmlContent(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlContentTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtmlContent(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForHtmlTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtml(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtml(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForHtmlUnquotedAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform HTML Attribute encoding for an unquoted attribute. 43 | * This wraps the {@link org.owasp.encoder.Encode#forHtmlUnquotedAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForHtmlUnquotedAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forHtmlUnquotedAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForJavaScriptAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript Attribute encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScriptAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScriptAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForJavaScriptBlockTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript Block encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScriptBlock(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptBlockTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScriptBlock(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForJavaScriptSourceTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript Source encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScriptSource(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptSourceTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScriptSource(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForJavaScriptTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform JavaScript encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forJavaScript(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForJavaScriptTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forJavaScript(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForUriComponentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag that performs percent-encoding for a component of a URI, such as a query 43 | * parameter name or value, path, or query-string. 44 | * This wraps the {@link org.owasp.encoder.Encode#forUriComponent(java.lang.String)}. 45 | * 46 | * @author Jeremy Long (jeremy.long@gmail.com) 47 | */ 48 | public class ForUriComponentTag extends EncodingTag { 49 | @Override 50 | public void doTag() throws JspException, IOException { 51 | Encode.forUriComponent(getJspContext().getOut(), _value); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForUriTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform percent-encoding of a URL according to RFC 3986. 43 | * This wraps the {@link org.owasp.encoder.Encode#forUri(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForUriTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forUri(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForXmlAttributeTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Attribute Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlAttributeTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXmlAttribute(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForXmlCommentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Comment Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlCommentTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXmlComment(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForXmlContentTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Content Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXmlAttribute(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlContentTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXmlContent(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java/org/owasp/encoder/tag/ForXmlTag.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | package org.owasp.encoder.tag; 36 | 37 | import java.io.IOException; 38 | import javax.servlet.jsp.JspException; 39 | import org.owasp.encoder.Encode; 40 | 41 | /** 42 | * A tag to perform XML Encoding. 43 | * This wraps the {@link org.owasp.encoder.Encode#forXml(java.lang.String)}. 44 | * 45 | * @author Jeremy Long (jeremy.long@gmail.com) 46 | */ 47 | public class ForXmlTag extends EncodingTag { 48 | @Override 49 | public void doTag() throws JspException, IOException { 50 | Encode.forXml(getJspContext().getOut(), _value); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /jsp/src/main/java9/module-info.java: -------------------------------------------------------------------------------- 1 | module owasp.encoder.jsp { 2 | requires owasp.encoder; 3 | 4 | exports org.owasp.encoder.tag; 5 | } -------------------------------------------------------------------------------- /jsp/src/main/resources/META-INF/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2015 Jeff Ichnowski 2 | All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions 6 | are met: 7 | 8 | * Redistributions of source code must retain the above 9 | copyright notice, this list of conditions and the following 10 | disclaimer. 11 | 12 | * Redistributions in binary form must reproduce the above 13 | copyright notice, this list of conditions and the following 14 | disclaimer in the documentation and/or other materials 15 | provided with the distribution. 16 | 17 | * Neither the name of the OWASP nor the names of its 18 | contributors may be used to endorse or promote products 19 | derived from this software without specific prior written 20 | permission. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | OF THE POSSIBILITY OF SUCH DAMAGE. -------------------------------------------------------------------------------- /jsp/src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | ## OWASP JSP 2 | 3 | The OWASP JSP Encoder is a collection of high-performance low-overhead 4 | contextual encoders that, when utilized correctly, is an effective tool in 5 | preventing Web Application security vulnerabilities such as Cross-Site 6 | Scripting (XSS). 7 | 8 | Please see the [OWASP XSS Prevention Cheat Sheet](https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet) 9 | for more information on preventing XSS. 10 | 11 | ### JSP Usage 12 | 13 | The JSP Encoder makes the use of the Java Encoder within JSP simple via a TLD that 14 | includes tags and a set of JSP EL functions: 15 | 16 | ```xml 17 | 18 | org.owasp.encoder 19 | encoder-jsp 20 | 1.2.3 21 | 22 | ``` 23 | 24 | ```JSP 25 | <%@taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" %> 26 | 27 | <%-- ... --%> 28 | 29 |

Dynamic data via EL: ${e:forHtml(param.value)}

30 |

Dynamic data via tag:

31 | ``` 32 | -------------------------------------------------------------------------------- /jsp/src/site/site.xml: -------------------------------------------------------------------------------- 1 | 2 | 38 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForCDATATagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForCDATATag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForCDATATagTest extends EncodingTagTest { 44 | 45 | public ForCDATATagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForCDATATag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForCDATATag instance = new ForCDATATag(); 69 | String value = "
]]>
"; 70 | String expected = "
]]]]>
"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForCssStringTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForCssStringTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForCssStringTagTest extends EncodingTagTest { 44 | 45 | public ForCssStringTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForCssStringTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForCssStringTag instance = new ForCssStringTag(); 69 | String value = "
"; 70 | String expected = "\\3c div\\3e"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForCssUrlTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForCssUrlTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForCssUrlTagTest extends EncodingTagTest { 44 | 45 | public ForCssUrlTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForCssUrlTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForCssUrlTag instance = new ForCssUrlTag(); 69 | String value = "\\';"; 70 | String expected = "\\5c\\27;"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected, results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForHtmlAttributeTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForHtmlAttributeTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForHtmlAttributeTagTest extends EncodingTagTest { 44 | 45 | public ForHtmlAttributeTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForHtmlAttributeTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForHtmlAttributeTag instance = new ForHtmlAttributeTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForHtmlContentTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForHtmlContentTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForHtmlContentTagTest extends EncodingTagTest { 44 | 45 | public ForHtmlContentTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForHtmlContentTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForHtmlContentTag instance = new ForHtmlContentTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForHtmlTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForHtmlTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForHtmlTagTest extends EncodingTagTest { 44 | 45 | public ForHtmlTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForHtmlTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForHtmlTag instance = new ForHtmlTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForJavaScriptBlockTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForJavaScriptBlockTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForJavaScriptBlockTagTest extends EncodingTagTest { 44 | 45 | public ForJavaScriptBlockTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForJavaScriptBlockTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForJavaScriptBlockTag instance = new ForJavaScriptBlockTag(); 69 | String value = "'\"\0"; 70 | String expected = "\\'\\\"\\x00"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForJavaScriptSourceTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForJavaScriptSourceTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForJavaScriptSourceTagTest extends EncodingTagTest { 44 | 45 | public ForJavaScriptSourceTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForJavaScriptSourceTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForJavaScriptSourceTag instance = new ForJavaScriptSourceTag(); 69 | String value = "\0'\""; 70 | String expected = "\\x00\\'\\\""; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForJavaScriptTagTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * To change this template, choose Tools | Templates 3 | * and open the template in the editor. 4 | */ 5 | package org.owasp.encoder.tag; 6 | 7 | /** 8 | * Simple tests for the ForJavaScriptTag. 9 | * 10 | * @author Jeremy Long (jeremy.long@gmail.com) 11 | */ 12 | public class ForJavaScriptTagTest extends EncodingTagTest { 13 | 14 | public ForJavaScriptTagTest(String testName) { 15 | super(testName); 16 | } 17 | 18 | @Override 19 | protected void setUp() throws Exception { 20 | super.setUp(); 21 | } 22 | 23 | @Override 24 | protected void tearDown() throws Exception { 25 | super.tearDown(); 26 | } 27 | 28 | /** 29 | * Test of doTag method, of class ForJavaScriptTag. 30 | * This is a very simple test that doesn't fully 31 | * exercise/test the encoder - only that the 32 | * tag itself works. 33 | * @throws Exception is thrown if the tag fails. 34 | */ 35 | public void testDoTag() throws Exception { 36 | System.out.println("doTag"); 37 | ForJavaScriptTag instance = new ForJavaScriptTag(); 38 | String value = "\0'\""; 39 | String expected = "\\x00\\x27\\x22"; 40 | instance.setJspContext(_pageContext); 41 | instance.setValue(value); 42 | instance.doTag(); 43 | String results = _response.getContentAsString(); 44 | assertEquals(expected,results); 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForUriComponentTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForUriComponentTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForUriComponentTagTest extends EncodingTagTest { 44 | 45 | public ForUriComponentTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForUriComponentTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForUriComponentTag instance = new ForUriComponentTag(); 69 | String value = "&=test"; 70 | String expected = "%26amp%3B%3Dtest"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForUriTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForUriTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForUriTagTest extends EncodingTagTest { 44 | 45 | public ForUriTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForUriTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForUriTag instance = new ForUriTag(); 69 | String value = "\\\""; 70 | String expected = "%5C%22"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForXmlAttributeTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForXmlAttributeTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForXmlAttributeTagTest extends EncodingTagTest { 44 | 45 | public ForXmlAttributeTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForXmlAttributeTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForXmlAttributeTag instance = new ForXmlAttributeTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForXmlContentTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForXmlContentTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForXmlContentTagTest extends EncodingTagTest { 44 | 45 | public ForXmlContentTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForXmlContentTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForXmlContentTag instance = new ForXmlContentTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /jsp/src/test/java/org/owasp/encoder/tag/ForXmlTagTest.java: -------------------------------------------------------------------------------- 1 | // Copyright (c) 2012 Jeff Ichnowski 2 | // All rights reserved. 3 | // 4 | // Redistribution and use in source and binary forms, with or without 5 | // modification, are permitted provided that the following conditions 6 | // are met: 7 | // 8 | // * Redistributions of source code must retain the above 9 | // copyright notice, this list of conditions and the following 10 | // disclaimer. 11 | // 12 | // * Redistributions in binary form must reproduce the above 13 | // copyright notice, this list of conditions and the following 14 | // disclaimer in the documentation and/or other materials 15 | // provided with the distribution. 16 | // 17 | // * Neither the name of the OWASP nor the names of its 18 | // contributors may be used to endorse or promote products 19 | // derived from this software without specific prior written 20 | // permission. 21 | // 22 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 24 | // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 25 | // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 26 | // COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 27 | // INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 28 | // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 29 | // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 31 | // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 32 | // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 33 | // OF THE POSSIBILITY OF SUCH DAMAGE. 34 | 35 | 36 | package org.owasp.encoder.tag; 37 | 38 | /** 39 | * Simple tests for the ForXmlTag. 40 | * 41 | * @author Jeremy Long (jeremy.long@gmail.com) 42 | */ 43 | public class ForXmlTagTest extends EncodingTagTest { 44 | 45 | public ForXmlTagTest(String testName) { 46 | super(testName); 47 | } 48 | 49 | @Override 50 | protected void setUp() throws Exception { 51 | super.setUp(); 52 | } 53 | 54 | @Override 55 | protected void tearDown() throws Exception { 56 | super.tearDown(); 57 | } 58 | 59 | /** 60 | * Test of doTag method, of class ForXmlTag. 61 | * This is a very simple test that doesn't fully 62 | * exercise/test the encoder - only that the 63 | * tag itself works. 64 | * @throws Exception is thrown if the tag fails. 65 | */ 66 | public void testDoTag() throws Exception { 67 | System.out.println("doTag"); 68 | ForXmlTag instance = new ForXmlTag(); 69 | String value = "
"; 70 | String expected = "<div>"; 71 | instance.setJspContext(_pageContext); 72 | instance.setValue(value); 73 | instance.doTag(); 74 | String results = _response.getContentAsString(); 75 | assertEquals(expected,results); 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /src/main/config/checkstyle-header.txt: -------------------------------------------------------------------------------- 1 | ^// Copyright \(c\) 201[2-9] (Jeff Ichnowski|Jim Manico|Jeremy Long)\s*$ 2 | ^// All rights reserved\.\s*$ 3 | ^// 4 | ^// Redistribution and use in source and binary forms, with or without\s*$ 5 | ^// modification, are permitted provided that the following conditions\s*$ 6 | ^// are met:\s*$ 7 | ^//\s*$ 8 | ^// \* Redistributions of source code must retain the above\s*$ 9 | ^// copyright notice, this list of conditions and the following\s*$ 10 | ^// disclaimer\.\s*$ 11 | ^// 12 | ^// \* Redistributions in binary form must reproduce the above\s*$ 13 | ^// copyright notice, this list of conditions and the following\s*$ 14 | ^// disclaimer in the documentation and/or other materials\s*$ 15 | ^// provided with the distribution.\s*$ 16 | ^// 17 | ^// \* Neither the name of the OWASP nor the names of its\s*$ 18 | ^// contributors may be used to endorse or promote products\s*$ 19 | ^// derived from this software without specific prior written\s*$ 20 | ^// permission\.\s*$ 21 | ^// 22 | ^// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\s*$ 23 | ^// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\s*$ 24 | ^// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS\s*$ 25 | ^// FOR A PARTICULAR PURPOSE ARE DISCLAIMED\. IN NO EVENT SHALL THE\s*$ 26 | ^// COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,\s*$ 27 | ^// INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES\s*$ 28 | ^// \(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR\s*$ 29 | ^// SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION\)\s*$ 30 | ^// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,\s*$ 31 | ^// STRICT LIABILITY, OR TORT \(INCLUDING NEGLIGENCE OR OTHERWISE\)\s*$ 32 | ^// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED\s*$ 33 | ^// OF THE POSSIBILITY OF SUCH DAMAGE\.\s*$ 34 | -------------------------------------------------------------------------------- /src/site/markdown/index.md: -------------------------------------------------------------------------------- 1 | ## OWASP Java Encoder Project 2 | 3 | The OWASP Java Encoder Project is a collection of high-performance low-overhead 4 | contextual encoders, that when utilized correctly, is an effective tool in 5 | preventing Web Application security vulnerabilities such as Cross-Site 6 | Scripting (XSS). 7 | 8 | Please see the [OWASP XSS Prevention Cheat Sheet](https://www.owasp.org/index.php/XSS_%28Cross_Site_Scripting%29_Prevention_Cheat_Sheet) 9 | for more information on preventing XSS. 10 | 11 | ### Usage 12 | 13 | In addition to the usage guidance below, more examples can be found on the [OWASP Java Encoder Project Wiki](https://www.owasp.org/index.php/OWASP_Java_Encoder_Project#tab=Use_the_Java_Encoder_Project). 14 | 15 | The JARs can be found in [Maven Central](https://search.maven.org/#search%7Cga%7C1%7Cg%3A%22org.owasp.encoder%22). 16 | 17 | ```xml 18 | 19 | org.owasp.encoder 20 | encoder 21 | 1.2.3 22 | 23 | ``` 24 | 25 | Utilize the encoder: 26 | 27 | ```java 28 | import org.owasp.encoder.Encode; 29 | 30 | //... 31 | 32 | PrintWriter out = ....; 33 | out.println(""); 34 | ``` 35 | 36 | ### JSP Usage 37 | 38 | The JSP Encoder makes the use of the Java Encoder within JSP simple via a TLD that 39 | includes tags and a set of JSP EL functions: 40 | 41 | ```xml 42 | 43 | org.owasp.encoder 44 | encoder-jsp 45 | 1.2.3 46 | 47 | ``` 48 | 49 | ```JSP 50 | <%@taglib prefix="e" uri="https://www.owasp.org/index.php/OWASP_Java_Encoder_Project" %> 51 | 52 | <%-- ... --%> 53 | 54 |

Dynamic data via EL: ${e:forHtml(param.value)}

55 |

Dynamic data via tag:

56 | ``` 57 | -------------------------------------------------------------------------------- /src/site/resources/images/owasp.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OWASP/owasp-java-encoder/9645e8dad1c436dae98382a28549ff8d745ae3c0/src/site/resources/images/owasp.jpg -------------------------------------------------------------------------------- /src/site/site.xml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/OWASP/owasp-java-encoder/9645e8dad1c436dae98382a28549ff8d745ae3c0/src/site/site.xml --------------------------------------------------------------------------------