[medium] semgrep: Improper neutralization of directives in dynamically evaluated code ('Eval Injection') #831

Closed
opened 2026-11-04 16:32:27 +00:00 by pruefwerk · 1 comment
Member

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

## 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)
pruefwerk added the severity:mediumcra:annex-ipruefwerk labels 2026-11-04 16:32:27 +00:00
Author
Member

Prüfwerk: Bei der Prüfung nicht mehr gefunden, daher als behoben markiert.

No longer found by the scan, so marked resolved.

**Prüfwerk:** Bei der Prüfung nicht mehr gefunden, daher als behoben markiert. No longer found by the scan, so marked resolved.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: platform/pruefwerk#831