 
          
        Safe(r) User File Uploads /
Peter Wolanin
Scripts being served by a website can access that site as you by using session cookies
This is why XSS is dangerous
<html>
<body>
<script>
alert(document.cookie);
</script>
</body>
</html>
              $WEBSERVER to send nosniffhttps://soroush.secproject.com/blog/2014/05/even-uploading-a-jpg-file-can-lead-to-cross-domain-data-hijacking-client-side-attack/
A valid file upload like a .jpg can actually be flash content
Embedding with an OBJECT tag another site can enable CSRF and data hijacking
<IfModule mod_headers.c>
  <FilesMatch "\.(?i:pdf)$">
    ForceType application/octet-stream
    Header set Content-Disposition "attachment"
  </FilesMatch>
</IfModule>
              By using a different domain or subdomain you can avoid sending session cookies
For example, gmail attachments are served from https://mail-attachment.googleusercontent.com
Drupal 7 core issue: https://www.drupal.org/node/2522002
/**
 * Drupal automatically generates a unique session cookie name
 *  for each site based on its full domain name...
 */
# $cookie_domain = 'example.com';
              
function mymodule_file_url_alter(&$uri) {
  if (file_uri_scheme($uri) == 'public') {
    $wrapper = file_stream_wrapper_get_instance_by_scheme($scheme);
    $path = $wrapper->getDirectoryPath();
    $path .= '/' . file_uri_target($uri);
    $uri = 'http://downloads.drupal-7.local:8083/' . $path;
  }
}
              
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule . - [F]
              It's important to configure your site to respond to only the expected domains
See: https://www.drupal.org/node/1992030