Skip to content

Example on how to use this with CRA + react-app-rewired? #53

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

Closed
2 of 9 tasks
RIP21 opened this issue Feb 5, 2020 · 4 comments
Closed
2 of 9 tasks

Example on how to use this with CRA + react-app-rewired? #53

RIP21 opened this issue Feb 5, 2020 · 4 comments

Comments

@RIP21
Copy link

RIP21 commented Feb 5, 2020

Description

Hey folks, can you please make some example that will show how to make this thingy working with CRA + react-app-rewired? Because all my attempts failed with no result in resulting index.html

I tried rewired function like that with no avail tho. I tried a few other approaches, also no result.

function addCspHtmlWebpackPlugin(config, env) {
  config.plugins[0].options.cspPlugin = {
    enabled: true,
    policy: {
      'base-uri': "'self'",
      'script-src': ["'unsafe-inline'", "'self'"],
    },
    hashEnabled: {
      'script-src': true,
    },
    nonceEnabled: {
      'script-src': true,
    },
  }

  config.plugins.push(
    new CspHtmlWebpackPlugin(
      {
        'base-uri': "'self'",
        'script-src': ["'unsafe-inline'", "'self'"],
      },
      { ...config.plugins[0].options },
    ),
  )

  return config
}

I'm talking about this thing :)
https://github.com/timarney/react-app-rewired

Thanks!

What type of issue is this? (place an x in one of the [ ])

  • bug
  • enhancement (feature request)
  • question
  • documentation related
  • testing related
  • discussion

Requirements (place an x in each of the [ ])

  • I've read and understood the Contributing guidelines and have done my best effort to follow them.
  • I've read and agree to the Code of Conduct.
  • I've searched for any related issues and avoided creating a duplicate issue.
@AnujRNair
Copy link
Contributor

Hi @RIP21,

I'm unfamiliar with how CRA and react-app-rewired work, but if you are able to replicate the issue in a minimal repo, where I could poke around, I might be able to point you in the right direction.

Thanks!

@kaikun213
Copy link

@RIP21 With the following code it works fine for me (similar to yours):

In config-overrides.js:

function addCspHtmlWebpackPlugin(config) {
  if(process.env.NODE_ENV === 'production' &&  
     process.env.PUBLIC_URL === "") {
      console.log("[PRODUCTION] Enable CSP")
      config.plugins.push(new CspHtmlWebpackPlugin(cspConfigPolicy));
  }

  return config;
}
module.exports = override(
  addCspHtmlWebpackPlugin,
)

In public/index.html:

<meta http-equiv="Content-Security-Policy" content="">

@RIP21
Copy link
Author

RIP21 commented Feb 16, 2020 via email

@AnujRNair
Copy link
Contributor

That's correct! Glad you managed to implement this. Closing this issue for now

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

No branches or pull requests

3 participants