This depends entirely on what you do with the input from the webform. In normal use the form gets encoded as x-www-form-urlencoded or json -- Both formats which can be deserialized into a python dictionary completely safely. Of course, they could be deserialized in unsafe ways too -- Make sure that you use libraries that are dedicated to handling this properly (e.g. urlparse or json).
From there, whether the input is safe depends entirely on what the application does with it. (e.g. it is not safe if the application uses eval with input based on the decoded dict).
As for automated testing for this -- I don't know of any way to accomplish this, but these problems are generally pretty easy to mitigate by just following normal best-practices (don't eval code you don't trust, etc. etc.)
python - Does converting json to dict with eval a good choice? - Stack Overflow
python - I need to inject the code with eval() function to complete my task, do i need to changes in eval() funcction? - Stack Overflow
JSON Python Evaluation - Stack Overflow
Is this eval() in python safe? - Stack Overflow
Using eval is not a good way to process JSON:
JSON isn't even valid Python, because of
true,false, andnull.evalwill execute arbitrary Python code, so you are at the mercy of malicious injection of code.
Use the json module available in the standard library instead:
import json
data = json.loads("[1, 2, 3]")
If you're using a version of Python older than 2.6, you'll need to download the module yourself. It's called simplejson and can be downloaded from PyPi.
Yes, very. Use a json decoder instead:
>>> from simplejson import loads
>>> loads(response)
Don't eval(); JSON is not Python even if they look a lot alike. Use the json module to parse it:
import json
with open('text.json') as f:
obj = json.load(f)
This uses json.load() to load the JSON data from an open file object. If you have a string containing the JSON data use json.loads() (note the s).
You can try:
eval("""{
"Herausgeber": "Xema",
"Nummer": "1234-5678-9012-3456",
"Deckung": 2e+6,
"Waehrung": "EURO",
"Inhaber": {
"Name": "Mustermann",
"Vorname": "Max",
"maennlich": true,
"Hobbys": [ "Reiten", "Golfen", "Lesen" ],
"Alter": 42,
"Kinder": [],
"Partner": null
}
}""")
The above code raised an error:
NameError: name 'true' is not defined
So, because the true keyword is not acceptable in python, you'd better not to do this.
Do this istead:
import json
obj = json.loads("""{
"Herausgeber": "Xema",
"Nummer": "1234-5678-9012-3456",
"Deckung": 2e+6,
"Waehrung": "EURO",
"Inhaber": {
"Name": "Mustermann",
"Vorname": "Max",
"maennlich": true,
"Hobbys": [ "Reiten", "Golfen", "Lesen" ],
"Alter": 42,
"Kinder": [],
"Partner": null
}
}""")
print(obj)