Skip to content
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

Adds an audit script that ignores dev vulnerabilities #5655

Merged
merged 2 commits into from
May 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"build-storybook": "build-storybook -c .storybook -o .storybook-out",
"storybook": "start-storybook",
"test-unit": "jest -t",
"test-security": "npm audit",
"test-security": "python script/audit_deps.py",
"test-python-scripts": "npm run pep8 && PYTHONPATH=./script python -m unittest discover -s ./script/test"
},
"repository": {
Expand Down
66 changes: 66 additions & 0 deletions script/audit_deps.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/usr/bin/env python

# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this file,
# You can obtain one at http://mozilla.org/MPL/2.0/.

import sys
import json
import argparse
import subprocess


def main():
args = parse_args()
return audit_deps(args)


def audit_deps(args):
npm_cmd = 'npm'
if sys.platform.startswith('win'):
npm_cmd = 'npm.cmd'

npm_args = [npm_cmd, 'audit']

# Just run audit regularly if --audit_dev_deps is passed
if args.audit_dev_deps:
return subprocess.call(npm_args)

npm_args.append('--json')
audit_process = subprocess.Popen(npm_args, stdout=subprocess.PIPE)
output, error_data = audit_process.communicate()

try:
result = json.loads(str(output))
resolutions = result['actions'][0]['resolves']
non_dev_exceptions = [r for r in resolutions if not r['dev']]
except ValueError:
# This can happen in the case of an NPM network error
print('Audit failed to return valid json')
return 1

print(output)

# Trigger a failure if there are non-dev exceptions
if non_dev_exceptions:
print('Audit finished, vulnerabilities found')
return 1

# Still pass if there are dev exceptions, but let the user know about them
if resolutions:
print('Audit finished, there are dev package warnings')
else:
print('Audit finished, no vulnerabilities found')
return 0


def parse_args():
parser = argparse.ArgumentParser(description='Audit brave-core npm deps')
parser.add_argument('--audit_dev_deps',
action='store_true',
help='Audit dev dependencies')
return parser.parse_args()


if __name__ == '__main__':
sys.exit(main())
2 changes: 1 addition & 1 deletion script/uplift.py
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ def fancy_print(text):

def parse_issues_fixed(body):
try:
regex = r'((Resolves|Fixes|Fix|Closes|Close|resolves|fixes|fix|closes|close) https:\/\/github\.com\/brave\/brave-browser\/issues\/(\d*))'
regex = r'((Resolves|Fixes|Fix|Closes|Close|resolves|fixes|fix|closes|close) https:\/\/github\.com\/brave\/brave-browser\/issues\/(\d*))' # nopep8
return re.findall(regex, body)
except Exception as e:
print str(e)
Expand Down