ResponseHeadersXSSProtection
- class aws_cdk.aws_cloudfront.ResponseHeadersXSSProtection(*, override, protection, mode_block=None, report_uri=None)
Bases:
object
Determines whether CloudFront includes the X-XSS-Protection HTTP response header and the header’s value.
- Parameters:
override (
bool
) – A Boolean that determines whether CloudFront overrides the X-XSS-Protection HTTP response header received from the origin with the one specified in this response headers policy.protection (
bool
) – A Boolean that determines the value of the X-XSS-Protection HTTP response header. When this setting is true, the value of the X-XSS-Protection header is 1. When this setting is false, the value of the X-XSS-Protection header is 0.mode_block (
Optional
[bool
]) – A Boolean that determines whether CloudFront includes the mode=block directive in the X-XSS-Protection header. Default: falsereport_uri (
Optional
[str
]) – A reporting URI, which CloudFront uses as the value of the report directive in the X-XSS-Protection header. You cannot specify a ReportUri when ModeBlock is true. Default: - no report uri
- ExampleMetadata:
infused
Example:
# Using an existing managed response headers policy # bucket_origin: origins.S3Origin cloudfront.Distribution(self, "myDistManagedPolicy", default_behavior=cloudfront.BehaviorOptions( origin=bucket_origin, response_headers_policy=cloudfront.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS ) ) # Creating a custom response headers policy -- all parameters optional my_response_headers_policy = cloudfront.ResponseHeadersPolicy(self, "ResponseHeadersPolicy", response_headers_policy_name="MyPolicy", comment="A default policy", cors_behavior=cloudfront.ResponseHeadersCorsBehavior( access_control_allow_credentials=False, access_control_allow_headers=["X-Custom-Header-1", "X-Custom-Header-2"], access_control_allow_methods=["GET", "POST"], access_control_allow_origins=["*"], access_control_expose_headers=["X-Custom-Header-1", "X-Custom-Header-2"], access_control_max_age=Duration.seconds(600), origin_override=True ), custom_headers_behavior=cloudfront.ResponseCustomHeadersBehavior( custom_headers=[cloudfront.ResponseCustomHeader(header="X-Amz-Date", value="some-value", override=True), cloudfront.ResponseCustomHeader(header="X-Amz-Security-Token", value="some-value", override=False) ] ), security_headers_behavior=cloudfront.ResponseSecurityHeadersBehavior( content_security_policy=cloudfront.ResponseHeadersContentSecurityPolicy(content_security_policy="default-src https:;", override=True), content_type_options=cloudfront.ResponseHeadersContentTypeOptions(override=True), frame_options=cloudfront.ResponseHeadersFrameOptions(frame_option=cloudfront.HeadersFrameOption.DENY, override=True), referrer_policy=cloudfront.ResponseHeadersReferrerPolicy(referrer_policy=cloudfront.HeadersReferrerPolicy.NO_REFERRER, override=True), strict_transport_security=cloudfront.ResponseHeadersStrictTransportSecurity(access_control_max_age=Duration.seconds(600), include_subdomains=True, override=True), xss_protection=cloudfront.ResponseHeadersXSSProtection(protection=True, mode_block=False, report_uri="https://example.com/csp-report", override=True) ), remove_headers=["Server"], server_timing_sampling_rate=50 ) cloudfront.Distribution(self, "myDistCustomPolicy", default_behavior=cloudfront.BehaviorOptions( origin=bucket_origin, response_headers_policy=my_response_headers_policy ) )
Attributes
- mode_block
A Boolean that determines whether CloudFront includes the mode=block directive in the X-XSS-Protection header.
- Default:
false
- override
A Boolean that determines whether CloudFront overrides the X-XSS-Protection HTTP response header received from the origin with the one specified in this response headers policy.
- protection
A Boolean that determines the value of the X-XSS-Protection HTTP response header.
When this setting is true, the value of the X-XSS-Protection header is 1. When this setting is false, the value of the X-XSS-Protection header is 0.
- report_uri
A reporting URI, which CloudFront uses as the value of the report directive in the X-XSS-Protection header.
You cannot specify a ReportUri when ModeBlock is true.
- Default:
no report uri