Skip to content

Automatically use secure WebSocket on HTTPS pages #371

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

Merged
merged 2 commits into from
May 23, 2018

Conversation

lutovich
Copy link
Contributor

Previously, driver used in browser used secure WebSocket with 'wss' scheme only when encryption was explicitly turned on in the driver config. On HTTP web pages it is perfectly fine to use either plane or secure WebSocket ('ws' and 'wss' respectively). On HTTPS web pages only 'wss' is allowed. So explicit {encrypted: true} configuration was always required for drivers used on HTTPS web pages.

This PR makes driver automatically use secure WebSocket when driver is used on a HTTPS web page.

Resolves #255

@lutovich lutovich requested a review from ali-ince May 13, 2018 21:48
Previously, driver used in browser used secure WebSocket with 'wss'
scheme only when encryption was explicitly turned on in the driver
config. On HTTP web pages it is perfectly fine to use either plane
or secure WebSocket ('ws' and 'wss' respectively). On HTTPS web
pages only 'wss' is allowed. So explicit `{encrypted: true}`
configuration was always required for drivers used on HTTPS web pages.

This commit makes driver automatically use secure WebSocket when driver
is used on a HTTPS web page.
@lutovich lutovich force-pushed the 1.7-wss-in-https branch from 26669bb to e8b4bcd Compare May 13, 2018 21:52
Copy link
Contributor

@ali-ince ali-ince left a comment

Choose a reason for hiding this comment

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

LGTM along with a couple of comments.

* @param {function(): string} protocolSupplier - function that detects protocol of the web page.
* @return {{scheme: string|null, error: Neo4jError|null}} object containing either scheme or error.
*/
function determineWebSocketScheme(config, protocolSupplier) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Based on the information given in Security Considerations section here, it may make sense generating warning message about mixing protocols may not work - if encryption is explicitly turned off or on (i.e. https/ws or http/wss).

Copy link
Contributor Author

@lutovich lutovich May 17, 2018

Choose a reason for hiding this comment

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

Added a warn print in c623d8a


if (encrypted === true || encrypted === ENCRYPTION_ON) {
// encryption explicitly requested in the config
if (!trust || trust === 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES') {
Copy link
Contributor

Choose a reason for hiding this comment

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

This is totally out of scope of this PR, but I find TRUST_CUSTOM_CA_SIGNED_CERTIFICATES setting to be confusing and would prefer TRUST_SYSTEM_CA_SIGNED_CERTIFICATES as the default. We may consider revising naming / behaviour in upcoming releases?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll create a card for this

Encryption can be explicitly turned on or off in the driver config.
Driver can be used on both HTTP and HTTPS web pages. Configured
encryption has to match the security protocol of the web page. Insecure
WebSockets ('ws') have to be used on insecure pages ('http'). Secure
WebSockets ('wss') have to be used on secure pages ('https').
WebSockets might not work in a mixed content environment,
i.e. 'ws' + 'https' or 'wss' + 'http'.

This commit makes driver print a warning when its configuration is
inconsistent with the web page.
@ali-ince ali-ince merged commit f55184a into neo4j:1.7 May 23, 2018
@lutovich lutovich deleted the 1.7-wss-in-https branch May 23, 2018 15:59
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