Skip to content

Commit 99c9e26

Browse files
authored
update semgrep rules (#9560)
* update * format
1 parent 4ed5339 commit 99c9e26

File tree

2 files changed

+42
-15
lines changed

2 files changed

+42
-15
lines changed

.github/configs/semgrep_rules.yaml

Lines changed: 40 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,45 @@
11
rules:
2-
- id: detect-os-system-calls
3-
pattern: os.system(...)
4-
message: "Unsafe use of os.system(). Consider using subprocess.run() instead."
5-
languages: [python]
2+
- id: third-party-action-not-pinned-to-commit-sha
3+
pattern-either:
4+
- pattern: uses: $ACTION@$REF
5+
metavariable-regex:
6+
$ACTION: ^(?!.*?/\.)(?!actions/).*?/.*?$
7+
$REF: ^(v?\d+(\.\d+){0,2}|[^@]+)$
8+
- pattern: uses: $ACTION
9+
metavariable-regex:
10+
$ACTION: ^(?!.*?/\.)(?!actions/).*?/.*?$
11+
message: >
12+
Third-party GitHub Action is not pinned to a specific commit SHA.
13+
This can be a security risk as the action may be modified unexpectedly.
14+
Consider using a full length commit SHA instead of a tag or branch name.
615
severity: WARNING
16+
languages: [yaml]
17+
paths:
18+
include:
19+
- '**/workflows/*.yml'
20+
- '**/workflows/*.yaml'
21+
metadata:
22+
category: security
23+
technology:
24+
- github-actions
25+
references:
26+
- https://docs.github.com/en/actions/security-guides/security-hardening-for-github-actions#using-third-party-actions
727

8-
- id: detect-sql-injection
9-
pattern: 'execute("SELECT * FROM " + $TABLE)'
10-
message: "Potential SQL injection detected. Use parameterized queries."
28+
- id: insecure-file-permissions
29+
pattern: os.chmod(..., $PERMS)
30+
message: >
31+
Detected a call to os.chmod() with potentially insecure permissions.
32+
Ensure that file permissions are set correctly to prevent unauthorized access.
33+
severity: WARNING
1134
languages: [python]
12-
severity: ERROR
35+
metadata:
36+
category: security
37+
technology:
38+
- python
39+
references:
40+
- https://docs.python.org/3/library/os.html#os.chmod
41+
- https://owasp.org/www-community/vulnerabilities/Insecure_Temporary_File
42+
fix-regex:
43+
regex: os\.chmod\((.*?),\s*(.*?)\)
44+
replacement: os.chmod($1, 0o600)
1345

14-
- id: detect-eval-usage
15-
pattern: eval(...)
16-
message: "Use of eval() detected. This can be dangerous if used with untrusted input."
17-
languages: [python]
18-
severity: ERROR

.github/workflows/semgrep.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ jobs:
4747
- name: restart docker
4848
uses: docker://docker
4949
with:
50-
args: docker restart semgrepcontainer
51-
- run: ls -la /mnt
50+
args: docker restart semgrepcontainer
51+
- run: ls -la /mnt
5252
- run: semgrep ci --config=/mnt/semgrep_rules.yaml
5353
update-status:
5454
permissions:

0 commit comments

Comments
 (0)