Skip to content

Commit 7c5031a

Browse files
author
Vitaliy Saveliev
committed
Fix semgrep warnings
1 parent 7696fa6 commit 7c5031a

File tree

7 files changed

+19
-11
lines changed

7 files changed

+19
-11
lines changed

.github/workflows/secure.yml

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ on: push
55
jobs:
66
# Sample GitHub Actions:
77
# 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
811
semgrep:
912
runs-on: ubuntu-latest
1013
container:
@@ -14,7 +17,7 @@ jobs:
1417
security-events: write
1518
steps:
1619
- uses: actions/checkout@v4
17-
- run: semgrep scan --sarif --output=semgrep.sarif --error
20+
- run: semgrep scan --sarif --output=semgrep.sarif --error --severity=WARNING
1821
env:
1922
SEMGREP_RULES: >-
2023
p/bandit
@@ -54,7 +57,7 @@ jobs:
5457
format: 'sarif'
5558
output: 'trivy.sarif'
5659
exit-code: '1'
57-
severity: 'CRITICAL,HIGH'
60+
severity: 'MEDIUM,CRITICAL,HIGH'
5861
- uses: github/codeql-action/upload-sarif@v3
5962
with:
6063
sarif_file: trivy.sarif

.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 & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,6 @@ def delete_many(self, token_ids, raise_if_not_found=True):
4646
for token_id in token_ids:
4747
try:
4848
self.delete(token_id)
49-
log.info("Token %s has been deleted", token_id)
5049
except ClientException as err:
5150
if raise_if_not_found:
5251
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)