aws-cdk-lib.aws_cloudfront.ResponseHeadersStrictTransportSecurity

interface ResponseHeadersStrictTransportSecurity

LanguageType name
.NETAmazon.CDK.AWS.CloudFront.ResponseHeadersStrictTransportSecurity
Gogithub.com/aws/aws-cdk-go/awscdk/v2/awscloudfront#ResponseHeadersStrictTransportSecurity
Javasoftware.amazon.awscdk.services.cloudfront.ResponseHeadersStrictTransportSecurity
Pythonaws_cdk.aws_cloudfront.ResponseHeadersStrictTransportSecurity
TypeScript (source)aws-cdk-lib » aws_cloudfront » ResponseHeadersStrictTransportSecurity

Determines whether CloudFront includes the Strict-Transport-Security HTTP response header and the header’s value.

Example

// Using an existing managed response headers policy
declare const bucketOrigin: origins.S3Origin;
new cloudfront.Distribution(this, 'myDistManagedPolicy', {
  defaultBehavior: {
    origin: bucketOrigin,
    responseHeadersPolicy: cloudfront.ResponseHeadersPolicy.CORS_ALLOW_ALL_ORIGINS,
  },
});

// Creating a custom response headers policy -- all parameters optional
const myResponseHeadersPolicy = new cloudfront.ResponseHeadersPolicy(this, 'ResponseHeadersPolicy', {
  responseHeadersPolicyName: 'MyPolicy',
  comment: 'A default policy',
  corsBehavior: {
    accessControlAllowCredentials: false,
    accessControlAllowHeaders: ['X-Custom-Header-1', 'X-Custom-Header-2'],
    accessControlAllowMethods: ['GET', 'POST'],
    accessControlAllowOrigins: ['*'],
    accessControlExposeHeaders: ['X-Custom-Header-1', 'X-Custom-Header-2'],
    accessControlMaxAge: Duration.seconds(600),
    originOverride: true,
  },
  customHeadersBehavior: {
    customHeaders: [
      { header: 'X-Amz-Date', value: 'some-value', override: true },
      { header: 'X-Amz-Security-Token', value: 'some-value', override: false },
    ],
  },
  securityHeadersBehavior: {
    contentSecurityPolicy: { contentSecurityPolicy: 'default-src https:;', override: true },
    contentTypeOptions: { override: true },
    frameOptions: { frameOption: cloudfront.HeadersFrameOption.DENY, override: true },
    referrerPolicy: { referrerPolicy: cloudfront.HeadersReferrerPolicy.NO_REFERRER, override: true },
    strictTransportSecurity: { accessControlMaxAge: Duration.seconds(600), includeSubdomains: true, override: true },
    xssProtection: { protection: true, modeBlock: true, reportUri: 'https://example.com/csp-report', override: true },
  },
  removeHeaders: ['Server'],
  serverTimingSamplingRate: 50,
});
new cloudfront.Distribution(this, 'myDistCustomPolicy', {
  defaultBehavior: {
    origin: bucketOrigin,
    responseHeadersPolicy: myResponseHeadersPolicy,
  },
});

Properties

NameTypeDescription
accessControlMaxAgeDurationA number that CloudFront uses as the value for the max-age directive in the Strict-Transport-Security HTTP response header.
overridebooleanA Boolean that determines whether CloudFront overrides the Strict-Transport-Security HTTP response header received from the origin with the one specified in this response headers policy.
includeSubdomains?booleanA Boolean that determines whether CloudFront includes the includeSubDomains directive in the Strict-Transport-Security HTTP response header.
preload?booleanA Boolean that determines whether CloudFront includes the preload directive in the Strict-Transport-Security HTTP response header.

accessControlMaxAge

Type: Duration

A number that CloudFront uses as the value for the max-age directive in the Strict-Transport-Security HTTP response header.


override

Type: boolean

A Boolean that determines whether CloudFront overrides the Strict-Transport-Security HTTP response header received from the origin with the one specified in this response headers policy.


includeSubdomains?

Type: boolean (optional, default: false)

A Boolean that determines whether CloudFront includes the includeSubDomains directive in the Strict-Transport-Security HTTP response header.


preload?

Type: boolean (optional, default: false)

A Boolean that determines whether CloudFront includes the preload directive in the Strict-Transport-Security HTTP response header.