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

how to start https server with SSL cert? #1411

Closed
mksuper1 opened this issue Jan 19, 2017 · 17 comments
Closed

how to start https server with SSL cert? #1411

mksuper1 opened this issue Jan 19, 2017 · 17 comments

Comments

@mksuper1
Copy link

Hi,

I am able to start the https server in windows using set HTTPS=true&&npm start.
Is it possible to pass the SSL cert and key to the https server?

e.g. for node http-server, I can start the https server with
http-server S -C c:\cert\server.pem -K c:\cert\server.key.

How do I achieve the same result for create-react-app?

@Reanmachine
Copy link

Reanmachine commented Jan 19, 2017

The development server

You can't currently, react-scripts uses webpack-dev-server and it would need to pass key/cert files in this configuration block.

The better question is why do you want to pass a specific certificate for your dev server? You're not really gaining much other than identity verification (which you're in control of the server so you know the identity). The self-signed default certificate it uses may not be "valid" but will still encrypt the data in transit which will protect the data if your dev server is across an untrusted network.

The production server

See the discussion in #1409 for details about HTTPs in production.

@gaearon
Copy link
Contributor

gaearon commented Feb 11, 2017

I’m going to close since it doesn’t seem really necessary in DEV, and it would either require configuration, or having some sort of convention for the filenames of the cert. If you feel strongly about this feel free to send a PR that uses a filename convention for them, and we can review it.

@gaearon gaearon closed this as completed Feb 11, 2017
@bitsandbytes
Copy link

I'm surprised this was closed. Two-way client authentication is a typical part of our webapp's security design. And create-react-app does a lot to make developers' lives easier, so getting rid of the pesky security error would be nice.

Our particular use case is:

  1. Install self-signed CA chain on both server and browser.
  2. Install user's cert in browser, and server's cert in server.
  3. When a browser connects, verify the user's cert's CA chain matches the server's.

So part of our development includes writing/testing the code that handles (3) above. This is not currently possible using the dev server.

@gaearon
Copy link
Contributor

gaearon commented Jul 7, 2017

Can you raise a new issue and describe your proposal in more detail? It's not clear to me what we should do to enable this. We do support HTTP=true environment variable which switches HTTPS mode in WebpackDevServer but I presume you need something more.

@bitsandbytes
Copy link

You're right my above comment wasn't clear and was conflating the original request with 2-way authentication. I've submitted #2759.

@jamesmfriedman
Copy link
Contributor

I have the same issue, I need to pass a certificate file in to webpackDevServer like so

https: {
  key: path/to/key/file,
  cert: path/to/pem/file
}

@disaacson
Copy link

I'm running into this in dev as well. The use case is using some web services that use HTTPS, and browsers not allowing HTTP and HTTPS to be mixed on the same page for security reasons.

@jamesmfriedman
Copy link
Contributor

@disaacson check out the epic hack I found to get this working #2759 (comment)

@tobias74
Copy link

tobias74 commented Oct 1, 2017

The Use-Case: Developing a webapp that uses websockets.

Websockets will be declined by chrome with unsecure self-signed certificates.

@mihir0x69
Copy link

mihir0x69 commented Nov 1, 2017

I just made this change to scripts/start.js.

before-

    const devServer = new WebpackDevServer(compiler, serverConfig);

after-

    const devServer = new WebpackDevServer(compiler, {
      ...serverConfig,
      https: true
    });

Webpack dev server creates the certificate. Just navigate to https://localhost:3000, allow chrome to visit the site and you're good to go. It goes without saying that this is not a good practice. But a quick fix.

@roniger
Copy link

roniger commented Nov 19, 2017

Looked at the code and it seems to be sensitive to an environment variable called HTTPS.
Changed my start script to HTTPS=true react-scripts start and it automatically generates the certificates and opens with https.
Looking on how I can supply my own certificate. Let me know if that interests any of you and I will share my findings :)

@sshadmand
Copy link

+1 for

how I can supply my own certificate

@roniger
Copy link

roniger commented Nov 28, 2017

You will need to save your certificate as a pem file with the name server.pem into your node_modules/webpack-dev-server/ssl

Hope this helps

@jh0l
Copy link

jh0l commented Jan 31, 2018

if you run chrome enabling this seems to work

chrome://flags/#allow-insecure-localhost

@A4Abhiraj
Copy link

Why was this closed?
I'm requesting rss feed from a wordpress site. Now wordpress won't accept cross origin requests from a non secure origin. I don't understand the security implications behind this but I'm sure the guys at wordpress won't enable it for me.

@itnirmaan
Copy link

itnirmaan commented May 25, 2018

I used following in start.js
At start

process.env.HTTPS = 'true';

and in WebpackDevServer

{
      ...serverConfig,
      https: {
        key: fs.readFileSync( "/path/server.key"),
        cert: fs.readFileSync("/path/server.crt")
      }
}

@eladmoshe
Copy link

@roniger solution is great, thanks.
I added to my package.json's scripts section a postinstall script that create a symlink from the local development certificate into the appropriate node_modules folder. This make sure the certificate is always in the right place, even if someone clones the repo, delete and reinstall node_modules etc.
Here is the gist if it helps someone.

@lock lock bot locked and limited conversation to collaborators Jan 18, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests