[Tutor] [OT] Secure coding guidelines

Wayne srilyk at gmail.com
Sun Oct 11 00:04:56 CEST 2009


On Sat, Oct 10, 2009 at 4:31 AM, Didar Hossain <didar.hossain at gmail.com>wrote:

> Since I am learning Python, I was wondering if there are any good
> references on secure
> coding practices. Books, guides or even any howtos would suffice.
>

I'm not sure of any references, but I know of a few things. First, for
versions < 3.0 use raw_input (ref:
http://docs.python.org/library/functions.html#raw_input )

It's a lot more secure than input()

Data validation is also a good thing: rather than a function like this:

def mysum(n1, n2):
   return n1 + n2

validate your data:

def mysum(n1, n2):
    try:
        n1 = int(n1)
        n2 = int(n2)
    except ValueError:
        print "Error! Cannot convert values to int!"

    return n1+n2

Or do something similar.

HTH,
Wayne
-- 
To be considered stupid and to be told so is more painful than being called
gluttonous, mendacious, violent, lascivious, lazy, cowardly: every weakness,
every vice, has found its defenders, its rhetoric, its ennoblement and
exaltation, but stupidity hasn’t. - Primo Levi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20091010/7d2cce1d/attachment-0001.htm>


More information about the Tutor mailing list