Configura un Content Security Policy (CSP) per tutte le pagine del portale per proteggerti da attacchi cross-site scripting (XSS) e altri attacchi di iniezione di codice. La
CSP definisce origini attendibili per i contenuti, ad esempio script, stili e immagini.
Dopo aver configurato una policy, i contenuti caricati da origini non attendibili verranno bloccati dal browser.
CSP viene aggiunto come intestazione della risposta HTTP Content-Security-Policy a tutte le pagine del portale, come segue:
Se attivi l'intestazione CSP, per impostazione predefinita viene definita la seguente direttiva CSP:
default-src 'unsafe-eval' 'unsafe-inline' * data:
L'istruzione default-src configura il criterio predefinito per i tipi di risorse che non hanno un'istruzione configurata.
La tabella seguente descrive le norme definite nell'ambito della direttiva predefinita.
Norme
Accesso
'unsafe-inline'
Risorse incorporate, come elementi <script> incorporati, URL javascript:, gestori di eventi incorporati ed elementi <style> incorporati. Nota: devi racchiudere il criterio tra virgolette singole.
'unsafe-eval'
Valutazione di codice dinamico non sicuro, ad esempio eval() JavaScript e metodi simili utilizzati per creare codice da stringhe. Nota: devi racchiudere il criterio tra virgolette singole.
* (wildcard)
Qualsiasi URL, ad eccezione degli schemi data:, blob: e filesystem:.
data:
Risorse caricate tramite lo schema dati (ad esempio, immagini codificate Base64).
Di seguito sono riportati esempi di configurazione di CSP per limitare tipi di risorse specifici.
Norme
Accesso
default-src 'none'
Nessun accesso per i tipi di risorse che non hanno un'istruzione configurata.
img-src *
URL dell'immagine da qualsiasi origine.
media-src https://example.com/
URL video o audio tramite HTTPS dal dominio example.com.
script-src *.example.com
Esecuzione di qualsiasi script da un sottodominio di example.com.
style-src 'self' css.example.com
Applicazione di qualsiasi stile dall'origine del sito o dal dominio css.example.com.
Per configurare una policy di sicurezza dei contenuti:
UI di Cloud Console
Nella console Apigee in Cloud, vai alla pagina Distribuzione > Portali.
[[["Facile da capire","easyToUnderstand","thumb-up"],["Il problema è stato risolto","solvedMyProblem","thumb-up"],["Altra","otherUp","thumb-up"]],[["Difficile da capire","hardToUnderstand","thumb-down"],["Informazioni o codice di esempio errati","incorrectInformationOrSampleCode","thumb-down"],["Mancano le informazioni o gli esempi di cui ho bisogno","missingTheInformationSamplesINeed","thumb-down"],["Problema di traduzione","translationIssue","thumb-down"],["Altra","otherDown","thumb-down"]],["Ultimo aggiornamento 2025-09-04 UTC."],[[["\u003cp\u003eThis page details how to configure a Content Security Policy (CSP) for Apigee and Apigee hybrid portals to guard against cross-site scripting (XSS) and code-injection attacks.\u003c/p\u003e\n"],["\u003cp\u003eThe CSP, added as a \u003ccode\u003eContent-Security-Policy\u003c/code\u003e HTTP response header, defines trusted sources for content and uses directives like \u003ccode\u003edefault-src\u003c/code\u003e, \u003ccode\u003eimg-src\u003c/code\u003e, and \u003ccode\u003escript-src\u003c/code\u003e to manage access.\u003c/p\u003e\n"],["\u003cp\u003eBy default, enabling CSP sets the \u003ccode\u003edefault-src\u003c/code\u003e directive to allow \u003ccode\u003e'unsafe-eval'\u003c/code\u003e, \u003ccode\u003e'unsafe-inline'\u003c/code\u003e, \u003ccode\u003e*\u003c/code\u003e, and \u003ccode\u003edata:\u003c/code\u003e, but you can modify this for more specific access control.\u003c/p\u003e\n"],["\u003cp\u003eTo configure the CSP, you must navigate through the portal's settings under the Security tab and enable the content security policy.\u003c/p\u003e\n"],["\u003cp\u003eYou can revert to the default CSP settings at any time by clicking the "Restore default" button.\u003c/p\u003e\n"]]],[],null,["# Configure a content security policy\n\n*This page\napplies to **Apigee** and **Apigee hybrid**.*\n\n\n*View [Apigee Edge](https://docs.apigee.com/api-platform/get-started/what-apigee-edge) documentation.*\n\n\u003cbr /\u003e\n\nConfigure a content security policy (CSP) for all pages in your portal to\nprotect against cross-site scripting (XSS) and other code-injection attacks. The\nCSP defines trusted sources for content such as scripts, styles, and images.\nAfter configuring a policy, content loaded from untrusted sources will be\nblocked by your browser.\n\nThe CSP is added as a `Content-Security-Policy` HTTP response header to all\npages in your portal, as follows:\n\n`Content-Security-Policy: `*policy*\n\nYou define the policy using directives, as defined in\n[Content Security Policy Directives](https://www.w3.org/TR/CSP3/#csp-directives) in the W3C site.\n\nIf you enable the CSP header, by default the following CSP directive is defined:\n\n`default-src 'unsafe-eval' 'unsafe-inline' * data:`\n\nThe `default-src` directive configures the default policy for\nresource types that do not have a configured directive.\n| Apigee recommends that you define a default directive as part of the CSP to configure the minimum restrictions.\n\nThe following table describes the policies defined as part of the default directive.\n\nThe following provides examples of configuring the CSP to restrict specific resource types.\n\nTo configure a content security policy: \n\n### Cloud Console UI\n\n1. In the Apigee in Cloud console, go to the **Distribution \\\u003e Portals** page.\n\n [Go to Portals](https://console.cloud.google.com/apigee/portals)\n2. Click your portal.\n\n3. Click **Settings** in the navigation menu.\n\n4. Click the **Security** tab.\n\n5. Click **Enable content security policy**.\n\n6. Configure the CSP or leave the default.\n\n7. Click **Save**.\n\n### Classic UI\n\n1. Select **Publish \\\u003e Portals** and select your portal.\n2. Select **Settings** in the drop-down menu in the top navigation bar.\n3. Alternatively, click **Settings** on the portal landing page.\n4. Click the **Security** tab.\n5. Click **Enable content security policy**.\n6. Configure the CSP or leave the default.\n7. Click **Save**.\n\nYou can restore the default CSP policy at any time by clicking **Restore default**."]]