@@ -98,23 +98,23 @@ public class StrictHttpFirewall implements HttpFirewall {
98
98
99
99
private static final List <String > FORBIDDEN_BACKSLASH = Collections .unmodifiableList (Arrays .asList ("\\ " , "%5c" , "%5C" ));
100
100
101
- private Set <String > encodedUrlBlacklist = new HashSet <>();
101
+ private Set <String > encodedUrlBlocklist = new HashSet <>();
102
102
103
- private Set <String > decodedUrlBlacklist = new HashSet <>();
103
+ private Set <String > decodedUrlBlocklist = new HashSet <>();
104
104
105
105
private Set <String > allowedHttpMethods = createDefaultAllowedHttpMethods ();
106
106
107
107
private Predicate <String > allowedHostnames = hostname -> true ;
108
108
109
109
public StrictHttpFirewall () {
110
- urlBlacklistsAddAll (FORBIDDEN_SEMICOLON );
111
- urlBlacklistsAddAll (FORBIDDEN_FORWARDSLASH );
112
- urlBlacklistsAddAll (FORBIDDEN_DOUBLE_FORWARDSLASH );
113
- urlBlacklistsAddAll (FORBIDDEN_BACKSLASH );
114
-
115
- this .encodedUrlBlacklist .add (ENCODED_PERCENT );
116
- this .encodedUrlBlacklist .addAll (FORBIDDEN_ENCODED_PERIOD );
117
- this .decodedUrlBlacklist .add (PERCENT );
110
+ urlBlocklistsAddAll (FORBIDDEN_SEMICOLON );
111
+ urlBlocklistsAddAll (FORBIDDEN_FORWARDSLASH );
112
+ urlBlocklistsAddAll (FORBIDDEN_DOUBLE_FORWARDSLASH );
113
+ urlBlocklistsAddAll (FORBIDDEN_BACKSLASH );
114
+
115
+ this .encodedUrlBlocklist .add (ENCODED_PERCENT );
116
+ this .encodedUrlBlocklist .addAll (FORBIDDEN_ENCODED_PERIOD );
117
+ this .decodedUrlBlocklist .add (PERCENT );
118
118
}
119
119
120
120
/**
@@ -185,9 +185,9 @@ public void setAllowedHttpMethods(Collection<String> allowedHttpMethods) {
185
185
*/
186
186
public void setAllowSemicolon (boolean allowSemicolon ) {
187
187
if (allowSemicolon ) {
188
- urlBlacklistsRemoveAll (FORBIDDEN_SEMICOLON );
188
+ urlBlocklistsRemoveAll (FORBIDDEN_SEMICOLON );
189
189
} else {
190
- urlBlacklistsAddAll (FORBIDDEN_SEMICOLON );
190
+ urlBlocklistsAddAll (FORBIDDEN_SEMICOLON );
191
191
}
192
192
}
193
193
@@ -208,9 +208,9 @@ public void setAllowSemicolon(boolean allowSemicolon) {
208
208
*/
209
209
public void setAllowUrlEncodedSlash (boolean allowUrlEncodedSlash ) {
210
210
if (allowUrlEncodedSlash ) {
211
- urlBlacklistsRemoveAll (FORBIDDEN_FORWARDSLASH );
211
+ urlBlocklistsRemoveAll (FORBIDDEN_FORWARDSLASH );
212
212
} else {
213
- urlBlacklistsAddAll (FORBIDDEN_FORWARDSLASH );
213
+ urlBlocklistsAddAll (FORBIDDEN_FORWARDSLASH );
214
214
}
215
215
}
216
216
@@ -225,9 +225,9 @@ public void setAllowUrlEncodedSlash(boolean allowUrlEncodedSlash) {
225
225
*/
226
226
public void setAllowUrlEncodedDoubleSlash (boolean allowUrlEncodedDoubleSlash ) {
227
227
if (allowUrlEncodedDoubleSlash ) {
228
- urlBlacklistsRemoveAll (FORBIDDEN_DOUBLE_FORWARDSLASH );
228
+ urlBlocklistsRemoveAll (FORBIDDEN_DOUBLE_FORWARDSLASH );
229
229
} else {
230
- urlBlacklistsAddAll (FORBIDDEN_DOUBLE_FORWARDSLASH );
230
+ urlBlocklistsAddAll (FORBIDDEN_DOUBLE_FORWARDSLASH );
231
231
}
232
232
}
233
233
@@ -250,9 +250,9 @@ public void setAllowUrlEncodedDoubleSlash(boolean allowUrlEncodedDoubleSlash) {
250
250
*/
251
251
public void setAllowUrlEncodedPeriod (boolean allowUrlEncodedPeriod ) {
252
252
if (allowUrlEncodedPeriod ) {
253
- this .encodedUrlBlacklist .removeAll (FORBIDDEN_ENCODED_PERIOD );
253
+ this .encodedUrlBlocklist .removeAll (FORBIDDEN_ENCODED_PERIOD );
254
254
} else {
255
- this .encodedUrlBlacklist .addAll (FORBIDDEN_ENCODED_PERIOD );
255
+ this .encodedUrlBlocklist .addAll (FORBIDDEN_ENCODED_PERIOD );
256
256
}
257
257
}
258
258
@@ -275,9 +275,9 @@ public void setAllowUrlEncodedPeriod(boolean allowUrlEncodedPeriod) {
275
275
*/
276
276
public void setAllowBackSlash (boolean allowBackSlash ) {
277
277
if (allowBackSlash ) {
278
- urlBlacklistsRemoveAll (FORBIDDEN_BACKSLASH );
278
+ urlBlocklistsRemoveAll (FORBIDDEN_BACKSLASH );
279
279
} else {
280
- urlBlacklistsAddAll (FORBIDDEN_BACKSLASH );
280
+ urlBlocklistsAddAll (FORBIDDEN_BACKSLASH );
281
281
}
282
282
}
283
283
@@ -297,11 +297,11 @@ public void setAllowBackSlash(boolean allowBackSlash) {
297
297
*/
298
298
public void setAllowUrlEncodedPercent (boolean allowUrlEncodedPercent ) {
299
299
if (allowUrlEncodedPercent ) {
300
- this .encodedUrlBlacklist .remove (ENCODED_PERCENT );
301
- this .decodedUrlBlacklist .remove (PERCENT );
300
+ this .encodedUrlBlocklist .remove (ENCODED_PERCENT );
301
+ this .decodedUrlBlocklist .remove (PERCENT );
302
302
} else {
303
- this .encodedUrlBlacklist .add (ENCODED_PERCENT );
304
- this .decodedUrlBlacklist .add (PERCENT );
303
+ this .encodedUrlBlocklist .add (ENCODED_PERCENT );
304
+ this .decodedUrlBlocklist .add (PERCENT );
305
305
}
306
306
}
307
307
@@ -320,20 +320,20 @@ public void setAllowedHostnames(Predicate<String> allowedHostnames) {
320
320
this .allowedHostnames = allowedHostnames ;
321
321
}
322
322
323
- private void urlBlacklistsAddAll (Collection <String > values ) {
324
- this .encodedUrlBlacklist .addAll (values );
325
- this .decodedUrlBlacklist .addAll (values );
323
+ private void urlBlocklistsAddAll (Collection <String > values ) {
324
+ this .encodedUrlBlocklist .addAll (values );
325
+ this .decodedUrlBlocklist .addAll (values );
326
326
}
327
327
328
- private void urlBlacklistsRemoveAll (Collection <String > values ) {
329
- this .encodedUrlBlacklist .removeAll (values );
330
- this .decodedUrlBlacklist .removeAll (values );
328
+ private void urlBlocklistsRemoveAll (Collection <String > values ) {
329
+ this .encodedUrlBlocklist .removeAll (values );
330
+ this .decodedUrlBlocklist .removeAll (values );
331
331
}
332
332
333
333
@ Override
334
334
public FirewalledRequest getFirewalledRequest (HttpServletRequest request ) throws RequestRejectedException {
335
335
rejectForbiddenHttpMethod (request );
336
- rejectedBlacklistedUrls (request );
336
+ rejectedBlocklistedUrls (request );
337
337
rejectedUntrustedHosts (request );
338
338
339
339
if (!isNormalized (request )) {
@@ -363,13 +363,13 @@ private void rejectForbiddenHttpMethod(HttpServletRequest request) {
363
363
}
364
364
}
365
365
366
- private void rejectedBlacklistedUrls (HttpServletRequest request ) {
367
- for (String forbidden : this .encodedUrlBlacklist ) {
366
+ private void rejectedBlocklistedUrls (HttpServletRequest request ) {
367
+ for (String forbidden : this .encodedUrlBlocklist ) {
368
368
if (encodedUrlContains (request , forbidden )) {
369
369
throw new RequestRejectedException ("The request was rejected because the URL contained a potentially malicious String \" " + forbidden + "\" " );
370
370
}
371
371
}
372
- for (String forbidden : this .decodedUrlBlacklist ) {
372
+ for (String forbidden : this .decodedUrlBlocklist ) {
373
373
if (decodedUrlContains (request , forbidden )) {
374
374
throw new RequestRejectedException ("The request was rejected because the URL contained a potentially malicious String \" " + forbidden + "\" " );
375
375
}
@@ -481,20 +481,41 @@ private static boolean isNormalized(String path) {
481
481
}
482
482
483
483
/**
484
- * Provides the existing encoded url blacklist which can add/remove entries from
484
+ * Provides the existing encoded url blocklist which can add/remove entries from
485
485
*
486
- * @return the existing encoded url blacklist , never null
486
+ * @return the existing encoded url blocklist , never null
487
487
*/
488
+ public Set <String > getEncodedUrlBlocklist () {
489
+ return this .encodedUrlBlocklist ;
490
+ }
491
+
492
+ /**
493
+ * Provides the existing decoded url blocklist which can add/remove entries from
494
+ *
495
+ * @return the existing decoded url blocklist, never null
496
+ */
497
+ public Set <String > getDecodedUrlBlocklist () {
498
+ return this .decodedUrlBlocklist ;
499
+ }
500
+
501
+ /**
502
+ * Provides the existing encoded url blocklist which can add/remove entries from
503
+ *
504
+ * @return the existing encoded url blocklist, never null
505
+ * @deprecated Use {@link #getEncodedUrlBlocklist()} instead
506
+ */
507
+ @ Deprecated
488
508
public Set <String > getEncodedUrlBlacklist () {
489
- return encodedUrlBlacklist ;
509
+ return getEncodedUrlBlocklist () ;
490
510
}
491
511
492
512
/**
493
- * Provides the existing decoded url blacklist which can add/remove entries from
513
+ * Provides the existing decoded url blocklist which can add/remove entries from
514
+ *
515
+ * @return the existing decoded url blocklist, never null
494
516
*
495
- * @return the existing decoded url blacklist, never null
496
517
*/
497
518
public Set <String > getDecodedUrlBlacklist () {
498
- return decodedUrlBlacklist ;
519
+ return getDecodedUrlBlocklist () ;
499
520
}
500
521
}
0 commit comments