UNPKG

is-website-vulnerable

Version:

finds publicly known security vulnerabilities in a website's frontend JavaScript libraries

48 lines (39 loc) 1.06 kB
'use strict' const process = require('process') const debug = require('debug')('is-website-vulnerable') const { prompt } = require('enquirer') const isUrl = require('is-url-superb') const { Utils } = require('../index') function validate(url) { if (!isUrl(url)) { throw new Error('Given argument is an invalid URL') } return Utils.parseUrl(url) } async function promptUrlInput(url, isJson) { debug(`received url argument: ${url}`) if (url) { return validate(url) } if (isJson) { throw new Error('Please provide a URL of a website to scan') } console.error('Woops! You forgot to provide a URL of a website to scan.') if (process.env.CI) { process.exit(1) } try { const response = await prompt({ type: 'input', name: 'url', message: 'Please provide a URL to scan:', validate(input) { return input && input.length > 0 && isUrl(input) } }) return validate(response.url) } catch (_) { throw new Error('URL input prompt failed') } } module.exports = promptUrlInput