Skip to content

Commit

Permalink
Added a simple param inspector to prevent malicious code
Browse files Browse the repository at this point in the history
  • Loading branch information
NekoLuka committed Aug 24, 2023
1 parent 99fe988 commit abf4862
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
5 changes: 5 additions & 0 deletions cliserver.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from configparser import Config
from wsgiref.simple_server import make_server
from typing import Dict, Any, Iterable, Union, List, Tuple, Callable

from inspector import inspector
from localtypes import ResponseEnum
from responder import Responder
from params import merge_request_params
Expand Down Expand Up @@ -40,6 +42,9 @@ def app(environ: Dict[str, Any], start_response: StartResponse) -> Iterable[byte
return responder.respond(start_response, ResponseEnum.MethodNotAllowed, None, [("allow", route.get("method"))])
if len(route["params"]) > 0:
param_dict = merge_request_params(query, content_type, content_length, body)
status, value = inspector(param_dict)
if status != ResponseEnum.OK:
return responder.respond(start_response, ResponseEnum.BadRequest, value, None)
else:
param_dict = dict()
commander = Commander(route["commands"], route["return_stdout"], len(route["params"]) > 0, param_dict)
Expand Down
15 changes: 15 additions & 0 deletions inspector.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from typing import Dict

from localtypes import ResponseEnum


def inspector(params: Dict[str, str]):
error_string = "{symbol} is not allowed in commands"
for value in params.values():
if "&&" in value:
return ResponseEnum.BadRequest, error_string.format(symbol="&&")
elif "||" in value:
return ResponseEnum.BadRequest, error_string.format(symbol="||")
elif ">" in value:
return ResponseEnum.BadRequest, error_string.format(symbol=">")
return ResponseEnum.OK, ""
Empty file removed sanatizer.py
Empty file.

0 comments on commit abf4862

Please sign in to comment.