5454import org .owasp .esapi .reference .validation .StringValidationRule ;
5555
5656/**
57- * Reference implementation of the Validator interface. This implementation
58- * relies on the ESAPI Encoder, Java Pattern (regex), Date,
57+ * Reference implementation of the {@code Validator} interface. This implementation
58+ * relies on the ESAPI {@code Encoder}, {@link java.util.regex.Pattern},
59+ * {@link java.util.Date},
5960 * and several other classes to provide basic validation functions. This library
60- * has a heavy emphasis on whitelist validation and canonicalization.
61+ * has a heavy emphasis on allow-list validation and canonicalization.
62+ * <p>
63+ * <b>A Note about Canonicalization</b>:
64+ * The behaviors of objects of this class are largely driven by how the
65+ * associated {@code Encoder} is created and passed to one of this
66+ * class' constructors. Specifically, what {@link org.owasp.esapi.codecs.Codec}
67+ * types are referenced by the {@link org.owasp.esapi.Encoder} instance
68+ * associated with this particular {@code DefaultValidator} instance. In places
69+ * where the default {@code Encoder} instance is used, the behavior is driven
70+ * by three ESAPI properties as defined in the <b>ESAPI.properties</b> file.
71+ * These property names and their default values (as delivered in ESAPI's
72+ * "configuration" jar) are as follows:
73+ * <pre>
74+ * Encoder.AllowMultipleEncoding=false
75+ * Encoder.AllowMixedEncoding=false
76+ * Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec
77+ * </pre>
78+ * In places where canonicalization is checked, multiple
79+ * encoding (the first property, which refers to encoding in the <i>same</i> manner
80+ * more than once) or mixed encoding (the second property, which refers to
81+ * encoding using multiple <i>different</i> encoding mechanisms) are generally
82+ * considered attacks unless these respective property values are set to
83+ * "true".
84+ * </p><p>
85+ * Note that changing any of these three properties may affect the behavior as
86+ * documented in this class' methods.
87+ * </p>
6188 *
6289 * @author Jeff Williams (jeff.williams .at. aspectsecurity.com) <a href="http://www.aspectsecurity.com">Aspect Security</a>
6390 * @author Jim Manico ([email protected] ) <a href="http://www.manico.net">Manico.net</a> 6491 * @author Matt Seil (mseil .at. acm.org)
6592 *
6693 * @since June 1, 2007
6794 * @see org.owasp.esapi.Validator
95+ * @see org.owasp.esapi.Encoder
96+ * @see org.owasp.esapi.Encoder#canonicalize(String,boolean,boolean)
6897 */
6998public class DefaultValidator implements org .owasp .esapi .Validator {
7099 private static Logger logger = ESAPI .log ();
@@ -102,16 +131,22 @@ public static Validator getInstance() {
102131
103132 /**
104133 * Default constructor uses the ESAPI standard encoder for canonicalization.
134+ * This uses an {@code Encoder} created based on the {@code Codec}s
135+ * specified by the value of the {@code Encoder.DefaultCodecList} ESAPI
136+ * property as defined in your <b>ESAPI.properties</b> file.
105137 */
106138 public DefaultValidator () {
107139 this .encoder = ESAPI .encoder ();
108140 }
109141
110142 /**
111143 * Construct a new DefaultValidator that will use the specified
112- * Encoder for canonicalization.
113- *
114- * @param encoder
144+ * {@code Encoder} for canonicalization.
145+ * @param encoder The specially constructed ESAPI {@code Encoder} instance
146+ * that uses a custom list of {@code Codec}s for
147+ * canonicalization purposes. See
148+ * {@link org.owasp.esapi.Encoder#canonicalize(String,boolean,boolean)}
149+ * for an example of how to create a custom {@code Encoder}.
115150 */
116151 public DefaultValidator ( Encoder encoder ) {
117152 this .encoder = encoder ;
@@ -139,7 +174,11 @@ public ValidationRule getRule(String name ) {
139174 * {@inheritDoc}
140175 * <p>
141176 * Double encoding is treated as an attack.
142- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
177+ * The canonicalization behavior is controlled by the instance's associated ESAPI
178+ * {@code Encoder} and generally driven through the ESAPI property
179+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
180+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
181+ * for additional details.
143182 */
144183 @ Override
145184 public boolean isValidInput (String context , String input , String type , int maxLength , boolean allowNull ) throws IntrusionException {
@@ -150,7 +189,11 @@ public boolean isValidInput(String context, String input, String type, int maxLe
150189 * {@inheritDoc}
151190 * <p>
152191 * Double encoding is treated as an attack.
153- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
192+ * The canonicalization behavior is controlled by the instance's associated ESAPI
193+ * {@code Encoder} and generally driven through the ESAPI property
194+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
195+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
196+ * for additional details.
154197 */
155198 @ Override
156199 public boolean isValidInput (String context , String input , String type , int maxLength , boolean allowNull , ValidationErrorList errors ) {
@@ -161,7 +204,11 @@ public boolean isValidInput(String context, String input, String type, int maxLe
161204 * {@inheritDoc}
162205 * <p>
163206 * Double encoding is treated as an attack.
164- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
207+ * The canonicalization behavior is controlled by the instance's associated ESAPI
208+ * {@code Encoder} and generally driven through the ESAPI property
209+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
210+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
211+ * for additional details.
165212 * <p>
166213 * This implementation does not throw {@link IntrusionException}.
167214 */
@@ -179,7 +226,11 @@ public boolean isValidInput(String context, String input, String type, int maxLe
179226 * {@inheritDoc}
180227 * <p>
181228 * Double encoding is treated as an attack.
182- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
229+ * The canonicalization behavior is controlled by the instance's associated ESAPI
230+ * {@code Encoder} and generally driven through the ESAPI property
231+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
232+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
233+ * for additional details.
183234 */
184235 @ Override
185236 public boolean isValidInput (String context , String input , String type , int maxLength , boolean allowNull , boolean canonicalize , ValidationErrorList errors ) throws IntrusionException {
@@ -196,7 +247,11 @@ public boolean isValidInput(String context, String input, String type, int maxLe
196247 * {@inheritDoc}
197248 * <p>
198249 * Double encoding is treated as an attack.
199- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
250+ * The canonicalization behavior is controlled by the instance's associated ESAPI
251+ * {@code Encoder} and generally driven through the ESAPI property
252+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
253+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
254+ * for additional details.
200255 */
201256 @ Override
202257 public String getValidInput (String context , String input , String type , int maxLength , boolean allowNull ) throws ValidationException {
@@ -207,7 +262,11 @@ public String getValidInput(String context, String input, String type, int maxLe
207262 * {@inheritDoc}
208263 * <p>
209264 * Double encoding is treated as an attack.
210- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
265+ * The canonicalization behavior is controlled by the instance's associated ESAPI
266+ * {@code Encoder} and generally driven through the ESAPI property
267+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
268+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
269+ * for additional details.
211270 */
212271 @ Override
213272 public String getValidInput (String context , String input , String type , int maxLength , boolean allowNull , boolean canonicalize ) throws ValidationException {
@@ -229,7 +288,11 @@ public String getValidInput(String context, String input, String type, int maxLe
229288 * {@inheritDoc}
230289 * <p>
231290 * Double encoding is treated as an attack.
232- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
291+ * The canonicalization behavior is controlled by the instance's associated ESAPI
292+ * {@code Encoder} and generally driven through the ESAPI property
293+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
294+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
295+ * for additional details.
233296 */
234297 @ Override
235298 public String getValidInput (String context , String input , String type , int maxLength , boolean allowNull , ValidationErrorList errors ) throws IntrusionException {
@@ -240,7 +303,11 @@ public String getValidInput(String context, String input, String type, int maxLe
240303 * {@inheritDoc}
241304 * <p>
242305 * Double encoding is treated as an attack.
243- * The default encoder supports HTML encoding, URL encoding, and javascript escaping.
306+ * The canonicalization behavior is controlled by the instance's associated ESAPI
307+ * {@code Encoder} and generally driven through the ESAPI property
308+ * {@code Encoder.DefaultCodecList} specified in the <b>ESAPI.properties</b>
309+ * file. See the class level documentation section "<b>A Note about Canonicalization</b>"
310+ * for additional details.
244311 */
245312 @ Override
246313 public String getValidInput (String context , String input , String type , int maxLength , boolean allowNull , boolean canonicalize , ValidationErrorList errors ) throws IntrusionException {
0 commit comments