

Terjemahan disediakan oleh mesin penerjemah. Jika konten terjemahan yang diberikan bertentangan dengan versi bahasa Inggris aslinya, utamakan versi bahasa Inggris.

# Tambahkan header keamanan HTTP ke acara respons penampil CloudFront Fungsi
<a name="example_cloudfront_functions_add_security_headers_section"></a>

Contoh kode berikut menunjukkan cara menambahkan header keamanan HTTP ke acara respons penampil CloudFront Fungsi.

------
#### [ JavaScript ]

**JavaScript runtime 2.0 untuk Fungsi CloudFront **  
 Ada lebih banyak tentang GitHub. Temukan contoh lengkapnya dan pelajari cara mengatur dan menjalankan di repositori [contoh CloudFront Functions](https://github.com/aws-samples/amazon-cloudfront-functions/tree/main/add-security-headers). 

```
async function handler(event) {
    var response = event.response;
    var headers = response.headers;

    // Set HTTP security headers
    // Since JavaScript doesn't allow for hyphens in variable names, we use the dict["key"] notation 
    headers['strict-transport-security'] = { value: 'max-age=63072000; includeSubdomains; preload'}; 
    headers['content-security-policy'] = { value: "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'; frame-ancestors 'none'"}; 
    headers['x-content-type-options'] = { value: 'nosniff'}; 
    headers['x-frame-options'] = {value: 'DENY'}; 
    headers['x-xss-protection'] = {value: '1; mode=block'};
    headers['referrer-policy'] = {value: 'same-origin'};
    
    // Return the response to viewers 
    return response;
}
```

------

Untuk daftar lengkap panduan pengembang AWS SDK dan contoh kode, lihat[Menggunakan CloudFront dengan AWS SDK](sdk-general-information-section.md). Topik ini juga mencakup informasi tentang memulai dan detail tentang versi SDK sebelumnya.