Skip to content

Commit 340e0e0

Browse files
committed
Use json.loads instead of eval.
1 parent b893b18 commit 340e0e0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/judge0/__init__.py

+4-2
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ def _get_preview_client(flavor: Flavor) -> Union[SuluJudge0CE, SuluJudge0ExtraCE
111111

112112

113113
def _get_custom_client(flavor: Flavor) -> Union[Client, None]:
114+
from json import loads
115+
114116
ce_endpoint = os.getenv("JUDGE0_CE_ENDPOINT")
115117
ce_auth_header = os.getenv("JUDGE0_CE_AUTH_HEADERS")
116118
extra_ce_endpoint = os.getenv("JUDGE0_EXTRA_CE_ENDPOINT")
@@ -119,7 +121,7 @@ def _get_custom_client(flavor: Flavor) -> Union[Client, None]:
119121
if flavor == Flavor.CE and ce_endpoint is not None and ce_auth_header is not None:
120122
return Client(
121123
endpoint=ce_endpoint,
122-
auth_headers=eval(ce_auth_header),
124+
auth_headers=loads(ce_auth_header),
123125
)
124126

125127
if (
@@ -129,7 +131,7 @@ def _get_custom_client(flavor: Flavor) -> Union[Client, None]:
129131
):
130132
return Client(
131133
endpoint=extra_ce_endpoint,
132-
auth_headers=eval(extra_ce_auth_header),
134+
auth_headers=loads(extra_ce_auth_header),
133135
)
134136

135137
return None

tests/conftest.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import json
12
import os
23

34
import pytest
@@ -16,7 +17,7 @@ def judge0_ce_client():
1617
if endpoint is None or auth_headers is None:
1718
return None
1819
else:
19-
return clients.Client(endpoint=endpoint, auth_headers=eval(auth_headers))
20+
return clients.Client(endpoint=endpoint, auth_headers=json.loads(auth_headers))
2021

2122

2223
@pytest.fixture(scope="session")
@@ -27,7 +28,7 @@ def judge0_extra_ce_client():
2728
if endpoint is None or auth_headers is None:
2829
return None
2930
else:
30-
return clients.Client(endpoint=endpoint, auth_headers=eval(auth_headers))
31+
return clients.Client(endpoint=endpoint, auth_headers=json.loads(auth_headers))
3132

3233

3334
@pytest.fixture(scope="session")

0 commit comments

Comments
 (0)