P.Wiaderny (talk | contribs) (Created page with "When integrating CKFinder, you will often want to give users access to uploaded files, so they can insert images or links to files into the edited content. This requires to ma...") |
P.Wiaderny (talk | contribs) |
||
Line 4: | Line 4: | ||
To avoid content sniffing, you should make sure that your server adds the <code>X-Content-Type-Options: nosniff</code> header to all HTTP responses when serving files from the publicly available folder. The <code>X-Content-Type-Options</code> response HTTP header is a marker used by the server to indicate that the MIME type set by the <code>Content-Type</code> header should not be changed and should be followed. As a result, the browser does not perform any content sniffing on the received content. | To avoid content sniffing, you should make sure that your server adds the <code>X-Content-Type-Options: nosniff</code> header to all HTTP responses when serving files from the publicly available folder. The <code>X-Content-Type-Options</code> response HTTP header is a marker used by the server to indicate that the MIME type set by the <code>Content-Type</code> header should not be changed and should be followed. As a result, the browser does not perform any content sniffing on the received content. | ||
+ | |||
'''Apache''' | '''Apache''' | ||
Line 12: | Line 13: | ||
Header set X-Content-Type-Options "nosniff" | Header set X-Content-Type-Options "nosniff" | ||
</source> | </source> | ||
+ | |||
'''Nginx''' | '''Nginx''' |
Revision as of 11:23, 21 August 2019
When integrating CKFinder, you will often want to give users access to uploaded files, so they can insert images or links to files into the edited content. This requires to make the folder publicly accessible, so all the files are served through the web server. If you rely on your web server to serve the files uploaded with CKFinder, you should take additional steps to make sure the files are served in a secure way.
Let us assume that you have configured your CKFinder to allow uploading of avi files. Even if the avi file is then served with a valid Content-Type: video/x-msvideo
header, some browsers may ignore this information and perform additional checks on the raw file contents. If any HTML-like data is detected in the file content, the browser may decide to ignore information about the content type and handle the served content as if it was a regular web page. This behavior is called content sniffing (also known as media type sniffing or MIME sniffing), and in some circumstances, it may lead to security issues (for example, it may open door for XSS attacks)).
To avoid content sniffing, you should make sure that your server adds the X-Content-Type-Options: nosniff
header to all HTTP responses when serving files from the publicly available folder. The X-Content-Type-Options
response HTTP header is a marker used by the server to indicate that the MIME type set by the Content-Type
header should not be changed and should be followed. As a result, the browser does not perform any content sniffing on the received content.
Apache
If you use the Apache web server, you can add custom HTTP response headers using mod_headers. Make sure the mod_headers
module is enabled, and create (or modify) the following .htaccess
file in the root of the publicly accessible folder (for example userfiles/.htaccess
):
Header set X-Content-Type-Options "nosniff"
Nginx
If you use Nginx, custom HTTP response headers can be defined per location:
location /userfiles { add_header X-Content-Type-Options nosniff; }
Microsoft IIS
For Microsoft IIS servers, you can enable the X-Content-Type-Options
header in your web.config
file:
<system.webServer> <httpProtocol> <customHeaders> <remove name="X-Content-Type-Options"/> <add name="X-Content-Type-Options" value="nosniff"/> </customHeaders> </httpProtocol> </system.webServer>