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

Added CodeQL and Bandit security checks as GitHub Actions #3625

Merged
merged 9 commits into from
Apr 7, 2021
3 changes: 2 additions & 1 deletion .circleci/regenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
"""

import jinja2
from jinja2 import select_autoescape
import yaml
import os.path

Expand Down Expand Up @@ -295,7 +296,7 @@ def ios_workflows(indentation=6, nightly=False):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(d),
lstrip_blocks=True,
autoescape=False,
autoescape=select_autoescape(enabled_extensions=('html', 'xml')),
keep_trailing_newline=True,
)

Expand Down
23 changes: 23 additions & 0 deletions .github/workflows/bandit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# GitHub Actions Bandit Workflow

name: Bandit

on:
pull_request:
branches: [ master ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

# Task will fail if any high-severity issues are found
# Ignoring submodules
- name: Run Bandit Security Analysis
run: |
python -m pip install bandit
python -m bandit -r . -x ./third_party -lll
43 changes: 43 additions & 0 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# GitHub Actions CodeQL Workflow

name: CodeQL

on:
pull_request:
branches: [ master ]

workflow_dispatch:

jobs:
build:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2

- name: Initialize CodeQL
uses: github/codeql-action/init@v1
with:
languages: python, cpp

- name: Install Ninja
run: |
sudo apt-get update -y
sudo apt-get install -y ninja-build

- name: Update submodules
run: git submodule update --init --recursive

- name: Install Torch
run: |
python -m pip install cmake
python -m pip install torch==1.8.1+cpu -f https://download.pytorch.org/whl/torch_stable.html
sudo ln -s /usr/bin/ninja /usr/bin/ninja-build
Comment on lines +34 to +35
Copy link
Member

@fmassa fmassa Apr 7, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

(Can be done in a follow-up PR): torchvision from master uses PyTorch nightly, so it would be better to change this to instead install PyTorch from a nightly release


- name: Build TorchVision
run: python setup.py develop --user

# If any code scanning alerts are found, they will be under Security -> CodeQL
# Link: https://github.com/pytorch/vision/security/code-scanning
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v1
6 changes: 6 additions & 0 deletions torchvision/datasets/voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ def __getitem__(self, index: int) -> Tuple[Any, Any]:
Returns:
tuple: (image, target) where target is a dictionary of the XML tree.
"""
# If defusedxml exists, use defusedxml.ElementTree instead.
# Else, use xml.ElementTree as normal.
try:
import defusedxml.ElementTree as ET
except ImportError:
pass
mstfbl marked this conversation as resolved.
Show resolved Hide resolved
img = Image.open(self.images[index]).convert("RGB")
target = self.parse_voc_xml(ET.parse(self.annotations[index]).getroot())

Expand Down