Python from Python: restricting functionality?

0 votes
I'm building a corporate web system in Python which allows scripts to be uploaded and run serverside. I'm using Python as it is a simple language to write the scripts in. However, there is a security hazard there, I want to block all function calls except a limited subset. Is there a mechanism I can use to do this, or some other technique? Do I need to use something else like Lua?

Please help me with this.
Jun 24 in Python by ana1504.k
• 7,870 points
20 views

1 answer to this question.

0 votes
This doesn't seem like a good idea but you can try the following:

You could sanitize a string that contains the Python code (and by sanitize I mean you need to do like a few hundred malicious unit tests and heavily test that the sanitation is adequate) with RegEx to only match the function calls you want and then call eval() on the string.
answered Jun 24 by SDeb
• 13,180 points

Related Questions In Python

0 votes
1 answer

How can I find out the index of an element from row and column in Python?

You probably want to use np.ravel_multi_index: [code] import numpy ...READ MORE

answered Apr 16, 2018 in Python by charlie_brown
• 7,720 points
96 views
0 votes
1 answer

How can I convert a list of dictionaries from a CSV into a JSON object in Python?

You could try using the AST module. ...READ MORE

answered Apr 17, 2018 in Python by anonymous
783 views
0 votes
2 answers

Extracting data from a JSON file in Python

Here is what i found and was ...READ MORE

answered Nov 27, 2018 in Python by Rupali
9,553 views
0 votes
1 answer

Unable to take input from user in Python

num = input("enter number") print(num) READ MORE

answered May 1, 2018 in Python by aayushi
• 750 points
39 views
+1 vote
2 answers

how can i count the items in a list?

Syntax :            list. count(value) Code: colors = ['red', 'green', ...READ MORE

answered Jul 6 in Python by Neha
• 330 points

edited Jul 8 by Kalgi 333 views
0 votes
1 answer

How to exit from Python without traceback?

You are presumably encountering an exception and ...READ MORE

answered Oct 9, 2018 in Python by SDeb
• 13,180 points
95 views
0 votes
1 answer

Get path from open file in Python

The key here is the name attribute ...READ MORE

answered Jan 16 in Python by SDeb
• 13,180 points
29 views