J4.x: gestione delle intestazioni HTTP
From Joomla! Documentation
Come utilizzare la nuova gestione delle intestazioni HTTP in Joomla 4.0
A partire da Joomla 4.0, Joomla ha introdotto un sistema di gestione delle intestazioni HTTP. Questo sistema è progettato per aiutare i proprietari di siti a configurare le intestazioni di sicurezza HTTP dal back-end
In questo tutorial, troverai informazioni su come impostare questo nuovo sistema sul tuo sito.
Plugin
Intestazioni HTTP (plg_system_httpheaders)
Passare a Sistema → Plugin → Sistema - Intestazioni HTTP per accedere alla configurazione del plug-in.
Configurazione plugin
Da questa pagina è possibile scegliere di abilitare la scrittura delle intestazioni nei file di configurazione del server (.htaccess e web.config) e configurare se le seguenti intestazioni http sono abilitate
Utilizzando il modulo "Intestazione aggiuntiva" puoi anche configurare le seguenti intestazioni con i suoi valori:
- Strict-Transport-Security
- Content-Security-Policy
- Content-Security-Policy-Report-Only
- Expect-CT
- Feature-Policy & Permissions-Policy
- Report-to
Configurazione Strict-Transport-Security (HSTS)
Da questa pagina è possibile scegliere di abilitare l'intestazione Strict-Transport-Security (HSTS) e configurare il valore di età massima se includere sottodomini e se si desidera aggiungere all'elenco di precaricamento del browser.
Content-Security-Policy (CSP) Configuration
From this page you can choose to enable and configure the Content-Security-Policy (CSP) header set by the plugin.
Once enabled you can set the client where you want to enforce the configured CSP on, allowing you to set set "site", "administrator" or "both".
The following settings need a bit more explanation, thats also the reason there are additional descriptions on all of them.
The final option called "Add Directive" allows you to configure the allowlist per directive as you need them. For example the directive "script-src" where the option "Value" you enter the origins you want to allow to load scripts from.
Notes
When you have configured some HTTP Security Headers directly on the server, then our tooling might create double entries.
Check the output of your HTTP Headers after configuring in the browser console. In Google Chrome: Inspect > Network > the output under Headers). You can than disable the headers that cause double entries. Also check the console of your browser for possible errors.
Sviluppatori di estensioni
Come forse saprai, il grande vantaggio in termini di sicurezza relativo alle Norme sulla sicurezza dei contenuti si manifesta quando possiamo usare l'intestazione per bloccare JavaScript inline e CSS inline. So with this browser protection enabled we will block inline JavaScript and inline CSS usage also for your extensions. That protection is not enabled by default but can be enabled by your users.
For 4.0 it would be recommended to get the frontend of your extension running with strict Content Security Policy enabled. For 4.1 compatibility it would be recommended that this also applies to your backend.
Ma sappiamo anche che è ancora necessario avere JavaScript e CSS incorporati, per questo motivo abbiamo implementato un supporto nonce nelle nostre API JavaScript e CSS utilizzando questo nonce possiamo ancora autorizzare i tuoi JavaScript e CSS incorporati ma ancora bloccare quelli dannosi per proteggere i nostri siti.
Important notes for Extension Developers
Starting with Joomla 4.0 Content Security Policy:
- is shipped by the core
- is disabled by default
- can be enabled by your users
- it is strongly recommended that your extension frontend works by 4.0 with Content Security Policy enabled
- it is recommended that your extension backend works by 4.1 with Content Security Policy enabled
With strict Content Security Policy enabled the following features will be blocked:
- the execution of JavaScript via the HTML event handlers (onXXX handlers like onClick and similar)
- the execution of in-page JavaScript not passed to the page via the Document API
- the execution of JavaScript code injected into DOM APIs such as eval()
- the usage of inline in-page CSS not passed to the page via the Document API
- the usage of inline CSS using the HTML style attribute
Affinché le estensioni funzionino anche con la rigorosa politica di sicurezza dei contenuti abilitata, il modo più semplice è utilizzare l'API Joomla per applicare JavaScript e CSS in linea, controlla gli esempi di seguito.
Aggiunta di JavaScript mediante l'API Joomla
use Joomla\CMS\Factory;
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// Add JavaScript from URL
$wa->registerAndUseScript('com_example.sample', 'https://example.org/sample.js', [], ['defer' => true]);
// Add inline JavaScript
$wa->addInlineScript('
document.addEventListener("DOMContentLoaded", function(event) {
alert("An inline JavaScript Declaration");
});
');
Aggiunta di CSS mediante l'API Joomla
use Joomla\CMS\Factory;
/** @var Joomla\CMS\WebAsset\WebAssetManager $wa */
$wa = Factory::getApplication()->getDocument()->getWebAssetManager();
// Add Style from URL
$wa->registerAndUseStyle('com_example.sample', 'https://example.org/sample.css');
// Add inline Style
$wa->addInlineStyle('
body {
background: #00ff00;
color: rgb(0,0,255);
}
');
Maggiori dettagli possono essere trovati qui:Aggiunta di JavaScript e CSS alla pagina