diff --git a/.npmrc b/.npmrc index 214c29d1..43396fe6 100644 --- a/.npmrc +++ b/.npmrc @@ -1 +1,2 @@ registry=https://registry.npmjs.org/ +scripts-prepend-node-path=true diff --git a/package.json b/package.json index 1c7d7358..2c8a2455 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "Stethoscope", - "version": "3.0.3", + "version": "3.0.4", "private": true, "homepage": "./", "author": "Netflix", @@ -99,7 +99,7 @@ ] }, "scripts": { - "start": "nf start -p 12000", + "start": "cross-env FORCE_COLOR=true nf start -p 12000", "test": "react-scripts test --env=jsdom", "electron": "cross-env STETHOSCOPE_ENV=development electron .", "electron:start": "node src/start-react", @@ -109,7 +109,7 @@ "build:react": "react-scripts build && node update-download-page.js", "build:mac": "rm -r dist/; npm run build:react && npm run build:electron -m && npm run test:spectron", "build:windows": " npm run build:react && npm run build:electron -w && npm run test:spectron", - "build:electron": "ELECTRON_BUILDER_COMPRESSION_LEVEL=9 electron-builder", + "build:electron": "cross-env ELECTRON_BUILDER_COMPRESSION_LEVEL=9 electron-builder", "test:spectron": "node src/__tests__/test-build.js", "build:linux": "rm -r dist/ ; react-scripts build && electron-builder -l", "lint": "standard --fix src/*.js src/**/*.js resolvers/*.js sources/*.js server.js" @@ -118,6 +118,7 @@ "applescript": "^1.0.0", "auto-launch": "^5.0.5", "body-parser": "^1.18.2", + "chalk": "^2.4.2", "classnames": "^2.2.5", "cors": "^2.8.4", "cross-env": "^5.2.0", diff --git a/practices/policy.yaml b/practices/policy.yaml index aebcdb35..e4f1ca27 100644 --- a/practices/policy.yaml +++ b/practices/policy.yaml @@ -1,14 +1,14 @@ osVersion: darwin: # High Sierra - ok: ">=10.13.6" + ok: ">=10.14.3" # Sierra nudge: ">=10.12.6" win32: - # Version 1803 - April 2018 Update - ok: ">=10.0.17134" - # Version 1803 - Redstone 3 Fall Creators Update - nudge: ">=10.0.16299" + # Version 1809 + ok: ">=10.0.17763" + # Version 1803 + nudge: ">=10.0.17134" awsWorkspace: ok: ">=10.0.14393" nudge: ">=10.0.10240" diff --git a/server.js b/server.js index ba5a6223..0b038780 100644 --- a/server.js +++ b/server.js @@ -109,8 +109,11 @@ module.exports = async function startServer (env, log, language = 'en-US', appAc } app.use(['/scan', '/graphql'], cors(corsOptions), async (req, res) => { - req.setTimeout(60000) + // set upper boundary on scan time + const MAX_SCAN_SECONDS = 45 + req.setTimeout(MAX_SCAN_SECONDS * 1000) + // allow GET/POST requests and determine what property to use const key = req.method === 'POST' ? 'body' : 'query' const origin = req.get('origin') const remote = origin !== 'stethoscope://main' @@ -133,37 +136,48 @@ module.exports = async function startServer (env, log, language = 'en-US', appAc // are throttled by the users's session id let showNotification = sessionId && !alertCache.has(sessionId) const start = performance.now() - // TODO each of these checks should probably be individually executed + // TODO each of these checks should be individually executed // by relecvant resolvers. Since it is currently super fast, there is no // real performance penalty for running all checks on each request + // this would require loading the script files differently so the resolvers + // could execute the appropriate pre-compiled scripts const checkData = await Promise.all(checks.map(async script => { - const response = await run(script) - return response + try { return await run(script) } + catch (e) { return '' } })) + // perf data const total = performance.now() - start context.kmdResponse = extend(true, {}, ...checkData) - - policy = policy || {} - + // throttle native push notifications to user by session id if (sessionId && !alertCache.has(sessionId)) { alertCache.set(sessionId, true) } + // policy needs to be an object, regardless of whether or not one was + // supplied in the request, parse if String was supplied if (typeof policy === 'string') { policy = JSON.parse(policy) + } else { + policy = Object.assign({}, policy) } - // tell the app if a policy was passed to display scanning status + // if a policy was passed, tell the app display scanning status if (Object.keys(policy).length) { // show the scan is happening in the UI io.sockets.emit('scan:init', { remote, remoteLabel }) } - graphql(schema, query, null, context, policy).then((result) => { - const { data = {} } = result + graphql(schema, query, null, context, policy).then(result => { + const { data = {}, errors } = result let scanResult = { noResults: true } + if (errors && !remote) { + const errMessage = errors.reduce((p, c) => p + c + '\n', '') + io.sockets.emit('scan:error', { error: errMessage }) + throw new Error(errMessage) + } + // update the tray icon if a policy result is in the response if (data.policy && data.policy.validate) { appActions.setScanStatus(data.policy.validate.status) @@ -177,7 +191,7 @@ module.exports = async function startServer (env, log, language = 'en-US', appAc res.json(result) }).catch(err => { log.error(err.message) - io.sockets.emit('scan:error') + io.sockets.emit('scan:error', { error: err.message }) res.status(500).json({ error: err.message }) }) }) diff --git a/sources/darwin/file-vault.sh b/sources/darwin/file-vault.sh index c9c59055..81c7c98b 100644 --- a/sources/darwin/file-vault.sh +++ b/sources/darwin/file-vault.sh @@ -1,3 +1,3 @@ #!/usr/bin/env kmd -exec fdesetup isactive +exec /usr/bin/fdesetup isactive save disks.fileVaultEnabled diff --git a/src/Action.js b/src/Action.js index e8b6f377..d686d822 100644 --- a/src/Action.js +++ b/src/Action.js @@ -2,9 +2,9 @@ import React, { Component } from 'react' import ReactDOMServer from 'react-dom/server' import Accessible from './Accessible' import ActionIcon from './ActionIcon' -import Handlebars from 'handlebars' import semver from 'semver' import showdown from 'showdown' +import Handlebars from 'handlebars/dist/handlebars.min.js'; const converter = new showdown.Converter() @@ -186,7 +186,11 @@ class Action extends Component { } return ( -
+ {JSON.stringify(this.state.error, null, 3)} ++