X-Content-Type-Options header, Security issues

Hosting Mautic QuickStart -50% with support in Spanish
24 hours and free training

Send up to 1,000,000 emails/year. Mautic support in Spanish 24 hours, 365 days

If we send the header X-Content-Type-Options in the response with the “nosniff” value, browsers that support this header (IE and Chrome) do not load style sheets or scripts (Javascript) whose Myme-type is not appropriate.

The appearance of the header is as follows:

X-Content-Type-Options: nosniff

The best way to add this header would be to add a few lines of code to the file functions.php of the WordPress theme that we are using.

This file is located in the path wp-content/themes/THEME_NAMEwhere NAME_TOPIC is the name of the theme that we have activated.

First of all, we will make a backup copy of the functions.php file.

Then we edit it and add the following code at the end of it:

add_action( ‘send_headers’, ‘add_header_xcontenttype’ ); function add_header_xcontenttype() { header( ‘X-Content-Type-Options: nosniff’ ); }

There are other alternatives.

To implement the header in an Apache web server, it can be done using the .htaccess file, adding the following code:

Header set X-Content-Type-Options nosniff

With this header, the risk of an attack based on mime-type confusion is reduced.

In general, with the X-Content-Type-Options Header we will prevent malicious style sheets or scripts from being loaded.

You can read.

If we want to add other security headers from changes in the functions.php file, we can do it using a single function, instead of adding each header in a different function, although the behavior is similar.

See also  WordPress Backend What is it? and Best Plugins

In the following sample code, which should be placed at the end of the functions.php file, headers X-Content-Type-Options, X-Frame-Options and :

add_action( ‘send_headers’, ‘add_header_security’ ); function add_header_security() { header( ‘X-Content-Type-Options: nosniff’ ); header( ‘X-Frame-Options: SAMEORIGIN’ ); header( ‘X-XSS-Protection: 1;mode=block’ ); }

You can take a look at the following article about .

Help us improve our content by sharing your opinion

Member of the Systems Administration team at and leader of the CiberProtector and CiberBox development team.

Loading Facebook Comments ...
Loading Disqus Comments ...