-
Notifications
You must be signed in to change notification settings - Fork 149
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
Conversation
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.
26669bb
to
e8b4bcd
Compare
There was a problem hiding this 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) { |
There was a problem hiding this comment.
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).
There was a problem hiding this comment.
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
src/v1/internal/ch-websocket.js
Outdated
|
||
if (encrypted === true || encrypted === ENCRYPTION_ON) { | ||
// encryption explicitly requested in the config | ||
if (!trust || trust === 'TRUST_CUSTOM_CA_SIGNED_CERTIFICATES') { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
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