Skip to content

Commit

Permalink
Replace "whitelist" with alternative words
Browse files Browse the repository at this point in the history
  • Loading branch information
rstoyanchev committed Jun 8, 2020
1 parent 4c29bbb commit a2d516d
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -361,7 +361,7 @@ void registerAdapters(ReactiveAdapterRegistry registry) {

/**
* {@code BlockHoundIntegration} for spring-core classes.
* <p>Whitelists the following:
* <p>Explicitly allow the following:
* <ul>
* <li>Reading class info via {@link LocalVariableTableParameterNameDiscoverer}.
* <li>Locking within {@link ConcurrentReferenceHashMap}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ public void setFavorPathExtension(boolean favorPathExtension) {
* {@code ResourceHttpRequestHandler}.
* <li>Determine the media type of views rendered with
* {@code ContentNegotiatingViewResolver}.
* <li>Whitelist extensions for RFD attack detection (check the Spring
* <li>List safe extensions for RFD attack detection (check the Spring
* Framework reference docs for details).
* </ul>
* @param mediaTypes media type mappings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public ContentNegotiationConfigurer favorPathExtension(boolean favorPathExtensio
* Add a mapping from a key, extracted from a path extension or a query
* parameter, to a MediaType. This is required in order for the parameter
* strategy to work. Any extensions explicitly registered here are also
* whitelisted for the purpose of Reflected File Download attack detection
* (see Spring Framework reference documentation for more details on RFD
* attack protection).
* treated as safe for the purpose of Reflected File Download attack
* detection (see Spring Framework reference documentation for more details
* on RFD attack protection).
* <p>The path extension strategy will also try to use
* {@link ServletContext#getMimeType} and {@link MediaTypeFactory} to resolve path
* extensions. To change this behavior see the {@link #useRegisteredExtensionsOnly} property.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,12 @@ public abstract class AbstractMessageConverterMethodProcessor extends AbstractMe
implements HandlerMethodReturnValueHandler {

/* Extensions associated with the built-in message converters */
private static final Set<String> WHITELISTED_EXTENSIONS = new HashSet<>(Arrays.asList(
private static final Set<String> SAFE_EXTENSIONS = new HashSet<>(Arrays.asList(
"txt", "text", "yml", "properties", "csv",
"json", "xml", "atom", "rss",
"png", "jpe", "jpeg", "jpg", "gif", "wbmp", "bmp"));

private static final Set<String> WHITELISTED_MEDIA_BASE_TYPES = new HashSet<>(
private static final Set<String> SAFE_MEDIA_BASE_TYPES = new HashSet<>(
Arrays.asList("audio", "image", "video"));

private static final List<MediaType> ALL_APPLICATION_MEDIA_TYPES =
Expand Down Expand Up @@ -133,7 +133,7 @@ protected AbstractMessageConverterMethodProcessor(List<HttpMessageConverter<?>>

this.contentNegotiationManager = (manager != null ? manager : new ContentNegotiationManager());
this.safeExtensions.addAll(this.contentNegotiationManager.getAllFileExtensions());
this.safeExtensions.addAll(WHITELISTED_EXTENSIONS);
this.safeExtensions.addAll(SAFE_EXTENSIONS);
}


Expand Down Expand Up @@ -406,8 +406,8 @@ private MediaType getMostSpecificMediaType(MediaType acceptType, MediaType produ
}

/**
* Check if the path has a file extension and whether the extension is
* either {@link #WHITELISTED_EXTENSIONS whitelisted} or explicitly
* Check if the path has a file extension and whether the extension is either
* on the list of {@link #SAFE_EXTENSIONS safe extensions} or explicitly
* {@link ContentNegotiationManager#getAllFileExtensions() registered}.
* If not, and the status is in the 2xx range, a 'Content-Disposition'
* header with a safe attachment file name ("f.txt") is added to prevent
Expand Down Expand Up @@ -491,7 +491,7 @@ private MediaType resolveMediaType(ServletRequest request, String extension) {
}

private boolean safeMediaType(MediaType mediaType) {
return (WHITELISTED_MEDIA_BASE_TYPES.contains(mediaType.getType()) ||
return (SAFE_MEDIA_BASE_TYPES.contains(mediaType.getType()) ||
mediaType.getSubtype().endsWith("+xml"));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,15 +380,15 @@ public void addContentDispositionHeader() throws Exception {
Collections.singletonList(new StringHttpMessageConverter()),
factory.getObject());

assertContentDisposition(processor, false, "/hello.json", "whitelisted extension");
assertContentDisposition(processor, false, "/hello.json", "safe extension");
assertContentDisposition(processor, false, "/hello.pdf", "registered extension");
assertContentDisposition(processor, true, "/hello.dataless", "unknown extension");

// path parameters
assertContentDisposition(processor, false, "/hello.json;a=b", "path param shouldn't cause issue");
assertContentDisposition(processor, true, "/hello.json;a=b;setup.dataless", "unknown ext in path params");
assertContentDisposition(processor, true, "/hello.dataless;a=b;setup.json", "unknown ext in filename");
assertContentDisposition(processor, false, "/hello.json;a=b;setup.json", "whitelisted extensions");
assertContentDisposition(processor, false, "/hello.json;a=b;setup.json", "safe extensions");

// encoded dot
assertContentDisposition(processor, true, "/hello%2Edataless;a=b;setup.json", "encoded dot in filename");
Expand Down
8 changes: 4 additions & 4 deletions src/docs/asciidoc/web/webmvc.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -1737,11 +1737,11 @@ lower the risk but are not sufficient to prevent RFD attacks.

To prevent RFD attacks, prior to rendering the response body, Spring MVC adds a
`Content-Disposition:inline;filename=f.txt` header to suggest a fixed and safe download
file. This is done only if the URL path contains a file extension that is neither whitelisted
nor explicitly registered for content negotiation. However, it can potentially have
side effects when URLs are typed directly into a browser.
file. This is done only if the URL path contains a file extension that is neither
allowed as safe nor explicitly registered for content negotiation. However, it can
potentially have side effects when URLs are typed directly into a browser.

Many common path extensions are whitelisted by default. Applications with custom
Many common path extensions are allowed as safe by default. Applications with custom
`HttpMessageConverter` implementations can explicitly register file extensions for content
negotiation to avoid having a `Content-Disposition` header added for those extensions.
See <<mvc-config-content-negotiation>>.
Expand Down

0 comments on commit a2d516d

Please sign in to comment.