Skip to content

Commit d9e19b6

Browse files
authored
Add Security Scanners (#36)
1 parent 089f1b2 commit d9e19b6

File tree

8 files changed

+88
-20
lines changed

8 files changed

+88
-20
lines changed

.github/workflows/secure.yml

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
name: Secure
2+
3+
on: push
4+
5+
jobs:
6+
# Sample GitHub Actions:
7+
# https://semgrep.dev/docs/semgrep-ci/sample-ci-configs#sample-github-actions-configuration-file
8+
#
9+
# CLI Reference:
10+
# https://semgrep.dev/docs/cli-reference
11+
semgrep:
12+
runs-on: ubuntu-24.04
13+
container:
14+
image: semgrep/semgrep
15+
permissions:
16+
contents: read
17+
security-events: write
18+
steps:
19+
- uses: actions/checkout@v4
20+
- run: semgrep scan --sarif --output=semgrep.sarif --error --severity=WARNING
21+
env:
22+
SEMGREP_RULES: >-
23+
p/bandit
24+
p/command-injection
25+
p/comment
26+
p/cwe-top-25
27+
p/default
28+
p/gitlab
29+
p/gitlab-bandit
30+
p/gitleaks
31+
p/insecure-transport
32+
p/owasp-top-ten
33+
p/python
34+
p/r2c-best-practices
35+
p/r2c-bug-scan
36+
p/r2c-security-audit
37+
p/secrets
38+
p/security-audit
39+
p/xss
40+
- uses: github/codeql-action/upload-sarif@v3
41+
with:
42+
sarif_file: semgrep.sarif
43+
if: always()
44+
45+
# Samples GitHub Actions:
46+
# https://github.com/aquasecurity/trivy-action
47+
trivy:
48+
runs-on: ubuntu-24.04
49+
permissions:
50+
contents: read
51+
security-events: write
52+
steps:
53+
- uses: actions/checkout@v4
54+
- uses: aquasecurity/trivy-action@master
55+
with:
56+
scan-type: 'fs'
57+
format: 'sarif'
58+
output: 'trivy.sarif'
59+
exit-code: '1'
60+
severity: 'MEDIUM,CRITICAL,HIGH'
61+
- uses: github/codeql-action/upload-sarif@v3
62+
with:
63+
sarif_file: trivy.sarif
64+
if: always()

.github/workflows/checks.yml renamed to .github/workflows/verify.yml

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,23 @@
1-
name: Checks
1+
name: Verify
2+
23
on: push
4+
35
jobs:
46
flake8:
5-
runs-on: ubuntu-latest
7+
runs-on: ubuntu-24.04
68
steps:
7-
- uses: actions/checkout@v3
8-
- uses: actions/setup-python@v4
9+
- uses: actions/checkout@v4
10+
- uses: actions/setup-python@v5
911
with:
1012
python-version: '3.8'
1113
- run: pip install -r requirements.txt -r test-requirements.txt
1214
- run: flake8 .
15+
1316
pytest:
14-
runs-on: ubuntu-latest
17+
runs-on: ubuntu-24.04
1518
steps:
16-
- uses: actions/checkout@v3
17-
- uses: actions/setup-python@v4
19+
- uses: actions/checkout@v4
20+
- uses: actions/setup-python@v5
1821
with:
1922
python-version: '3.8'
2023
- run: pip install -r requirements.txt -r test-requirements.txt

.semgrepignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
env.example.bat
2+
env.example.sh

selvpcclient/resources/tokens.py

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
1-
import logging
2-
31
from selvpcclient import base
42
from selvpcclient.exceptions.base import ClientException
53

6-
log = logging.getLogger(__name__)
7-
84

95
class Token(base.Resource):
106
"""Represents a token."""
@@ -46,8 +42,6 @@ def delete_many(self, token_ids, raise_if_not_found=True):
4642
for token_id in token_ids:
4743
try:
4844
self.delete(token_id)
49-
log.info("Token %s has been deleted", token_id)
5045
except ClientException as err:
5146
if raise_if_not_found:
5247
raise err
53-
log.error("%s %s", err, token_id)

selvpcclient/util.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ def make_curl(url, method, data):
211211
v = str()
212212
if value:
213213
v = value.encode('utf-8')
214-
h = hashlib.sha1(v)
214+
h = hashlib.sha256(v)
215215
d = h.hexdigest()
216216
value = "{SHA1}%s" % d
217217
header = ' -H "%s: %s"' % (key, value)
@@ -225,15 +225,17 @@ def make_curl(url, method, data):
225225
def is_url(data):
226226
"""Checks if getting value is valid url and path exists."""
227227
try:
228-
r = requests.head(data)
229-
except Exception:
228+
r = requests.head(data, timeout=15)
229+
r.raise_for_status()
230+
except requests.RequestException:
230231
return False
231232
return r.status_code == requests.codes.ok
232233

233234

234235
def process_logo_by_url(url):
235236
"""Download and encode image by url."""
236-
res = requests.get(url)
237+
res = requests.get(url, timeout=15)
238+
res.raise_for_status()
237239
encoded_logo = base64.b64encode(res.content)
238240
return encoded_logo
239241

tests/cli/__init__.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
import json
22

3-
import mock
3+
from unittest import mock
4+
45
from selvpcclient.client import Client
56
from selvpcclient.shell import CLI
67

78

9+
# nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
810
def prepare_to_run_command(cmd):
911
pass
1012

tests/rest/__init__.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
1-
import mock
2-
31
from datetime import datetime, timedelta
2+
from unittest import mock
43

54
from selvpcclient.httpclient import HTTPClient, RegionalHTTPClient
65

tests/test_util.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ def function_that_takes_theme_params(logo=None, color=""):
9595

9696

9797
def test_process_theme_params_invalid_logo():
98+
# nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
9899
@process_theme_params
99100
def function_that_takes_theme_params(logo=None, color=''):
100101
pass
@@ -105,6 +106,7 @@ def function_that_takes_theme_params(logo=None, color=''):
105106

106107

107108
def test_process_theme_params_wrong_path():
109+
# nosemgrep: python.lang.best-practice.pass-body.pass-body-fn
108110
@process_theme_params
109111
def function_that_takes_theme_params(logo=None, color=''):
110112
pass

0 commit comments

Comments
 (0)