

# CloudFront Functions 뷰어 응답 이벤트에 HTTP 보안 헤더 추가
<a name="example_cloudfront_functions_add_security_headers_section"></a>

다음 코드 예제에서는 CloudFront Functions 뷰어 응답 이벤트에 HTTP 보안 헤더를 추가하는 방법을 보여줍니다.

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

**CloudFront Functions를 위한 JavaScript 런타임 2.0**  
 GitHub에 더 많은 내용이 있습니다. [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;
}
```

------

AWS SDK 개발자 가이드 및 코드 예제의 전체 목록은 [AWS SDK와 함께 CloudFront 사용](sdk-general-information-section.md)을 참조하세요. 이 주제에는 시작하기에 대한 정보와 이전 SDK 버전에 대한 세부 정보도 포함되어 있습니다.