Spaces:
Sleeping

raufoon commited on
Commit
cabdfd8
·
verified ·
1 Parent(s): 8207997

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +11 -1
app.py CHANGED
@@ -1,6 +1,13 @@
1
  import gradio as gr
2
  import subprocess
3
 
 
 
 
 
 
 
 
4
  def run_code_with_inputs(code: str, inputs: str) -> str:
5
  """
6
  Runs the provided Pseudoku code as a console program with the given inputs.
@@ -11,7 +18,10 @@ def run_code_with_inputs(code: str, inputs: str) -> str:
11
 
12
  Returns:
13
  str: Combined output from the program execution.
14
- """
 
 
 
15
  filename = 'my_program.pseudo'
16
  import os
17
  pseudokey = os.getenv("pseudokey")
 
1
  import gradio as gr
2
  import subprocess
3
 
4
+ def valid(code:str) -> bool:
5
+ import re
6
+ strre = r"\"([^\"\r\n\\]*(\\.[^\"\r\n\\]*)*)\"|'([^'\r\n\\]*(\\.[^'\r\n\\]*)*)'"
7
+ illre = r"(?:\b|\s)(?:system|fpsystem|executeprocess|shellexecute|runcommand|process\.execute|tprocess\.execute|\.execute|createprocess|winexec|shellexecuteex|getenvironmentvariable|getenv|fpgetenv|tprocess\.environment|\.environment|getenvironmentstrings)\b"
8
+ checkcode = re.sub(strre, '', code)
9
+ return re.search(illre, checkcode, re.IGNORECASE) is None
10
+
11
  def run_code_with_inputs(code: str, inputs: str) -> str:
12
  """
13
  Runs the provided Pseudoku code as a console program with the given inputs.
 
18
 
19
  Returns:
20
  str: Combined output from the program execution.
21
+ """
22
+ if not valid(code):
23
+ raise Exception("Code contains keywords which violate Pseudoku's security protocol.")
24
+
25
  filename = 'my_program.pseudo'
26
  import os
27
  pseudokey = os.getenv("pseudokey")