Es mostren els missatges amb l'etiqueta de comentaris .htaccess. Mostrar tots els missatges
Es mostren els missatges amb l'etiqueta de comentaris .htaccess. Mostrar tots els missatges

dimecres, 3 de març del 2021

Mozilla Observatory

 Hi ha una eina interesant de Mozilla per comprovar la seguretat d'una web. L'he provada amb una web pròpia i estava al nivell F. he seguit les suggerències de millora, i m'ha estat necessari revisar algunes recomanacions pel camí sobre .htaccess, php cookies, seguretat a wordpress, php.ini i més.

https://observatory.mozilla.org/analyze/

Prèviament ja tenia un certificat de seguretat implementat (Let's Encrypt)  i forçava https en lloc de http. Per exemple , amb un redirecció 301 de http a https

Seguin les recomanacions del Mozilla Observatory  he afegit el següent codi a .htaccess (al ser un hosting compartit) . La seguretat de la meva web ha passat del nivell F i 0/100 a nivell B i puntuació 70/100. No està gens malament per un parell d'hores de documentació i feina al servidor.

Fitxer .htaccess

Es tracta d'afegir aquest codi al fitxer .htaccess a l'arrel de la web. Aquestes son les opcions que m'han anat bé a mi.  

 # Security
<IfModule mod_headers.c>
Header set Strict-Transport-Security "max-age=63072000;"
Header set X-Content-Type-Options nosniff
Header always append X-Frame-Options SAMEORIGIN

Header always edit Set-Cookie (.*) "$1;HttpOnly;Secure"

Header set X-XSS-Protection "1; mode=block"
</IfModule>

 

Algunes aclaracions:

#Header set Strict-Transport-Security "max-age=63072000;"

Prova primer si et funciona la web escrivint max-age=300, que son 5 minuts. Si funciona correctament, en principi ho pots posar al valor definitiu.

#Header always edit Set-Cookie (.*) "$1;HttpOnly;Secure"

Aquesta opció Força les cookies amb httponly i secure encara que php.ini no sigui accesible o session_set_cookie_params no estigui utilitzada adecuadament en el PHP abans de session_start

 Referències

https://infosec.mozilla.org/guidelines/web_security#content-security-policy
https://developer.mozilla.org/es/docs/Web/HTTP/Headers
https://desarrollowp.com/blog/tutoriales/creando-el-htaccess-perfecto-para-wordpress/

divendres, 15 de novembre del 2013

Utilitzar la cache del navegador amb el nostre servidor

Un altre manera de agilitzar la càrrega de la nostra web és utilitzar la cache del nostre navegador. Afegint una data llunyana per actualitzar diversos fitxers (1 any) farem que no calgui tornar-los a carregar durant 1 any.

Per exemple, amb aquestes directives afegides al fitxer .htaccess.


## EXPIRES CACHING ##

ExpiresActive On
ExpiresByType image/jpg "access plus 1 year"
ExpiresByType image/jpeg "access plus 1 year"
ExpiresByType image/gif "access plus 1 year"
ExpiresByType image/png "access plus 1 year"
ExpiresByType text/css "access plus 1 month"
ExpiresByType application/pdf "access plus 1 month"
ExpiresByType text/x-javascript "access plus 1 month"
ExpiresByType application/x-shockwave-flash "access plus 1 month"
ExpiresByType image/x-icon "access plus 1 year"
ExpiresDefault "access plus 2 days"

## EXPIRES CACHING ##


Recursos
http://gtmetrix.com/leverage-browser-caching.html

Compresió amb GZip al servidor

Si teniu una web allotjada a un servidor podeu aconseguir millores en el temps de càrrega de les pàgines. (no és el cas d'un blog com aquest a Blogger). Per exemple, incloent la compresió de continguts pel servidor. En un servidor APACHE es pot utilitzar el CODI següent al fitxer




# compress text, html, javascript, css, xml:
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
AddType x-font/otf .otf AddType x-font/ttf .ttf
AddType x-font/eot .eot AddType x-font/woff .woff
AddType image/x-icon .ico AddType image/png .png



Aquest codi es coloca al fitxer .htaccess
Llegiu l'article  http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress
# compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddType x-font/otf .otf AddType x-font/ttf .ttf AddType x-font/eot .eot AddType x-font/woff .woff AddType image/x-icon .ico AddType image/png .png
Read more at http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress#l9WYQklgAK2uxwdy.99
# compress text, html, javascript, css, xml: AddOutputFilterByType DEFLATE text/plain AddOutputFilterByType DEFLATE text/html AddOutputFilterByType DEFLATE text/xml AddOutputFilterByType DEFLATE text/css AddOutputFilterByType DEFLATE application/xml AddOutputFilterByType DEFLATE application/xhtml+xml AddOutputFilterByType DEFLATE application/rss+xml AddOutputFilterByType DEFLATE application/javascript AddOutputFilterByType DEFLATE application/x-javascript AddType x-font/otf .otf AddType x-font/ttf .ttf AddType x-font/eot .eot AddType x-font/woff .woff AddType image/x-icon .ico AddType image/png .png
Read more at http://softstribe.com/wordpress/enable-gzip-compression-in-wordpress#l9WYQklgAK2uxwdy.99