-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
4 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
from typing import Literal | ||
from core.colortools import Log | ||
|
||
# Define all types of security prompts | ||
SecurityPromptType = Literal["unsafe_code", "disk_read", "web_requests"] | ||
type_messages: dict[str, str] = { | ||
"unsafe_code": "This program is attempting to execute potentially unsafe python code", | ||
"disk_read": "This program is attempting to access the filesystem", | ||
"web_requests": "This program is attempting to invoke web requests", | ||
} | ||
|
||
# List of allowed actions (used during code execution) | ||
allowed: dict[str, bool] = {} | ||
|
||
|
||
def security_prompt(type: SecurityPromptType) -> None: | ||
# If action already allowed, continue | ||
if type in allowed: | ||
return | ||
# Log the message and get a y/n prompt by user | ||
print(f"{Log.deep_warning(f"[{type.upper()}]")} {Log.deep_info(type_messages[type], True)}. Continue execution?") | ||
print(f"{Log.deep_purple("[Y/n] -> ")}", end="") | ||
# If user agreed | ||
if input().lower() == "y": | ||
# Add action to allowed list | ||
allowed[type] = True | ||
return | ||
# Exit program | ||
print("Permission denied by user.") | ||
exit(1) | ||
return |