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

Force https in production (deployment) #1409

Closed
firaskrichi opened this issue Jan 18, 2017 · 9 comments
Closed

Force https in production (deployment) #1409

firaskrichi opened this issue Jan 18, 2017 · 9 comments

Comments

@firaskrichi
Copy link

Is there a way to force the app to use https ?

@tbillington
Copy link

It's pretty unrelated. That's config on the server, not the running code.

If you don't want your code to work in non https you could check that the url starts with https and display some kind of error if it doesn't, but really you want to be configuring your server to redirect http to https.

@Reanmachine
Copy link

Reanmachine commented Jan 19, 2017

Create React App doesn't handle the server in production. It generates a static file structure that can be served by anything.

If you're using the reccomendation in CRA of pushstate-server then you need to read about adding https to connect because pushstate-server uses connect and you'll want to create a small server.js to instantiate it programatically.

Edit: It seems pushstate-server is really basic, if you're using this in lieu of a daemon (Apache/nginx/etc..) or a custom server script to server your static content you probably cannot get HTTPS support in pushstate-server as the author doesn't seem interested in supporting it.

I would recommend writing a really simple https/connect server or even express/koa/hapi to support the http -> https rewrite & serving the static files on the https port only.

@Timer
Copy link
Contributor

Timer commented Jan 19, 2017

I haven't tested this, but if configuring the server to do this isn't an option, you may try something like this (in your index.js; first line(s) of the file):

if (window.location.protocol !== 'https:') {
  window.location = 'https:' + window.location.href.substring(window.location.protocol.length)
  return // to stop app from mounting
}

This, however, defeats the purpose of preventing against a MITM attack if a malicious entity wanted to disguise your website as a whole. I wouldn't use it if I were you.

@Reanmachine
Copy link

Reanmachine commented Jan 19, 2017

@Timer That defeats the purpose of HTTPS enforcement, as the entire package (including the javascript) will be delivered over tamperable HTTP. Also, if the server isn't configured to serve over https then it will redirect to an url that won't connect as the server isn't listening on 443.

This is something that has to be solved at the server level (and thus not a CRA concern), the server should enforce the transition to prevent the client from receiving the app over http.

@Timer
Copy link
Contributor

Timer commented Jan 19, 2017

I'm aware of those implications @Reanmachine (and I would never do it that way, personally), but I was just offering the option.
Thus why I wrote "This, however, defeats the purpose of preventing against a MITM attack if a malicious entity wanted to disguise your website as a whole. I wouldn't use it if I were you."

@Reanmachine
Copy link

Sorry @Timer I must have missed that when reading your response.

@firaskrichi
Copy link
Author

Thanks guys, I will set it up on the express server.

@Timer Timer closed this as completed Jan 19, 2017
@cr101
Copy link
Contributor

cr101 commented Jan 20, 2017

@Reanmachine Using https-pushstate-server instead might be the solution

@lock lock bot locked and limited conversation to collaborators Jan 21, 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

6 participants