Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Static hosting custom header policies #825

Merged

Conversation

krishanthisera
Copy link
Contributor

This feature enable us to create and attach response header policies to specified path.
This is an optional configuration.

  1. Create a policy

    // Creating a custom response headers policy -- all parameters optional
    const reportUriPolicy = new ResponseHeadersPolicy(this, 'ReportUriPolicy', {
        responseHeadersPolicyName: 'ReportUriPolicy',
        comment: 'To enable CSP Reporting',
        customHeadersBehavior: {
            customHeaders: [
                { 
                    header: 'content-security-policy-report-only', 
                    value: `default-src 'none'; form-action 'none'; frame-ancestors 'none'; report-uri https://some-report-uri-domain.report-uri.com/r/t/csp/wizard`, 
                    override: true 
                },
            ],
        },
    });
  2. Attached policy to desired cache behavior or path

    const responseHeaders: ResponseHeaderMappings[] = [{
        header: reportUriPolicy,
        pathPatterns: ['/au*', '/nz*']
        attachToDefault: false
    }];

    If you should attached the policy to the Default Behavior, set attachToDefault: true

  3. Include the config as props

    new StaticHosting(this, 'pwa-stack', {...staticProps, ...{behaviors, customOriginConfigs, responseHeaders}});

Copy link
Contributor

@crispy101 crispy101 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@krishanthisera krishanthisera merged commit aab93ce into main Jan 4, 2023
@TheOrangePuff TheOrangePuff deleted the feature/DO-1419_static_hosting_custom_header_policies branch December 10, 2024 05:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants