-
Notifications
You must be signed in to change notification settings - Fork 364
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* Updated DefaultEncoder.getCanonicalizedURI(URI) javadoc to indicate that the method takes into consideration canonicalization of mixed/multi encoded URLs as specified in ESAPI.props 'allowMixed' and 'allowMultiple' accordingly. * Per issue #824. Updated DefaultEncoder.getCanonicalizedURI(URI) javadoc to indicate that the method takes into consideration canonicalization of mixed/multi encoded URLs as specified in ESAPI.props 'allowMixed' and 'allowMultiple' accordingly. * Fixed #824 by nesting the original canonicalize call into the else block of the check to see whether or not we were dealing with a query segment.
- Loading branch information
Showing
4 changed files
with
122 additions
and
20 deletions.
There are no files selected for viewing
2 changes: 1 addition & 1 deletion
2
src/main/java/org/owasp/esapi/codecs/LegacyHTMLEntityCodec.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,25 +15,21 @@ | |
*/ | ||
package org.owasp.esapi.reference; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
import static org.junit.Assert.assertNotEquals; | ||
|
||
import java.io.IOException; | ||
import java.io.UnsupportedEncodingException; | ||
import java.net.URI; | ||
import java.util.List; | ||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.Map.Entry; | ||
import java.util.regex.Matcher; | ||
import java.util.regex.Pattern; | ||
import java.util.List; | ||
|
||
import org.junit.Ignore; | ||
import org.owasp.esapi.ESAPI; | ||
import org.owasp.esapi.Encoder; | ||
import org.owasp.esapi.EncoderConstants; | ||
import org.owasp.esapi.codecs.CSSCodec; | ||
import org.owasp.esapi.SecurityConfiguration; | ||
import org.owasp.esapi.SecurityConfigurationWrapper; | ||
import org.owasp.esapi.codecs.Codec; | ||
import org.owasp.esapi.codecs.HTMLEntityCodec; | ||
import org.owasp.esapi.codecs.MySQLCodec; | ||
|
@@ -45,8 +41,7 @@ | |
import org.owasp.esapi.errors.EncodingException; | ||
import org.owasp.esapi.errors.IntrusionException; | ||
import org.owasp.esapi.Randomizer; | ||
import org.owasp.esapi.SecurityConfiguration; | ||
import org.owasp.esapi.SecurityConfigurationWrapper; | ||
|
||
|
||
import junit.framework.Test; | ||
import junit.framework.TestCase; | ||
|
@@ -747,6 +742,7 @@ public void testDecodeFromURL() throws Exception { | |
fail(); | ||
} | ||
try { | ||
//FIXME: Rewrite this to use expected Exceptions. | ||
instance.decodeFromURL( "%3xridiculous" ); | ||
fail(); | ||
} catch( Exception e ) { | ||
|
@@ -985,6 +981,50 @@ public void testGetCanonicalizedUri() throws Exception { | |
assertEquals(expectedUri, e.getCanonicalizedURI(uri)); | ||
|
||
} | ||
|
||
public void testGetCanonicalizedUriWithAnHTMLEntityCollision() throws Exception { | ||
System.out.println("GetCanonicalizedUriWithAnHTMLEntityCollision"); | ||
Encoder e = ESAPI.encoder(); | ||
|
||
String expectedUri = "http://[email protected]/path_to/resource?foo=bar¶1=test"; | ||
//Please note that section 3.2.1 of RFC-3986 explicitly states not to encode | ||
//password information as in http://palpatine:[email protected], and this will | ||
//not appear in the userinfo field. | ||
String input = "http://[email protected]/path_to/resource?foo=bar¶1=test"; | ||
URI uri = new URI(input); | ||
System.out.println(uri.toString()); | ||
assertEquals(expectedUri, e.getCanonicalizedURI(uri)); | ||
|
||
} | ||
|
||
@org.junit.Ignore("Pre-check in unit test for issue #826") | ||
public void Issue826GetCanonicalizedUriWithMultipleEncoding() throws Exception { | ||
System.out.println("GetCanonicalizedUriWithAnHTMLEntityCollision"); | ||
Encoder e = ESAPI.encoder(); | ||
String expectedUri = "http://[email protected]/path_to/resource?foo=bar¶1=&test"; | ||
//Please note that section 3.2.1 of RFC-3986 explicitly states not to encode | ||
//password information as in http://palpatine:[email protected], and this will | ||
//not appear in the userinfo field. | ||
String input = "http://[email protected]/path_to/resource?foo=bar¶1=&test"; | ||
URI uri = new URI(input); | ||
System.out.println(uri.toString()); | ||
assertEquals(expectedUri, e.getCanonicalizedURI(uri)); | ||
|
||
} | ||
public void testGetCanonicalizedUriWithMultQueryParams() throws Exception { | ||
System.out.println("getCanonicalizedUri"); | ||
Encoder e = ESAPI.encoder(); | ||
|
||
String expectedUri = "http://palpatine@foo bar.com/path_to/resource?foo=bar&bar=foo#frag"; | ||
//Please note that section 3.2.1 of RFC-3986 explicitly states not to encode | ||
//password information as in http://palpatine:[email protected], and this will | ||
//not appear in the userinfo field. | ||
String input = "http://palpatine@foo%20bar.com/path_to/resource?foo=bar&bar=foo#frag"; | ||
URI uri = new URI(input); | ||
System.out.println(uri.toString()); | ||
assertEquals(expectedUri, e.getCanonicalizedURI(uri)); | ||
|
||
} | ||
|
||
public void testGetCanonicalizedUriPiazza() throws Exception { | ||
System.out.println("getCanonicalizedUriPiazza"); | ||
|
@@ -1000,6 +1040,41 @@ public void testGetCanonicalizedUriPiazza() throws Exception { | |
assertEquals(expectedUri, e.getCanonicalizedURI(uri)); | ||
|
||
} | ||
|
||
public void testIssue824() throws Exception { | ||
System.out.println("getCanonicalizedUriPiazza"); | ||
Encoder e = ESAPI.encoder(); | ||
|
||
String expectedUri = "/webapp/ux/home?d=1705914006565&status=login&ticket=1705914090394_HzJpTROVfhW-JhRW0OqDbHu7tWXXlgrKSUmOzIMsZNCcUIiYGMXX_Q==&newsess=false&roleid=DP010101/0007&origin=ourprogram"; | ||
//Please note that section 3.2.1 of RFC-3986 explicitly states not to encode | ||
//password information as in http://palpatine:[email protected], and this will | ||
//not appear in the userinfo field. | ||
String input = "/webapp/ux/home?d=1705914006565&status=login&ticket=1705914090394_HzJpTROVfhW-JhRW0OqDbHu7tWXXlgrKSUmOzIMsZNCcUIiYGMXX_Q%3D%3D&newsess=false&roleid=DP010101/0007&origin=ourprogram"; | ||
URI uri = new URI(input); | ||
System.out.println(uri.toString()); | ||
assertEquals(expectedUri, e.getCanonicalizedURI(uri)); | ||
|
||
} | ||
|
||
@org.junit.Ignore("Pre-check in unit test for issue #826") | ||
public void Issue826GetCanonicalizedDoubleAmpersand() throws Exception { | ||
System.out.println("getCanonicalizedDoubleAmpersand"); | ||
Encoder e = ESAPI.encoder(); | ||
String expectedUri = "http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft%2C&html=&contentLaunched"; | ||
//http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft,&html=null&=null&contentLaunched=null | ||
/* | ||
* In this case, the URI class should break up the HTML entity in the query so | ||
*/ | ||
String input = "http://127.0.0.1:3000/campaigns?goal=all§ion=active&sort-by=-id&status=Draft%2C&html=&&contentLaunched"; | ||
URI uri = new URI(input); | ||
System.out.println(uri.toString()); | ||
try { | ||
assertEquals(expectedUri, e.getCanonicalizedURI(uri)); | ||
fail(); | ||
} catch (Exception ex) { | ||
//Expected | ||
} | ||
} | ||
|
||
public void testGetCanonicalizedUriWithMailto() throws Exception { | ||
System.out.println("getCanonicalizedUriWithMailto"); | ||
|