Scanner: semgrep Severity: medium Rule: gitlab-python_exec_rule-exec-used CWE: CWE-95
Description
The application was found calling the exec function with a non-literal variable. If the
variable comes from user-supplied input, an adversary could compromise the entire system by
executing arbitrary python code.
To remediate this issue, remove all calls to exec and consider alternative methods for
executing the necessary business logic. There is almost no safe method of calling eval
with user-supplied input.
If the application only needs to convert strings into objects, consider using json.loads.
In some cases ast.literal_eval is recommended, but this should be avoided as it can still
suffer from other issues such as the ability for malicious code to crash the python
interpreter or application.
Example using `json.loads`` to load in arbitrary data to create data structures:
# User supplied data as a blob of JSON
user_supplied_data = """{"user": "test", "metadata": [1,2,3]}"""
# Load the JSON
user_object = json.loads(user_supplied_data)
# Manually add protected properties _after_ loading, never before
user_object["is_admin"] = False
# Work with the object
## medium Finding
**Scanner:** semgrep
**Severity:** medium
**Rule:** gitlab-python_exec_rule-exec-used
**CWE:** CWE-95
### Description
The application was found calling the `exec` function with a non-literal variable. If the
variable comes from user-supplied input, an adversary could compromise the entire system by
executing arbitrary python code.
To remediate this issue, remove all calls to `exec` and consider alternative methods for
executing the necessary business logic. There is almost no safe method of calling `eval`
with user-supplied input.
If the application only needs to convert strings into objects, consider using `json.loads`.
In some cases `ast.literal_eval` is recommended, but this should be avoided as it can still
suffer from other issues such as the ability for malicious code to crash the python
interpreter or application.
Example using `json.loads`` to load in arbitrary data to create data structures:
```
# User supplied data as a blob of JSON
user_supplied_data = """{"user": "test", "metadata": [1,2,3]}"""
# Load the JSON
user_object = json.loads(user_supplied_data)
# Manually add protected properties _after_ loading, never before
user_object["is_admin"] = False
# Work with the object
```
### Location
**File:** `scripts/test_codesys_export.py` (line 65)
### Code
```
exec(compile(source, str(SCRIPT), "exec"), scope)
```
### Remediation
None
---
*Fingerprint:* `15a4c02ee878953263e0d560aa0437e2473ede2215d3b1836e4a083f528b8d32`
*Generated by compliance-scanner*
[Open in Prüfwerk / In Prüfwerk öffnen](https://pruefwerk.breakpilot.com/findings?target=6ae9aa2160f5d8045fc570a7)
Blocking a user prevents them from interacting with repositories, such as opening or commenting on pull requests or issues. Learn more about blocking a user.
medium Finding
Scanner: semgrep
Severity: medium
Rule: gitlab-python_exec_rule-exec-used
CWE: CWE-95
Description
The application was found calling the
execfunction with a non-literal variable. If thevariable comes from user-supplied input, an adversary could compromise the entire system by
executing arbitrary python code.
To remediate this issue, remove all calls to
execand consider alternative methods forexecuting the necessary business logic. There is almost no safe method of calling
evalwith user-supplied input.
If the application only needs to convert strings into objects, consider using
json.loads.In some cases
ast.literal_evalis recommended, but this should be avoided as it can stillsuffer from other issues such as the ability for malicious code to crash the python
interpreter or application.
Example using `json.loads`` to load in arbitrary data to create data structures:
Location
File:
scripts/test_codesys_export.py(line 65)Code
Remediation
None
Fingerprint:
15a4c02ee878953263e0d560aa0437e2473ede2215d3b1836e4a083f528b8d32Generated by compliance-scanner
Open in Prüfwerk / In Prüfwerk öffnen
Prüfwerk: Bei der Prüfung nicht mehr gefunden, daher als behoben markiert.
No longer found by the scan, so marked resolved.