Konfigurasi kebijakan keamanan konten (CSP) untuk semua halaman di portal Anda guna melindungi dari serangan pembuatan skrip lintas situs (XSS) dan serangan injeksi kode lainnya. CSP menentukan sumber tepercaya untuk konten seperti skrip, gaya, dan gambar.
Setelah mengonfigurasi kebijakan, konten yang dimuat dari sumber yang tidak tepercaya akan
diblokir oleh browser Anda.
CSP ditambahkan sebagai header respons HTTP Content-Security-Policy ke semua
halaman di portal Anda, sebagai berikut:
Jika Anda mengaktifkan header CSP, secara default, perintah CSP berikut akan ditentukan:
default-src 'unsafe-eval' 'unsafe-inline' * data:
Perintah default-src mengonfigurasi kebijakan default untuk
jenis resource yang tidak memiliki perintah yang dikonfigurasi.
Tabel berikut menjelaskan kebijakan yang ditentukan sebagai bagian dari direktif default.
Kebijakan
Akses
'unsafe-inline'
Resource inline, seperti elemen <script> inline, URL javascript:, pengendali peristiwa inline, dan elemen <style> inline. Catatan: Anda harus menyertakan kebijakan dalam tanda kutip tunggal.
'unsafe-eval'
Evaluasi kode dinamis yang tidak aman seperti eval() JavaScript dan metode serupa yang digunakan untuk membuat kode dari string. Catatan: Anda harus menyertakan kebijakan dalam tanda kutip tunggal.
* (wildcard)
URL apa pun kecuali skema data:, blob:, dan filesystem:.
data:
Resource yang dimuat melalui skema data (misalnya, gambar berenkode Base64).
Berikut ini contoh konfigurasi CSP untuk membatasi jenis resource tertentu.
Kebijakan
Akses
default-src 'none'
Tidak ada akses untuk jenis resource yang tidak memiliki perintah yang dikonfigurasi.
img-src *
URL gambar dari sumber mana pun.
media-src https://example.com/
URL video atau audio melalui HTTPS dari domain example.com.
script-src *.example.com
Eksekusi skrip apa pun dari subdomain example.com.
style-src 'self' css.example.com
Penerapan gaya apa pun dari asal situs atau domain css.example.com.
Untuk mengonfigurasi kebijakan keamanan konten:
UI Konsol Cloud
Di konsol Apigee di Cloud, buka halaman Distribution > Portals.
[[["Mudah dipahami","easyToUnderstand","thumb-up"],["Memecahkan masalah saya","solvedMyProblem","thumb-up"],["Lainnya","otherUp","thumb-up"]],[["Sulit dipahami","hardToUnderstand","thumb-down"],["Informasi atau kode contoh salah","incorrectInformationOrSampleCode","thumb-down"],["Informasi/contoh yang saya butuhkan tidak ada","missingTheInformationSamplesINeed","thumb-down"],["Masalah terjemahan","translationIssue","thumb-down"],["Lainnya","otherDown","thumb-down"]],["Terakhir diperbarui pada 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**."]]