Skip to content

Commit ff6649f

Browse files
committed
Delete code referring to the previously deprecated Validator.isValidSafeHTML methods.
This is wrap up GHSA-r68h-jhhj-9jvm.
1 parent acebf45 commit ff6649f

File tree

5 files changed

+13
-252
lines changed

5 files changed

+13
-252
lines changed

src/main/java/org/owasp/esapi/Validator.java

Lines changed: 4 additions & 91 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,10 @@
4444
* </p><p>
4545
* <b>CAUTION:</b> There are many methods that take multiple (or only!) {@code String}
4646
* arguments. Be careful that you do not mix up the order of these, because for
47-
* some methods such as {@code isValidSafeHTML} if you were to confuse the order of
48-
* {@code context} and {@code input} arguments, you would not be verifying what
49-
* you thought you were and it could have serious security consequences as a
50-
* result. When there are 2 these {@code String} parameters&mdash;{@code context} and
51-
* {@code input} arguments&mdash;the * {@code context} argument is always first.
47+
* several methods that have {@code context} and {@code input} arguments, mixing up
48+
* the order of those likely will result in serious security consequences.
49+
* . When there are 2 these {@code String} parameters&mdash;{@code context} and
50+
* {@code input} arguments&mdash;the {@code context} argument is <i>always</i> first.
5251
* See the individual method documentation for additional details.
5352
* </p>
5453
*
@@ -297,92 +296,6 @@ public interface Validator {
297296
*/
298297
Date getValidDate(String context, String input, DateFormat format, boolean allowNull, ValidationErrorList errorList) throws IntrusionException;
299298

300-
/**
301-
* Returns {@code true} if the parameter {@code input} is valid and <i>presumably</i> safe.
302-
* <p>
303-
* <b>WARNING:</b> Note that the only safe way to use this method is if you
304-
* instead of using the passed-in parameter '{@code input}' (which should
305-
* not be completely trusted as-is, regardless of whether this method returns
306-
* {@code true}), you first sanitize (i.e., cleanse) the parameter '{@code input}'
307-
* by first by calling one of the {@code getValidSafeHTML} methods on it. For
308-
* additional details explaining the rationale for this, please see the referenced
309-
* ESAPI Security Bulletin 12 in the referenced GitHub Security Advisory
310-
* mentioned in the "See Also" section below.
311-
*
312-
* @param context
313-
* A descriptive tag name for the input that you are validating (e.g., user_comment).
314-
* This value is used by any logging or error handling that is done with respect to the value passed in.
315-
* @param input
316-
* The actual user input data to validate. Note that the expectation
317-
* is that this input is allowed to contain "safe" HTML markup,
318-
* otherwise you should not be using this {@code Validator} method
319-
* at all.
320-
* @param maxLength
321-
* The maximum {@code String} length allowed for {@code input}.
322-
* @param allowNull
323-
* If {@code allowNull} is true then an input that is NULL or an empty string will be legal.
324-
* If {@code allowNull} is false then NULL or an empty String will throw a ValidationException.
325-
*
326-
* @return True if the {@code input} is <i>presumably</i> safe, otherwise false.
327-
*
328-
* @throws IntrusionException The parameter {@code input} likely indicates an attack.
329-
*
330-
* @deprecated Deprecated as of ESAPI 2.5.3.0. This method will be removed in 1 year
331-
* after the ESAPI 2.5.3.0 release date (2023-11-24).
332-
*
333-
* @see <a href="https://github.com/ESAPI/esapi-java-legacy/security/advisories/GHSA-r68h-jhhj-9jvm"
334-
* target="_blank" rel="noreferrer noopener">GitHub Security Advisory: Validator.isValidSafeHTML
335-
* is being deprecated and will be deleted in 1 year</a>
336-
*/
337-
@Deprecated
338-
boolean isValidSafeHTML(String context, String input, int maxLength, boolean allowNull) throws IntrusionException;
339-
340-
/**
341-
* Returns {@code true} if the parameter {@code input} is valid and <i>presumably</i> safe.
342-
* Any exceptions are added to the supplied {@code errorList} parameter.
343-
* <p>
344-
* <p>
345-
* Calls {@link #getValidSafeHTML(String, String, int, boolean)},
346-
* and returns true if no exceptions are thrown.
347-
* <p>
348-
* <b>WARNING:</b> Note that the only safe way to use this method is if you
349-
* instead of using the passed-in parameter '{@code input}' (which should
350-
* not be completely trusted as-is, regardless of whether this method returns
351-
* {@code true}), you first sanitize (i.e., cleanse) the parameter '{@code input}'
352-
* by first by calling one of the {@code getValidSafeHTML} methods on it. For
353-
* additional details explaining the rationale for this, please see the referenced
354-
* ESAPI Security Bulletin 12 in the referenced GitHub Security Advisory
355-
* mentioned in the "See Also" section below.
356-
*
357-
* @param context
358-
* A descriptive tag name for the input that you are validating (e.g., user_comment).
359-
* This value is used by any logging or error handling that is done with respect to the value passed in.
360-
* @param input
361-
* The actual user input data to validate. Note that the expectation
362-
* is that this input is allowed to contain "safe" HTML markup,
363-
* otherwise you should not be using this {@code Validator} method
364-
* at all.
365-
* @param maxLength
366-
* The maximum {@code String} length allowed for {@code input}.
367-
* @param allowNull
368-
* If {@code allowNull} is true then an input that is NULL or an empty string will be legal.
369-
* If {@code allowNull} is false then NULL or an empty String will throw a ValidationException.
370-
* @param errorList The error list to which any {@code ValidationException} messages are added.
371-
*
372-
* @return True if the {@code input} is <i>presumably</i> safe, otherwise false.
373-
*
374-
* @throws IntrusionException The parameter {@code input} likely indicates an attack.
375-
*
376-
* @deprecated Deprecated as of ESAPI 2.5.3.0. This method will be removed in 1 year
377-
* after the ESAPI 2.5.3.0 release date (2023-11-24).
378-
*
379-
* @see <a href="https://github.com/ESAPI/esapi-java-legacy/security/advisories/GHSA-r68h-jhhj-9jvm"
380-
* target="_blank" rel="noreferrer noopener">GitHub Security Advisory: Validator.isValidSafeHTML
381-
* is being deprecated and will be deleted in 1 year</a>
382-
*/
383-
@Deprecated
384-
boolean isValidSafeHTML(String context, String input, int maxLength, boolean allowNull, ValidationErrorList errorList) throws IntrusionException;
385-
386299
/**
387300
* Canonicalize and then sanitize the input so that it is "safe" for rendering in an HTML context (i.e., that
388301
* it does not contain unwanted scripts in the body, attributes, CSS, URLs, or anywhere else). Note that the resulting

src/main/java/org/owasp/esapi/reference/DefaultValidator.java

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,6 @@ public class DefaultValidator implements org.owasp.esapi.Validator {
9999
private static Logger logger = ESAPI.log();
100100
private static volatile Validator instance = null;
101101
private static boolean alreadyLogged = false;
102-
private static String deprecationWarning = "WARNING: You are using the Validator.isValidSafeHTML interface, " +
103-
"which has been deprecated and should be avoided. See GitHub Security Advisory " +
104-
"https://github.com/ESAPI/esapi-java-legacy/security/advisories/GHSA-r68h-jhhj-9jvm for details.";
105102

106103
public static Validator getInstance() {
107104
if ( instance == null ) {
@@ -379,47 +376,6 @@ public Date getValidDate(String context, String input, DateFormat format, boolea
379376
return safeDate;
380377
}
381378

382-
/**
383-
* {@inheritDoc}
384-
* <p>
385-
* This implementation does not throw {@link IntrusionException}.
386-
*/
387-
@Override
388-
public boolean isValidSafeHTML(String context, String input, int maxLength, boolean allowNull) {
389-
// Ensure a message about deprecation is logged once if this or the
390-
// other isValidSafeHTML method is called.
391-
if ( ! alreadyLogged ) {
392-
logger.always(Logger.SECURITY_AUDIT, deprecationWarning);
393-
alreadyLogged = true;
394-
}
395-
try {
396-
getValidSafeHTML( context, input, maxLength, allowNull);
397-
return true;
398-
} catch( Exception e ) {
399-
return false;
400-
}
401-
}
402-
403-
/**
404-
* {@inheritDoc}
405-
*/
406-
@Override
407-
public boolean isValidSafeHTML(String context, String input, int maxLength, boolean allowNull, ValidationErrorList errors) throws IntrusionException {
408-
// Ensure a message about deprecation is logged once if this or the
409-
// other isValidSafeHTML method is called.
410-
if ( ! alreadyLogged ) {
411-
logger.always(Logger.SECURITY_AUDIT, deprecationWarning);
412-
alreadyLogged = true;
413-
}
414-
try {
415-
getValidSafeHTML( context, input, maxLength, allowNull);
416-
return true;
417-
} catch( ValidationException e ) {
418-
errors.addError(context, e);
419-
return false;
420-
}
421-
}
422-
423379
/**
424380
* {@inheritDoc}
425381
* <p>

src/test/java/org/owasp/esapi/reference/validation/HTMLValidationRuleClasspathTest.java

Lines changed: 2 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,11 @@
4747
*
4848
* This class tests the case of a non-standard AntiSamy policy file along with
4949
* the case where the new ESAPI.property
50-
* {@code Validator.HtmlValidationAction}
50+
* <b>Validator.HtmlValidationAction</b>
5151
* is set to "throw", which causes certain calls to
52-
* ESAPI.validator().getValidSafeHTML() or ESAPI.validator().isValidSafeHTML()
52+
* {@code ESAPI.validator().getValidSafeHTML()}
5353
* to throw a ValidationException rather than simply logging a warning and returning
5454
* the cleansed (sanitizied) output when certain unsafe input is encountered.
55-
*
56-
* It should be noted that several of the tests in this file are deprecated because
57-
* they use {@code Validator.isValidSafeHTML} which is deprecated. See the
58-
* deprecation warnings for those methods respective Javadoc for further
59-
* details.
6055
*/
6156
public class HTMLValidationRuleClasspathTest {
6257
/** The intentionally non-compliant (to the AntiSamy XSD) AntiSamy policy file. We don't intend to
@@ -177,32 +172,4 @@ public void testGetValidSafeHTML() throws Exception {
177172
}
178173
}
179174

180-
/**
181-
* @deprecated because Validator.isValidSafeHTML is deprecated.
182-
* @see org.owasp.esapi.Validator#isValidSafeHTML(String,String,int,boolean)
183-
* @see org.owasp.esapi.Validator#isValidSafeHTML(String,String,int,boolean,org.owasp.esapi.ValidationErrorList)
184-
*/
185-
@Deprecated
186-
@Test
187-
public void testIsValidSafeHTML() {
188-
System.out.println("isValidSafeHTML");
189-
Validator instance = ESAPI.validator();
190-
thrownEx = ExpectedException.none(); // Not expecting any exceptions here.
191-
192-
assertTrue(instance.isValidSafeHTML("test", "<b>Jeff</b>", 100, false));
193-
assertTrue(instance.isValidSafeHTML("test", "<a href=\"http://www.aspectsecurity.com\">Aspect Security</a>", 100, false));
194-
assertFalse(instance.isValidSafeHTML("test", "Test. <script>alert(document.cookie)</script>", 100, false));
195-
assertFalse(instance.isValidSafeHTML("test", "Test. <div style={xss:expression(xss)}>", 100, false));
196-
assertFalse(instance.isValidSafeHTML("test", "Test. <s%00cript>alert(document.cookie)</script>", 100, false));
197-
assertFalse(instance.isValidSafeHTML("test", "Test. <s\tcript>alert(document.cookie)</script>", 100, false));
198-
assertFalse(instance.isValidSafeHTML("test", "Test. <s\r\n\0cript>alert(document.cookie)</script>", 100, false));
199-
200-
ValidationErrorList errors = new ValidationErrorList();
201-
assertFalse(instance.isValidSafeHTML("test1", "Test. <script>alert(document.cookie)</script>", 100, false, errors));
202-
assertFalse(instance.isValidSafeHTML("test2", "Test. <div style={xss:expression(xss)}>", 100, false, errors));
203-
assertFalse(instance.isValidSafeHTML("test3", "Test. <s%00cript>alert(document.cookie)</script>", 100, false, errors));
204-
assertFalse(instance.isValidSafeHTML("test4", "Test. <s\tcript>alert(document.cookie)</script>", 100, false, errors));
205-
assertFalse(instance.isValidSafeHTML("test5", "Test. <s\r\n\0cript>alert(document.cookie)</script>", 100, false, errors));
206-
assertTrue( errors.size() == 5 );
207-
}
208175
}

src/test/java/org/owasp/esapi/reference/validation/HTMLValidationRuleCleanTest.java

Lines changed: 5 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,9 @@
5656
* that were originally part of src/test/java/org/owasp/esapi/reference/ValidatorTest.java.
5757
*
5858
* This class tests the cases where the new ESAPI.property
59-
* Validator.HtmlValidationAction
59+
* <b>Validator.HtmlValidationAction</b>
6060
* is set to "clean", which causes certain calls to
61-
* ESAPI.validator().getValidSafeHTML() or ESAPI.validator().isValidSafeHTML()
61+
* {@code ESAPI.validator().getValidSafeHTML()}
6262
* to simply log a warning and return the cleansed (sanitized) output rather
6363
* than throwing a ValidationException when certain unsafe input is
6464
* encountered.
@@ -275,53 +275,6 @@ public void testAntiSamy_CVE_2023_43643() {
275275
}
276276
////////////////////////////////////////
277277

278-
/**
279-
* @deprecated because Validator.isValidSafeHTML is deprecated.
280-
* @see org.owasp.esapi.Validator#isValidSafeHTML(String,String,int,boolean)
281-
* @see org.owasp.esapi.Validator#isValidSafeHTML(String,String,int,boolean,org.owasp.esapi.ValidationErrorList)
282-
*/
283-
@Deprecated
284-
@Test
285-
public void testIsValidSafeHTML() {
286-
System.out.println("testIsValidSafeHTML");
287-
Validator instance = ESAPI.validator();
288-
289-
assertTrue(instance.isValidSafeHTML("test", "<b>Jeff</b>", 100, false));
290-
assertTrue(instance.isValidSafeHTML("test", "<a href=\"http://www.aspectsecurity.com\">Aspect Security</a>", 100, false));
291-
assertTrue(instance.isValidSafeHTML("test", "Test. <script>alert(document.cookie)</script>", 100, false));
292-
assertTrue(instance.isValidSafeHTML("test", "Test. <div style={xss:expression(xss)}>", 100, false));
293-
assertTrue(instance.isValidSafeHTML("test", "Test. <s%00cript>alert(document.cookie)</script>", 100, false));
294-
assertTrue(instance.isValidSafeHTML("test", "Test. <s\tcript>alert(document.cookie)</script>", 100, false));
295-
assertTrue(instance.isValidSafeHTML("test", "Test. <s\r\n\0cript>alert(document.cookie)</script>", 100, false));
296-
297-
ValidationErrorList errors = new ValidationErrorList();
298-
assertTrue(instance.isValidSafeHTML("test1", "<b>Jeff</b>", 100, false, errors));
299-
assertTrue(instance.isValidSafeHTML("test2", "<a href=\"http://www.aspectsecurity.com\">Aspect Security</a>", 100, false, errors));
300-
assertTrue(instance.isValidSafeHTML("test3", "Test. <script>alert(document.cookie)</script>", 100, false, errors));
301-
assertTrue(instance.isValidSafeHTML("test4", "Test. <div style={xss:expression(xss)}>", 100, false, errors));
302-
assertTrue(instance.isValidSafeHTML("test5", "Test. <s%00cript>alert(document.cookie)</script>", 100, false, errors));
303-
assertTrue(instance.isValidSafeHTML("test6", "Test. <s\tcript>alert(document.cookie)</script>", 100, false, errors));
304-
assertTrue(instance.isValidSafeHTML("test7", "Test. <s\r\n\0cript>alert(document.cookie)</script>", 100, false, errors));
305-
assertTrue(errors.size() == 0);
306-
307-
// Extracted from testIEConditionalComment().
308-
String input = "<!--[if gte IE 4]>\r\n <SCRIPT>alert('XSS');</SCRIPT>\r\n<![endif]-->";
309-
boolean isSafe = instance.isValidSafeHTML("test12", input, 100, false, errors);
310-
assertTrue(instance.isValidSafeHTML("test12", input, 100, false, errors)); // Safe bc "" gets returned!!!
311-
312-
// Extracted from testNekoDOSWithAnHTMLComment()
313-
errors = new ValidationErrorList();
314-
input = "<!--><?a/";
315-
assertTrue(instance.isValidSafeHTML("test11", input, 100, false, errors)); // Safe bc "" gets returned!!!
316-
assertTrue(errors.size() == 0);
317-
318-
// Extracted from testESAPI_CVE_2022_24891()
319-
String expectedSafeText = "This is safe from XSS. Trust us!";
320-
String badVoodoo = "<a href=\"javascript&#00058alert(1)>" + expectedSafeText + "</a>";
321-
boolean result = instance.isValidSafeHTML("CVE-2021-35043", badVoodoo, 200, false);
322-
assertTrue( result );
323-
}
324-
325278
// This test has been significantly changed because as on AntiSamy 1.7.4
326279
// (first used with ESAPI 2.5.3.0) has changed the results of
327280
// Validator.getValidSafeHTMLfor this output. Prior to AntiSamy 1.7.4, the
@@ -335,7 +288,7 @@ public void testIsValidSafeHTML() {
335288
//
336289
// Also, this test, which originally used Validator.isValidSafeHTML(), has been
337290
// changed to use Validator.getValidSafeHTML() instead because Validator.isValidSafeHTML()
338-
// has been deprecated. See GitHub Security Advisory
291+
// has been removed as of ESAPI 2.6.0.0. See GitHub Security Advisory
339292
// https://github.com/ESAPI/esapi-java-legacy/security/advisories/GHSA-r68h-jhhj-9jvm
340293
// and the referenced ESAPI Security Bulletin mentioned therein.
341294
@Test
@@ -368,7 +321,7 @@ public void testAntiSamyRegressionCDATAWithJavascriptURL() throws Exception {
368321
//
369322
// Also, this test, which originally used Validator.isValidSafeHTML(), has been
370323
// changed to use Validator.getValidSafeHTML() instead because Validator.isValidSafeHTML()
371-
// has been deprecated. See GitHub Security Advisory
324+
// has been removed as of ESAPI 2.6.0.0. See GitHub Security Advisory
372325
// https://github.com/ESAPI/esapi-java-legacy/security/advisories/GHSA-r68h-jhhj-9jvm
373326
// and the referenced ESAPI Security Bulletin mentioned therein.
374327
@Test
@@ -403,7 +356,7 @@ public void testScriptTagAfterStyleClosing() throws Exception {
403356
//
404357
// Also, this test, which originally used Validator.isValidSafeHTML(), has been
405358
// changed to use Validator.getValidSafeHTML() instead because Validator.isValidSafeHTML()
406-
// has been deprecated. See GitHub Security Advisory
359+
// has been removed as of ESAPI 2.6.0.0. See GitHub Security Advisory
407360
// https://github.com/ESAPI/esapi-java-legacy/security/advisories/GHSA-r68h-jhhj-9jvm
408361
// and the referenced ESAPI Security Bulletin mentioned therein.
409362
@Test

0 commit comments

Comments
 (0)