Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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 @@ -244,7 +244,7 @@ private String invokeAntiSamy( String context, String input ) throws ValidationE
List<String> errors = test.getErrorMessages();
if ( !errors.isEmpty() ) {
if ( legacyHtmlValidation() ) { // See GitHub issues 509 and 521
LOGGER.info(Logger.SECURITY_FAILURE, "Cleaned up invalid HTML input: " + errors );
LOGGER.info(Logger.SECURITY_FAILURE, "Cleaned up invalid HTML input: context=" + context + " errors=" + errors );
} else {
throw new ValidationException( context + ": Invalid HTML input", "Invalid HTML input does not follow rules in antisamy-esapi.xml: context=" + context + " errors=" + errors.toString());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@
import org.owasp.esapi.reference.validation.HTMLValidationRule;
import static org.owasp.esapi.PropNames.VALIDATOR_HTML_VALIDATION_ACTION;

import java.util.ArrayList;
import java.util.List;
import java.util.logging.Handler;
import java.util.logging.LogRecord;

import org.junit.Test;
import org.junit.Before;
import org.junit.Ignore;
Expand Down Expand Up @@ -405,4 +410,39 @@ public void testIEConditionalComment() throws Exception {
String output = instance.getValidSafeHTML("escaping IE conditional comment", input, 250, true);
assertEquals(expectEmpty, output); // Expect AntiSamy to return empty string here.
}

// Test for GitHub issue 793: the context should be logged when invalid
// HTML input is cleaned up rather than rejected.
@Test
public void testCleanedUpInputLogsContext() throws Exception {
final List<String> messages = new ArrayList<>();
Handler handler = new Handler() {
@Override
public void publish(LogRecord record) {
messages.add(record.getMessage());
}
@Override
public void flush() {
}
@Override
public void close() {
}
};
java.util.logging.Logger javaLogger = java.util.logging.Logger.getLogger("HTMLValidationRule");
javaLogger.addHandler(handler);
try {
HTMLValidationRule rule = new HTMLValidationRule("logContextTest");
rule.getValid("myContextName", "Test. <script>alert(document.cookie)</script>");
} finally {
javaLogger.removeHandler(handler);
}

boolean found = false;
for (String message : messages) {
if (message.contains("Cleaned up invalid HTML input") && message.contains("context=myContextName")) {
found = true;
}
}
assertTrue("Expected the context in the log message, got: " + messages, found);
}
}