diff --git a/lib/validate.js b/lib/validate.js index a95d708f..06a72a81 100644 --- a/lib/validate.js +++ b/lib/validate.js @@ -72,11 +72,10 @@ addMethod(string, 'ws', function (schemas, msg = 'invalid websocket') { name: 'ws', message: msg, test: value => { - if (!value) return true + if (typeof value === 'undefined') return true try { - // eslint-disable-next-line no-new - new URL(value) - return true + const url = new URL(value) + return url.protocol === 'ws:' || url.protocol === 'wss:' } catch (e) { return false }