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
Merged
Show file tree
Hide file tree
Changes from 2 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 .circleci/regenerate.py
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ def ios_workflows(indentation=6, nightly=False):
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(d),
lstrip_blocks=True,
autoescape=False,
autoescape=True,
keep_trailing_newline=True,
)

Expand Down
1 change: 1 addition & 0 deletions .circleci/unittest/linux/scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,4 @@ dependencies:
- pillow>=4.1.1
- scipy
- av
- defusedxml
1 change: 1 addition & 0 deletions .circleci/unittest/windows/scripts/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,4 @@ dependencies:
- scipy
- av
- dataclasses
- defusedxml
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
3 changes: 3 additions & 0 deletions packaging/torchvision/meta.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ requirements:
- jpeg <=9b
# NOTE: The only ffmpeg version that we build is actually 4.2
- ffmpeg >=4.2 # [not win]
- defusedxml

host:
- python
Expand All @@ -28,6 +29,7 @@ requirements:
- jpeg <=9b
- pillow >=4.1.1
- defaults::numpy >=1.11
- defusedxml
{{ environ.get('CONDA_PYTORCH_CONSTRAINT') }}
{{ environ.get('CONDA_CUDATOOLKIT_CONSTRAINT') }}

Expand Down Expand Up @@ -55,6 +57,7 @@ test:
- av >=8.0.1
- jpeg <=9b
- ca-certificates
- defusedxml


about:
Expand Down
3 changes: 2 additions & 1 deletion torchvision/datasets/voc.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import collections
from .vision import VisionDataset
import xml.etree.ElementTree as ET
import defusedxml.ElementTree as DET
mstfbl marked this conversation as resolved.
Show resolved Hide resolved
from PIL import Image
from typing import Any, Callable, Dict, Optional, Tuple, List
from .utils import download_and_extract_archive, verify_str_arg
Expand Down Expand Up @@ -203,7 +204,7 @@ def __getitem__(self, index: int) -> Tuple[Any, Any]:
tuple: (image, target) where target is a dictionary of the XML tree.
"""
img = Image.open(self.images[index]).convert("RGB")
target = self.parse_voc_xml(ET.parse(self.annotations[index]).getroot())
target = self.parse_voc_xml(DET.parse(self.annotations[index]).getroot())

if self.transforms is not None:
img, target = self.transforms(img, target)
Expand Down