|
2 | 2 | import logging
|
3 | 3 | import re
|
4 | 4 | import shlex
|
5 |
| -import subprocess |
| 5 | +import subprocess # nosec |
6 | 6 | import sys
|
7 | 7 | import types
|
8 | 8 |
|
@@ -926,7 +926,9 @@ def process_expr(scope: ScopeType, expr: Any, loc: LocationType) -> Any:
|
926 | 926 | try:
|
927 | 927 | if expr.startswith(EXPR_START_STRING) and expr.endswith(EXPR_END_STRING):
|
928 | 928 | # `expr` might be a single expression and should not be stringify
|
929 |
| - env = Environment( |
| 929 | + env = Environment( # nosec B701 |
| 930 | + # [B701:jinja2_autoescape_false] By default, jinja2 sets autoescape to False. Consider using autoescape=True or use the select_autoescape function to mitigate XSS vulnerabilities. |
| 931 | + # This is safe because autoescape is not needed since we do not generate HTML |
930 | 932 | block_start_string="{%%%%%PDL%%%%%%%%%%",
|
931 | 933 | block_end_string="%%%%%PDL%%%%%%%%%%}",
|
932 | 934 | variable_start_string=EXPR_START_STRING,
|
@@ -1276,14 +1278,20 @@ def step_call_code(
|
1276 | 1278 |
|
1277 | 1279 | def call_python(code: str, scope: dict) -> Any:
|
1278 | 1280 | my_namespace = types.SimpleNamespace(PDL_SESSION=__PDL_SESSION, **scope)
|
1279 |
| - exec(code, my_namespace.__dict__) |
| 1281 | + exec(code, my_namespace.__dict__) # nosec B102 |
| 1282 | + # [B102:exec_used] Use of exec detected. |
| 1283 | + # This is the code that the user asked to execute. It can be executed in a docker container with the option `--sandbox` |
1280 | 1284 | result = my_namespace.result
|
1281 | 1285 | return result
|
1282 | 1286 |
|
1283 | 1287 |
|
1284 | 1288 | def call_command(code: str) -> str:
|
1285 | 1289 | args = shlex.split(code)
|
1286 |
| - p = subprocess.run(args, capture_output=True, text=True, check=False) |
| 1290 | + p = subprocess.run( |
| 1291 | + args, capture_output=True, text=True, check=False, shell=False |
| 1292 | + ) # nosec B603 |
| 1293 | + # [B603:subprocess_without_shell_equals_true] subprocess call - check for execution of untrusted input. |
| 1294 | + # This is the code that the user asked to execute. It can be executed in a docker container with the option `--sandbox` |
1287 | 1295 | if p.stderr != "":
|
1288 | 1296 | print(p.stderr, file=sys.stderr)
|
1289 | 1297 | if p.returncode != 0:
|
|
0 commit comments