Skip to content

Commit e280336

Browse files
committed
Javadoc additons and clean-up.
1 parent 0024635 commit e280336

File tree

1 file changed

+38
-3
lines changed

1 file changed

+38
-3
lines changed

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

Lines changed: 38 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -160,11 +160,20 @@ public interface Encoder {
160160
/**
161161
* This method is equivalent to calling {@code Encoder.canonicalize(input, restrictMultiple, restrictMixed);}.
162162
*
163-
* The default values for restrictMultiple and restrictMixed come from {@code ESAPI.properties}
163+
* The <i>default</i> values for {@code restrictMultiple} and {@code restrictMixed} come from {@code ESAPI.properties}.
164164
* <pre>
165165
* Encoder.AllowMultipleEncoding=false
166166
* Encoder.AllowMixedEncoding=false
167167
* </pre>
168+
* and the default codecs that are used for canonicalization are the list
169+
* of codecs that comes from:
170+
* <pre>
171+
* Encoder.DefaultCodecList=HTMLEntityCodec,PercentCodec,JavaScriptCodec
172+
* </pre>
173+
* (If the {@code Encoder.DefaultCodecList} property is null or not set,
174+
* these same codecs are listed in the same order. Note that you may supply
175+
* your own codec by using a fully cqualified class name of a class that
176+
* implements {@code org.owasp.esapi.codecs.Codec<T>}.
168177
*
169178
* @see #canonicalize(String, boolean, boolean)
170179
* @see <a href="http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4">W3C specifications</a>
@@ -224,7 +233,25 @@ public interface Encoder {
224233
* Encoder encoder = new DefaultEncoder( list );
225234
* String clean = encoder.canonicalize( request.getParameter( "input" ));
226235
* </pre>
227-
* In ESAPI, the Validator uses the canonicalize method before it does validation. So all you need to
236+
* or alternately, you can just customize {@code Encoder.DefaultCodecList} property
237+
* in the {@code ESAPI.properties} file with your preferred codecs; for
238+
* example:
239+
* <pre>
240+
* Encoder.DefaultCodecList=WindowsCodec,MySQLCodec,PercentCodec
241+
* </pre>
242+
* and then use:
243+
* <pre>
244+
* Encoder encoder = ESAPI.encoder();
245+
* String clean = encoder.canonicalize( request.getParameter( "input" ));
246+
* </pre>
247+
* as you normally would. However, the downside to using the
248+
* {@code ESAPI.properties} file approach does not allow you to vary your
249+
* list of codecs that are used each time. The downside to using the
250+
* {@code DefaultEncoder} constructor is that your code is now timed to
251+
* specific reference implementations rather than just interfaces and those
252+
* reference implementations are what is most likely to change in ESAPI 3.x.
253+
* </p><p>
254+
* In ESAPI, the {@code Validator} uses the {@code canonicalize} method before it does validation. So all you need to
228255
* do is to validate as normal and you'll be protected against a host of encoded attacks.
229256
* <pre>
230257
* String input = request.getParameter( "name" );
@@ -253,14 +280,22 @@ public interface Encoder {
253280
* // disabling strict mode to allow mixed encoding
254281
* String url = ESAPI.encoder().canonicalize( request.getParameter("url"), false, false);
255282
* </pre>
256-
* <b>WARNING!!!</b> Please note that this method is incompatible with URLs and if there exist any HTML Entities
283+
* <b>WARNING #1!!!</b> Please note that this method is incompatible with URLs and if there exist any HTML Entities
257284
* that correspond with parameter values in a URL such as "&amp;para;" in a URL like
258285
* "https://foo.com/?bar=foo&amp;parameter=wrong" you will get a mixed encoding validation exception.
259286
* <p>
260287
* If you wish to canonicalize a URL/URI use the method {@code Encoder.getCanonicalizedURI(URI dirtyUri);}
288+
* </p><p>
289+
* <b>WARNING #2!!!</b> Even if you use {@code WindowsCodec} or {@code UnixCodec}
290+
* as appropriate, file path names in the {@code input} parameter will <b><i>NOT</i></b>
291+
* be canonicalized. It the failure of such file path name canonicalization
292+
* presents a potential security issue, consider using one of the
293+
* {@code Validator.getValidDirectoryPath()} methods instead of or in addition to this method.
261294
*
262295
* @see <a href="http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4">W3C specifications</a>
296+
* @see #canonicalize(String)
263297
* @see #getCanonicalizedURI(URI dirtyUri)
298+
* @see org.owasp.esapi.Validator#getValidDirectoryPath(java.lang.String, java.lang.String, java.io.File, boolean)
264299
*
265300
* @param input
266301
* the text to canonicalize

0 commit comments

Comments
 (0)