Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
f8ac3fd
Signed key history for MATT SEIL begins here.
Apr 4, 2021
87c4c4e
Signed key history for MATT SEIL begins here. Fixed email typo.
Apr 4, 2021
8cd4ab2
Merge branch 'develop' of https://github.com/xeno6696/esapi-java-lega…
xeno6696 Apr 4, 2021
304ee3e
Revert "Signed key history for MATT SEIL begins here. Fixed email ty…
xeno6696 Apr 4, 2021
fe6ed91
Merging.
xeno6696 Apr 17, 2021
0fb6613
created file on main.
xeno6696 Apr 19, 2021
dc16afd
Deleted foo.txt
xeno6696 Apr 19, 2021
2e8694c
Bump release to new patch version #.
kwwall May 8, 2021
eebcc8f
Merged with upstream/develop
xeno6696 Dec 28, 2021
a3967b6
Merge remote-tracking branch 'upstream/develop' into develop
xeno6696 Jan 12, 2022
9fa2a53
#661 Added ability to generate OSGi metadata with the command 'mvn or…
xeno6696 Feb 23, 2022
1d92c37
Updated to AntiSamy 1.6.5.
xeno6696 Feb 25, 2022
c7e431e
Merge remote-tracking branch 'upstream/develop' into develop
xeno6696 Feb 25, 2022
ccf203b
Revert "#661 Added ability to generate OSGi metadata with the command…
xeno6696 Feb 25, 2022
9934557
Merge remote-tracking branch 'upstream/develop' into develop
xeno6696 Feb 25, 2022
d975a8a
#656 --> Parameterized cookie name length and value to correspond wi…
xeno6696 Feb 25, 2022
5246396
Adjusted regex to allow for zero-length matches.
xeno6696 Feb 25, 2022
f1a7169
Added per review comments for PR #663
xeno6696 Feb 26, 2022
78c6fb4
Merge remote-tracking branch 'upstream/develop' into develop
xeno6696 Feb 26, 2022
d859556
#656 Finished sweep looking for headername, headervalue, and header v…
xeno6696 Mar 19, 2022
30920c2
Merged with upstream.
xeno6696 Mar 19, 2022
f684e2a
#663 Fixed a missed unit test.
xeno6696 Mar 19, 2022
39d8a8a
Antisamy 1.6.6, Antisamy regression test for analysis 1. A handful o…
xeno6696 Apr 2, 2022
8db0fc1
Attempting to fix classfile differences with antisamy dependencies.
xeno6696 Apr 2, 2022
14c914d
Fixed typo on exclusion.
xeno6696 Apr 2, 2022
6bc6891
Added xerces exclusion to antisamy in the pom.xml
xeno6696 Apr 2, 2022
fd1a323
Added test cases 2 & 3.
xeno6696 Apr 2, 2022
d2f4149
Added test cases 2 & 3. @Ignore on test case 3 from AntiSamy as the …
xeno6696 Apr 2, 2022
6135173
merged with Dave Wichers' kind changes.
xeno6696 Apr 3, 2022
d6589cd
Forced my version to match Wichers.
xeno6696 Apr 3, 2022
a473f17
Added a pair of unit tests for canoncialization to prove out an issue…
xeno6696 Apr 5, 2022
1d91f03
Merge branch 'develop' into develop
kwwall Apr 8, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,8 @@ protected User getUserFromSession() {
*/
protected DefaultUser getUserFromRememberToken() {
try {
String token = ESAPI.httpUtilities().getCookie(ESAPI.currentRequest(), HTTPUtilities.REMEMBER_TOKEN_COOKIE_NAME);
HTTPUtilities utils =ESAPI.httpUtilities();
String token = utils.getCookie(ESAPI.currentRequest(), HTTPUtilities.REMEMBER_TOKEN_COOKIE_NAME);
if (token == null) return null;

// See Google Issue 144 regarding first URLDecode the token and THEN unsealing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,11 +235,12 @@ public void addHeader(String name, String value) {
* {@inheritDoc}
*/
public void addHeader(HttpServletResponse response, String name, String value) {
SecurityConfiguration sc = ESAPI.securityConfiguration();
try {
String strippedName = StringUtilities.replaceLinearWhiteSpace(name);
String strippedValue = StringUtilities.replaceLinearWhiteSpace(value);
String safeName = ESAPI.validator().getValidInput("addHeader", strippedName, "HTTPHeaderName", 20, false);
String safeValue = ESAPI.validator().getValidInput("addHeader", strippedValue, "HTTPHeaderValue", 500, false);
String safeName = ESAPI.validator().getValidInput("addHeader", strippedName, "HTTPHeaderName", sc.getIntProp("HttpUtilities.MaxHeaderNameSize"), false);
String safeValue = ESAPI.validator().getValidInput("addHeader", strippedValue, "HTTPHeaderValue", sc.getIntProp("HttpUtilities.MaxHeaderValueSize"), false);
response.addHeader(safeName, safeValue);
} catch (ValidationException e) {
logger.warning(Logger.SECURITY_FAILURE, "Attempt to add invalid header denied", e);
Expand Down Expand Up @@ -464,9 +465,10 @@ public void encryptStateInCookie( Map<String,String> cleartext ) throws Encrypti
*/
public String getCookie( HttpServletRequest request, String name ) throws ValidationException {
Cookie c = getFirstCookie( request, name );
SecurityConfiguration sc = ESAPI.securityConfiguration();
if ( c == null ) return null;
String value = c.getValue();
return ESAPI.validator().getValidInput("HTTP cookie value: " + value, value, "HTTPCookieValue", 1000, false);
return ESAPI.validator().getValidInput("HTTP cookie value: " + value, value, "HTTPCookieValue", sc.getIntProp("HttpUtilities.MaxHeaderValueSize"), false);
}

/**
Expand Down Expand Up @@ -656,8 +658,9 @@ private Cookie getFirstCookie(HttpServletRequest request, String name) {
* {@inheritDoc}
*/
public String getHeader( HttpServletRequest request, String name ) throws ValidationException {
SecurityConfiguration sc = ESAPI.securityConfiguration();
String value = request.getHeader(name);
return ESAPI.validator().getValidInput("HTTP header value: " + value, value, "HTTPHeaderValue", 150, false);
return ESAPI.validator().getValidInput("HTTP header value: " + value, value, "HTTPHeaderValue", sc.getIntProp("HttpUtilities.MaxHeaderValueSize"), false);
}


Expand Down
21 changes: 20 additions & 1 deletion src/test/java/org/owasp/esapi/reference/EncoderTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ public void testCanonicalize() throws EncodingException {
assertEquals( "<", instance.canonicalize("&lT;"));
assertEquals( "<", instance.canonicalize("&Lt;"));
assertEquals( "<", instance.canonicalize("&LT;"));
assertEquals( "&", instance.canonicalize("&amp"));
assertEquals( "〈", instance.canonicalize("&lang"));

assertEquals( "<script>alert(\"hello\");</script>", instance.canonicalize("%3Cscript%3Ealert%28%22hello%22%29%3B%3C%2Fscript%3E") );
assertEquals( "<script>alert(\"hello\");</script>", instance.canonicalize("%3Cscript&#x3E;alert%28%22hello&#34%29%3B%3C%2Fscript%3E", false) );
Expand Down Expand Up @@ -912,11 +914,28 @@ public void testHtmlEncodeStrSurrogatePair()

public void testHtmlDecodeHexEntititesSurrogatePair()
{
HTMLEntityCodec htmlCodec = new HTMLEntityCodec();
HTMLEntityCodec htmlCodec = new HTMLEntityCodec();
String expected = new String (new int[]{0x2f804}, 0, 1);
assertEquals( expected, htmlCodec.decode("&#194564;") );
assertEquals( expected, htmlCodec.decode("&#x2f804;") );
}

public void testUnicodeCanonicalize() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you should at least add a comment here to refer to the appropriate GitHub issue #.

Encoder e = ESAPI.encoder();
String input = "测试";
String expected = "测试";
String output = e.canonicalize(input);
assertEquals(expected, output);
}

public void testUnicodeCanonicalizePercentEncoding() {
//TODO: We need to find a way to specify the encoding type for percent encoding.
//I believe by default we're doing Latin-1 and we really should be doing UTF-8
Encoder e = ESAPI.encoder();
String input = "%E6%B5%8B%E8%AF%95";
String expected = "测试";
String output = e.canonicalize(input);
assertNotSame(expected, output);
}
}

22 changes: 22 additions & 0 deletions src/test/java/org/owasp/esapi/reference/HTTPUtilitiesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.owasp.esapi.http.MockHttpServletResponse;
import org.owasp.esapi.http.MockHttpSession;
import org.owasp.esapi.util.FileTestUtils;
import org.owasp.esapi.util.TestUtils;

import junit.framework.Test;
import junit.framework.TestCase;
Expand Down Expand Up @@ -372,6 +373,27 @@ public void testSetCookie() {
instance.addCookie( response, new Cookie( "test3", "tes<t3" ) );
assertTrue(response.getHeaderNames().size() == 2);
}

/**
* Test of setCookie method, of class org.owasp.esapi.HTTPUtilities.
* Validation failures should prevent cookies being added.
*/
public void testSetCookieExceedingMaxValueAndName() {
HTTPUtilities instance = ESAPI.httpUtilities();
MockHttpServletResponse response = new MockHttpServletResponse();
assertTrue(response.getHeaderNames().isEmpty());
//request.addParameter(TestUtils.generateStringOfLength(32), "pass");
instance.addCookie( response, new Cookie( TestUtils.generateStringOfLength(32), "pass" ) );
assertTrue(response.getHeaderNames().size() == 1);

instance.addCookie( response, new Cookie( "pass", TestUtils.generateStringOfLength(32) ) );
assertTrue(response.getHeaderNames().size() == 2);
instance.addCookie( response, new Cookie( TestUtils.generateStringOfLength(5000), "fail" ) );
assertTrue(response.getHeaderNames().size() == 2);
instance.addCookie( response, new Cookie( "fail", TestUtils.generateStringOfLength(5001) ) );
assertTrue(response.getHeaderNames().size() == 2);
}


/**
*
Expand Down
10 changes: 8 additions & 2 deletions src/test/java/org/owasp/esapi/reference/ValidatorTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -1040,15 +1040,13 @@ public void testHeaderLengthChecks(){

@Test
public void testGetHeaderNames() {
//testing Validator.HTTPHeaderName
MockHttpServletRequest request = new MockHttpServletRequest();
SecurityWrapperRequest safeRequest = new SecurityWrapperRequest(request);
request.addHeader("d-49653-p", "pass");
request.addHeader("<img ", "fail");
// Note: Max length in ESAPI.properties as per
// Validator.HTTPHeaderName regex is 256, but upper
// bound is configurable by the property HttpUtilities.MaxHeaderNameSize
SecurityConfiguration sc = ESAPI.securityConfiguration();
request.addHeader(TestUtils.generateStringOfLength(255), "pass");
request.addHeader(TestUtils.generateStringOfLength(257), "fail");
assertEquals(2, Collections.list(safeRequest.getHeaderNames()).size());
Expand Down Expand Up @@ -1130,5 +1128,13 @@ public void testavaloqLooseSafeString(){
boolean isValid = v.isValidInput("RegexString", "&quot;test&quot;", "avaloqLooseSafeString", 2147483647, true, true);
assertFalse(isValid);
}

@Test
public void testStandardHeader() {
Validator v = ESAPI.validator();
boolean expected = false;
boolean result = v.isValidInput("HTTPHeaderValue ", "mary.poppins@gmail.com", "HTTPHeaderValue", 2147483647, true, true);
assertEquals(expected, result);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Uh, why not just assertFalse() here instead of setting expected to false and using assertEquals() here? I'd recommend parting it after the previous test (lines 1128-1129).

}
}

Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,14 @@
import org.owasp.esapi.ValidationErrorList;
import org.owasp.esapi.ValidationRule;
import org.owasp.esapi.Validator;
import org.owasp.esapi.errors.IntrusionException;
import org.owasp.esapi.errors.ValidationException;
import org.owasp.esapi.filters.SecurityWrapperRequest;
import org.owasp.esapi.reference.validation.HTMLValidationRule;

import org.junit.Test;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.After;
import org.junit.Rule;
import org.junit.rules.ExpectedException;
Expand Down Expand Up @@ -153,4 +155,46 @@ public void testIsValidSafeHTML() {
assertTrue(errors.size() == 0);

}

@Test
public void testAntiSamyRegressionCDATAWithJavascriptURL() throws Exception {
Validator instance = ESAPI.validator();
ValidationErrorList errors = new ValidationErrorList();
String input = "<style/>b<![cdata[</style><a href=javascript:alert(1)>test";
assertTrue(instance.isValidSafeHTML("test7", input, 100, false, errors));
String expected = "b&lt;/style&gt;&lt;a href=javascript:alert(1)&gt;test";
String output = instance.getValidSafeHTML("javascript Link", input, 250, false);
assertEquals(expected, output);
assertTrue(errors.size() == 0);

}

@Test
public void testScriptTagAfterStyleClosing() throws Exception {
Validator instance = ESAPI.validator();
ValidationErrorList errors = new ValidationErrorList();
String input = "<select<style/>W<xmp<script>alert(1)</script>";
assertTrue(instance.isValidSafeHTML("test7", input, 100, false, errors));
String expected = "W&lt;script&gt;alert(1)&lt;/script&gt;";
String output = instance.getValidSafeHTML("escaping style tag attack", input, 250, false);
assertEquals(expected, output);
assertTrue(errors.size() == 0);

}

@Test
@Ignore
public void testNekoDOSWithAnHTMLComment() throws Exception {
/**
* FIXME: This unit test needs to pass before the next ESAPI release.
*/
Validator instance = ESAPI.validator();
ValidationErrorList errors = new ValidationErrorList();
String input = "<!--><?a/";
assertTrue(instance.isValidSafeHTML("test7", input, 100, false, errors));
String expected = "&#x3C;!--&#x3E;&#x3C;?a/";
String output = instance.getValidSafeHTML("escaping style tag attack", input, 250, false);
assertEquals(expected, output);
assertTrue(errors.size() == 0);
}
}