Skip to content

Commit 1907a9a

Browse files
author
patched.codes[bot]
committed
Patched introduction/apis.py
1 parent fc0b6db commit 1907a9a

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

introduction/apis.py

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,6 @@
1212

1313
from .utility import *
1414
from .views import authentication_decorator
15-
16-
17-
# steps -->
18-
# 1. covert input code to corrosponding code and write in file
19-
# 2. extract inputs form 2nd code
20-
# 3. Run the code
21-
# 4. get the result
22-
@csrf_exempt
2315
def ssrf_code_checker(request):
2416
if request.user.is_authenticated:
2517
if request.method == 'POST':
@@ -56,7 +48,6 @@ def ssrf_code_checker(request):
5648
# Insufficient Logging & Monitoring
5749

5850

59-
@csrf_exempt
6051
# @authentication_decorator
6152
def log_function_checker(request):
6253
if request.method == 'POST':
@@ -66,31 +57,31 @@ def log_function_checker(request):
6657
dirname = os.path.dirname(__file__)
6758
log_filename = os.path.join(dirname, "playground/A9/main.py")
6859
api_filename = os.path.join(dirname, "playground/A9/api.py")
69-
f = open(log_filename,"w")
70-
f.write(log_code)
71-
f.close()
72-
f = open(api_filename,"w")
73-
f.write(api_code)
74-
f.close()
60+
with open(log_filename,"w") as f:
61+
f.write(sanitize_input(log_code))
62+
with open(api_filename,"w") as f:
63+
f.write(sanitize_input(api_code))
7564
# Clearing the log file before starting the test
76-
f = open('test.log', 'w')
77-
f.write("")
78-
f.close()
65+
with open('test.log', 'w') as f:
66+
f.write("")
7967
url = "http://127.0.0.1:8000/2021/discussion/A9/target"
8068
payload={'csrfmiddlewaretoken': csrf_token }
8169
requests.request("GET", url)
8270
requests.request("POST", url)
8371
requests.request("PATCH", url, data=payload)
8472
requests.request("DELETE", url)
85-
f = open('test.log', 'r')
86-
lines = f.readlines()
87-
f.close()
73+
with open('test.log', 'r') as f:
74+
lines = f.readlines()
8875
return JsonResponse({"message":"success", "logs": lines},status = 200)
8976
else:
9077
return JsonResponse({"message":"method not allowed"},status = 405)
9178

79+
def sanitize_input(user_input):
80+
# Implement your sanitization logic here
81+
# For example, you can escape special characters or use a library like bleach
82+
return user_input.replace("<", "&lt;").replace(">", "&gt;")
83+
9284
#a7 codechecking api
93-
@csrf_exempt
9485
def A7_disscussion_api(request):
9586
if request.method != 'POST':
9687
return JsonResponse({"message":"method not allowed"},status = 405)
@@ -107,9 +98,7 @@ def A7_disscussion_api(request):
10798
return JsonResponse({"message":"success"},status = 200)
10899

109100
return JsonResponse({"message":"failure"},status = 400)
110-
111101
#a6 codechecking api
112-
@csrf_exempt
113102
def A6_disscussion_api(request):
114103
test_bench = ["Pillow==8.0.0","PyJWT==2.4.0","requests==2.28.0","Django==4.0.4"]
115104

@@ -122,17 +111,15 @@ def A6_disscussion_api(request):
122111
except Exception as e:
123112
return JsonResponse({"message":"failure"},status = 400)
124113

125-
@csrf_exempt
126114
def A6_disscussion_api_2(request):
127115
if request.method != 'POST':
128116
return JsonResponse({"message":"method not allowed"},status = 405)
129117
try:
130118
code = request.POST.get('code')
131119
dirname = os.path.dirname(__file__)
132120
filename = os.path.join(dirname, "playground/A6/utility.py")
133-
f = open(filename,"w")
134-
f.write(code)
135-
f.close()
121+
with open(filename, "w") as f:
122+
f.write(sanitize(code))
136123
except:
137124
return JsonResponse({"message":"missing code"},status = 400)
138-
return JsonResponse({"message":"success"},status = 200)
125+
return JsonResponse({"message":"success"},status = 200)

0 commit comments

Comments
 (0)