GithubHelp home page GithubHelp logo

Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self' about cloudfront-authorization-at-edge HOT 3 CLOSED

aws-samples avatar aws-samples commented on July 19, 2024
Refused to execute inline script because it violates the following Content Security Policy directive: "script-src 'self'

from cloudfront-authorization-at-edge.

Comments (3)

rpattcorner avatar rpattcorner commented on July 19, 2024 7

In case anybody comes across this, here are two header sets you can feed to the CFN stack that I've found useful until you can develop a real working CSP.

#1 - this set puts CSP in report-only mode. It will moan about every violation, but still let you run. Very useful in the process of tracking down problems on the way to a valid CSP. Provides no CSP protection.

{
  "Content-Security-Policy-Report-Only": "default-src 'none'; img-src 'self'; script-src 'self'; style-src 'self'; object-src 'none'; connect-src 'self' https://*.amazonaws.com https://*.amazoncognito.com",
  "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
  "Referrer-Policy": "same-origin",
  "X-XSS-Protection": "1; mode=block",
  "X-Frame-Options": "DENY",
  "X-Content-Type-Options": "nosniff"
}

#2 This policy has no CSP but retains other important security items like transport security, referrer policy, etc. No CSP protection, no report warnings:

{
  "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
  "Referrer-Policy": "same-origin",
  "X-XSS-Protection": "1; mode=block",
  "X-Frame-Options": "DENY",
  "X-Content-Type-Options": "nosniff"
}

from cloudfront-authorization-at-edge.

ottokruse avatar ottokruse commented on July 19, 2024

Hi @pandrel

The default HTTP headers that this solution sets include a quite strict CSP––which seems to hinder you:

HttpHeaders:
    Type: String
    Description: The HTTP headers to set on all responses from CloudFront. To be provided as a JSON object
    Default: >-
      {
        "Content-Security-Policy": "default-src 'none'; img-src 'self'; script-src 'self' https://code.jquery.com https://stackpath.bootstrapcdn.com; style-src 'self' 'unsafe-inline' https://stackpath.bootstrapcdn.com; object-src 'none'; connect-src 'self' https://*.amazonaws.com https://*.amazoncognito.com",
        "Strict-Transport-Security": "max-age=31536000; includeSubdomains; preload",
        "Referrer-Policy": "same-origin",
        "X-XSS-Protection": "1; mode=block",
        "X-Frame-Options": "DENY",
        "X-Content-Type-Options": "nosniff"
      }

The easiest way to get going fast: redeploy the stack again (causing a stack update), this time provide the value "{}" for parameter "HTTPHeaders". This effectively removes the default HTTP headers.

The right way forward: determine which CSP headers you need exactly, and pass those in as HTTPHeaders.

Let me know if that helps.

from cloudfront-authorization-at-edge.

pandrel avatar pandrel commented on July 19, 2024

You are awesome. I updated the stack by adding 'unsafe-inline' in the script-src section, reconfigured cloudfront behaviors with new version of the lambda and everything worked fine.
FYI .. i am using existing cloudfront distribution so had to manually update the behaviors.

Thanks so much for your help. !!!

from cloudfront-authorization-at-edge.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.