CSC/ECE 517 Fall 2012/ch1 1w28 mv: Difference between revisions

From Expertiza_Wiki
Jump to navigation Jump to search
(Created page with "Editing CSC/ECE 517 Fall 2012/ch1 1w28 mv * w28 mv")
 
No edit summary
Line 1: Line 1:
Editing CSC/ECE 517 Fall 2012/ch1 1w28 mv
== Security risks ==
*
Special care '''must''' be taken when using <code>eval</code> with data from an untrusted source. For instance, assuming that the <code>get_data()</code> function gets data from the Internet, this [[Python (programming language)|Python]] code is insecure:
w28
<source lang="python">
mv
session['authenticated'] = False
data = get_data()
foo = eval(data)
</source>
 
An attacker could supply the program with the string <code>"session.update(authenticated=True)"</code> as data, which would update the <code>session</code> dictionary to set an authenticated key to be True. To remedy this, all data which will be used with <code>eval</code> must be escaped, or it must be run without access to potentially harmful functions.

Revision as of 00:22, 15 September 2012

== Security risks ==

Special care must be taken when using eval with data from an untrusted source. For instance, assuming that the get_data() function gets data from the Internet, this Python code is insecure:

session['authenticated'] = False
data = get_data()
foo = eval(data)

An attacker could supply the program with the string "session.update(authenticated=True)" as data, which would update the session dictionary to set an authenticated key to be True. To remedy this, all data which will be used with eval must be escaped, or it must be run without access to potentially harmful functions.