Penerapan Content Security Policy Agar Server Lebih Aman

Penerapan Content Security Policy Agar Server Lebih Aman
Content Security Policy atau CSP adalah pengaturan tambahan yang diterapkan melalui respon HTTP Headers. kegunaan dari CSP sendiri adalah untuk mencegah eksploitasi XSS maupun serangan dengan kode injeksi lainnya pada server. Dengan Content Security Policy kita bisa megatur sumber mana saja yang diijinkan untuk diload di server kita sehingga jika attacker mencoba menyisipkan kode exploit dari sumber yang tidak dipercaya makan browser akan memblokir.

Parameter yang Didukung :
Ada beberapa petunjuk yang tersedia untuk pemilik website yang ingin menerapkan Content Security Policy. Sebuah server juga dapat mendefinisikan beberapa arahan dalam header keamanan CSP. Berikut beberapa daftar yang disediakan oleh owasp.org :
  • default-src : Define loading policy for all resources type in case of a resource type dedicated directive is not defined (fallback),
  • script-src : Define which scripts the protected resource can execute,
  • object-src : Define from where the protected resource can load plugins,
  • style-src : Define which styles (CSS) the user applies to the protected resource,
  • img-src : Define from where the protected resource can load images,
  • media-src : Define from where the protected resource can load video and audio,
  • frame-src : Define from where the protected resource can embed frames,
  • frame-ancestors : Specifies valid parents that may embed a page using <frame>, <iframe>, <object>, <embed>, or <applet>.
  • font-src : Define from where the protected resource can load fonts,
  • connect-src : Define which URIs the protected resource can load using script interfaces,
  • form-action : Define which URIs can be used as the action of HTML form elements,
  • sandbox : Specifies an HTML sandbox policy that the user agent applies to the protected resource,
  • script-nonce : Define script execution by requiring the presence of the specified nonce on script elements,
  • plugin-types : Define the set of plugins that can be invoked by the protected resource by limiting the types of resources that can be embedded,
  • reflected-xss : Instructs a user agent to activate or deactivate any heuristics used to filter or block reflected cross-site scripting attacks, equivalent to the effects of the non-standard X-XSS-Protection header,
  • report-uri : Specifies a URI to which the user agent sends reports about policy violation

Membuat Content Security Policy
Oke kita langsung beri contohnya aja ya. Biar gak bingung.
Contoh 1
Content-Security-Policy: default-src https:
Kode CSP diatas memungkinkan browser untuk memuat semua sumber daya dari semua situs ber-ssl.
Contoh 2
Content-Security-Policy: script-src 'self' www.google-analytics.com linuxsec.org
CSP ini memungkinkan script yang diijinkan dieksekusi dari domain saat ini (didefinisikan dengan 'self'), google-analytics.com dan linuxsec.org .
Contoh 3
Content-Security-Policy: default-src 'self' *.zonawibu.net
CSP juga mendukung wildcard.Kode diatas memungkinkan script untuk dimuat dari situs saat ini dan semua subdomain zonawibu.net
Contoh Penerapan di Nginx dan Apache
Disini untuk penerapannya sebagai berikut.
Nginx
Edit file konfigurasi nginx kalian lalu masukkan CSP yang sudah kalian tentukan.
add_header Content-Security-Policy-Report-Only: "default-src 'none'; script-src https://zonawibu.net";
Apache
Edit file konfigurasi apache kalian lalu masukkan CSP yang sudah kalian tentukan.
Header set Content-Security-Policy-Report-Only "default-src 'none'; script-src https://zonawibu.net;"
Menerapkan Content Security Policy memang tidak menjamin 100% situs kalian aman dari peretasan. Namun tidak ada salahnya melakukan tindakan pencegahan untuk mengurangi resiko peretasan tersebut.
Sekian tutorial sederhana kali ini, jika ada yang kurang jelas silahkan bertanya.
Informasi

Dapatkan Tips Menarik Setiap Harinya!

  • Dapatkan tips dan trik yang belum pernah kamu tau sebelumnya
  • Jadilah orang pertama yang mengetahui hal-hal baru di dunia teknologi
  • Dapatkan Ebook Gratis: Cara Dapat 200 Juta / bulan dari AdSense

0 Response to "Penerapan Content Security Policy Agar Server Lebih Aman"

Post a Comment

Catatan Untuk Para Jejaker
  • Mohon Tinggalkan jejak sesuai dengan judul artikel.
  • Tidak diperbolehkan untuk mempromosikan barang atau berjualan.
  • Dilarang mencantumkan link aktif di komentar.
  • Komentar dengan link aktif akan otomatis dihapus
  • *Berkomentarlah dengan baik, Kepribadian Anda tercemin saat berkomentar.

Iklan Atas Artikel

Iklan Tengah Artikel 1

Iklan Tengah Artikel 2

Iklan Bawah Artikel