Skip to content

Commit b4a0074

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

File tree

8 files changed

+62
-11
lines changed

8 files changed

+62
-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

.github/workflows/semgrep.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
name: Semgrep
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-latest
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()

.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)