Skip to content

Commit

Permalink
Fix Bandit Security Tests
Browse files Browse the repository at this point in the history
Pull request #348 introduced Bandit, but did not actually made the
correct call for scanning. This patch fixes that problem and addresses
all current complaints.
  • Loading branch information
lkiesow committed Apr 29, 2022
1 parent d3131f6 commit 147f332
Show file tree
Hide file tree
Showing 4 changed files with 9 additions and 5 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ export DOCKER_BUILDKIT=1

lint:
@flake8 $$(find pyca tests -name '*.py') .github/selenium-tests
@bandit pyca tests
@bandit -s B404,B602,B603 -r pyca
@npm run eslint

test:
Expand Down
6 changes: 4 additions & 2 deletions pyca/ingest.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,8 @@ def ingest(event):
# ingest services to ensure that not every capture agent uses the same
# service at the same time
service_url = service('ingest', force_update=True)
service_url = service_url[random.randrange(0, len(service_url))]
# nosec: we do not need a secure random number here
service_url = service_url[random.randrange(0, len(service_url))] # nosec
logger.info('Selecting ingest service to use: ' + service_url)

# create mediapackage
Expand Down Expand Up @@ -144,7 +145,8 @@ def control_loop():
.filter(RecordedEvent.status ==
Status.FINISHED_RECORDING).first()
if event:
delay = random.randint(config('ingest', 'delay_min'),
# nosec: we do not need a secure random number here
delay = random.randint(config('ingest', 'delay_min'), # nosec
config('ingest', 'delay_max'))
logger.info("Delaying ingest for %s seconds", delay)
time.sleep(delay)
Expand Down
2 changes: 2 additions & 0 deletions pyca/ui/jsonapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def logs():
if not cmd:
return make_error_response('Logs are disabled.', 404)

# We specifically allow shell. This is no security issue since only admins
# may specify this command.
logs = subprocess.run(cmd, shell=True, check=True, stdout=subprocess.PIPE,
stderr=subprocess.STDOUT)\
.stdout\
Expand Down
4 changes: 2 additions & 2 deletions pyca/ui/opencast_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
:license: LGPL – see license.lgpl for more details.
'''

from xml.sax.saxutils import escape as xml_escape
from xml.sax.saxutils import escape as xml_escape # nosec B406
from pyca.config import config
from pyca.utils import http_request, service
from datetime import datetime, timedelta
Expand Down Expand Up @@ -48,7 +48,7 @@ def schedule(title='pyCA Recording', duration=60, creator=None):
# ingest services to ensure that not every capture agent uses the same
# service at the same time
service_url = service('ingest', force_update=True)
service_url = service_url[random.randrange(0, len(service_url))]
service_url = service_url[random.randrange(0, len(service_url))] # nosec
logger.info('Selecting ingest service for scheduling: ' + service_url)

# create media package
Expand Down

0 comments on commit 147f332

Please sign in to comment.