54
54
import org .owasp .esapi .reference .validation .StringValidationRule ;
55
55
56
56
/**
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},
59
60
* 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>
61
88
*
62
89
* @author Jeff Williams (jeff.williams .at. aspectsecurity.com) <a href="http://www.aspectsecurity.com">Aspect Security</a>
63
90
* @author Jim Manico ([email protected] ) <a href="http://www.manico.net">Manico.net</a>
64
91
* @author Matt Seil (mseil .at. acm.org)
65
92
*
66
93
* @since June 1, 2007
67
94
* @see org.owasp.esapi.Validator
95
+ * @see org.owasp.esapi.Encoder
96
+ * @see org.owasp.esapi.Encoder#canonicalize(String,boolean,boolean)
68
97
*/
69
98
public class DefaultValidator implements org .owasp .esapi .Validator {
70
99
private static Logger logger = ESAPI .log ();
@@ -102,16 +131,22 @@ public static Validator getInstance() {
102
131
103
132
/**
104
133
* 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.
105
137
*/
106
138
public DefaultValidator () {
107
139
this .encoder = ESAPI .encoder ();
108
140
}
109
141
110
142
/**
111
143
* 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}.
115
150
*/
116
151
public DefaultValidator ( Encoder encoder ) {
117
152
this .encoder = encoder ;
@@ -139,7 +174,11 @@ public ValidationRule getRule(String name ) {
139
174
* {@inheritDoc}
140
175
* <p>
141
176
* 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.
143
182
*/
144
183
@ Override
145
184
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
150
189
* {@inheritDoc}
151
190
* <p>
152
191
* 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.
154
197
*/
155
198
@ Override
156
199
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
161
204
* {@inheritDoc}
162
205
* <p>
163
206
* 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.
165
212
* <p>
166
213
* This implementation does not throw {@link IntrusionException}.
167
214
*/
@@ -179,7 +226,11 @@ public boolean isValidInput(String context, String input, String type, int maxLe
179
226
* {@inheritDoc}
180
227
* <p>
181
228
* 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.
183
234
*/
184
235
@ Override
185
236
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
196
247
* {@inheritDoc}
197
248
* <p>
198
249
* 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.
200
255
*/
201
256
@ Override
202
257
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
207
262
* {@inheritDoc}
208
263
* <p>
209
264
* 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.
211
270
*/
212
271
@ Override
213
272
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
229
288
* {@inheritDoc}
230
289
* <p>
231
290
* 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.
233
296
*/
234
297
@ Override
235
298
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
240
303
* {@inheritDoc}
241
304
* <p>
242
305
* 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.
244
311
*/
245
312
@ Override
246
313
public String getValidInput (String context , String input , String type , int maxLength , boolean allowNull , boolean canonicalize , ValidationErrorList errors ) throws IntrusionException {
0 commit comments