I'm trying to set up an authentication scheme in my CherryPy webapp.
I've seen both simple and complex snippets of code in the Wiki, such
as:
http://tools.cherrypy.org/wiki/AuthenticationAndAccessRestrictions
http://tools.cherrypy.org/wiki/CustomSessionAuth
http://tools.cherrypy.org/wiki/NewAuth
http://tools.cherrypy.org/wiki/VeryVerySimpleAuthFramework
http://tools.cherrypy.org/wiki/MultiAuth
I've always found security to be a bit of a conundrum. I'm working on
a web application that requires some reasonable level of security. The
passwords are stored as a double-md5-hashed value in a database. I
don't have any issues "getting" the password out of the database, but
am curious as to the best method for creating and enforcing user
sessions when working on webapps. I remember reading many years ago
when studying PHP that setting sessions when working with web
applications is important: you shouldn't set the password in the
session, but setting the username only may result in weak security.
Does anyone have any opinions on the best way to attack security in a
CherryPy web application?
Thanks!
-j
http://tools.cherrypy.org/wiki/RestfulAuth gives me a 'Create this page'
button once I log in using the guest account. Do you not get that?
Robert Brewer
fuma...@aminus.org
How hard is it to create a basic authentication scheme? I'm certainly
not a security guru and I'm aware that making one mistake could result
in a security hole. Some folks have indicated to me (privately) that I
should simply create a form, get the returned variables and then
compare the password to the database. If everything checks out I can
simply create a session and proceed with letting the user in to the
private sites.
Thoughts?
-j
--
Best regards,
arjuna
http://www.brahmaforces.com
That's one of the things I like about web frameworks like Django and
TurboGears; they seem to make it very easy to set up simple
authentication so that credentials are required to view certain pages.
I have poured over quite a bit of CherryPy documentation and haven't
really found any "great" article on how to write something simple,
very secure and straightforward...
Thoughts?
Except it isn't always as easy as you'd like when you need to extend it (I
had to write specific authentication support for Django and it hasn't been
an easy task because their documentation assumes only the easy path and
their code is not always straightforward).
>
> I have poured over quite a bit of CherryPy documentation and haven't
> really found any "great" article on how to write something simple,
> very secure and straightforward...
Because CP is just low-level. I mean what is secure to you might not be to
someone else. Basic auth+SSL is considered today as a default secure
mecanism for the web, is that good enough for you? Probably not.
What are your requirements? How do you consider security?
Eventually it'd be probably be great to have on single resource that
discuss all the options but that hasn't happened yet :)
- Sylvain
--
Sylvain Hellegouarch
http://www.defuze.org
Nope. Well actually you can if you do it via XHR (Ajax to sound foxy) but
if the user doesn't put the valid credentials the popup will show up
anyway. Basically it's due to the way browsers implement RFC 2617.
<shamelessplug>
I had explained that in CherryPy Essentials actually ;)
Look there for some code on that subject:
https://code.cherrypyessentials.com/trunk/Chapter_8/
</shamelessplug>
- Sylvain
No; tools.decode and enecode are for translating 7-bit HTTP strings to
unicode and back.
You probably want to encrypt passwords using md5 (or better).
Robert Brewer
fuma...@aminus.org
I don't think RFC 2617 specifies the login has to be requested bia a
popup. I think it's an implementation detail.
There are however issues with RFC 2617 nonetheless (the fact Digest is
hardly fully implemented correctly anywhere, questions with encoded
unicode data, etc.)
- Sylvain
It provides common form based authentication with decorators.
The examples on that page will give you a good idea. It's very similar
to what TurboGears and django have, except that you get to implement the
actual authentication functions yourself. No ties to a specific database
scheme or even a database at all.
-jj
>
> And doing _anything_ at the browser in javascript that you can't or
> don't completely verify at the
> server is a seriously bad security lapse since it's trivially easy to
> compromise at the client.
You are supposed to do validation serverside anyway.
>
> SSL/TLS is the proper tool for encrypting the packet stream between
> client and server. Don't even
> think of rolling your own.
Given you have enough resources for TLS (one IP for each domain, proper
cert from verisign and friends, CPU cycles). If you don't, doing client
side md5(password) is a proper solution.
cheers
Paul
Argh!
If you do client-side password hashing like that then you
can just send the password in the clear.
-jj
One huge benefit of Basic/Digest is that many http libs support it out
of the box (httplib2 for example). As for logging out, if you resend
the 401 and stop accepting the authorized header, then the user is
effectively logged out.
>>
>> And doing _anything_ at the browser in javascript that you can't or
>> don't completely verify at the
>> server is a seriously bad security lapse since it's trivially easy to
>> compromise at the client.
> You are supposed to do validation serverside anyway.
>
I think one important point here is that you rely on browsers to
handle the actual logging in instead of dealing with forms, error
messages, etc. This may not be that advantageous if you want a slick
login form, but in the same way you might trust a library to support
some function, you can let the browser support this client side
action. Hopefully, you can rely on the experience, testing and
maturity of the browsers to handle things instead of doing everything
yourself.
>>
>> SSL/TLS is the proper tool for encrypting the packet stream between
>> client and server. Don't even
>> think of rolling your own.
> Given you have enough resources for TLS (one IP for each domain, proper
> cert from verisign and friends, CPU cycles). If you don't, doing client
> side md5(password) is a proper solution.
You bring up a good point. Yet, even if you don't have a signed cert,
it doesn't mean you are out of luck with encrypting the packet stream.
Again, if you have a client that is not a browser, something like
verisign certs may mean nothing.
One aspect I think is really helpful is that by using HTTP based
authentication, you can potentially benefit from many available tools.
I personally don't see why an HTTP auth dialog is so terrible, but
that doesn't it isn't to some people. That said, even if you are
rolling your own authentication scheme, it seems very helpful to
provide a standard HTTP based authentication pattern in order to
support non-browser clients easily.
Just my two cents!
Eric Larson
>
> cheers
> Paul
>
> >
>
Or am I wrong?
I hate to reinvent the wheel (it'd be great to simply call a cherrypy
function that ends up relying on http-based authentication), but I
don't see an alternative in my solution.
-j
--
"Do not meddle in the affairs of wizards, for they are subtle and
quick to anger."
-Tolkien
They use home made authentication scheme. Have you looked at OpenID or
OAuth so that you rely on third-party providers to handle the
authentication?
- Sylvain
> What is insecure about the following:
>
> 1) Accept a password in a form
> 2) Encrypt in javascript using MD5 (better than passing a clear text
> password)
It's the same as sending it in the clear. If somebody intercepts the message,
then he does not need to know the real password, as it is sufficient to
resend the same md5 sum. To make it more secure you'd need to use some kind
of challange-response mechanism, where the md5 depends not only on the
password, but also on some one-use random token.
> 3) Store in mysql encrypted either using the same MD5 or mysqls naitive
> encryption
> 4) When validating do the same as the above and check against database
> password.
You'd be effectively just comparing value stored in the database to the value
sent over the network, without any encryption, as both would already contain
md5 of the password.
>
> Yes I could use ssl to transfer between the browser and server when i
> purchase the cert, but till then...This is better than passing clear text
> passwords.
Not much really.
--
Paweł Stradomski
cheers
Paul
How does PHP handle what? There are no automatic login forms built-in
to PHP. You have to create your own, or steal someone else's, just like
in CherryPy.
--
Tim Roberts, ti...@probo.com
Providenza & Boekelheide, Inc.
> W liście arjuna z dnia wtorek 15 lipca 2008:
>> Hi All,
>>
>
>> What is insecure about the following:
>>
>> 1) Accept a password in a form
>> 2) Encrypt in javascript using MD5 (better than passing a clear text
>> password)
> It's the same as sending it in the clear. If somebody intercepts the message,
> then he does not need to know the real password, as it is sufficient to
> resend the same md5 sum. To make it more secure you'd need to use some kind
> of challange-response mechanism, where the md5 depends not only on the
> password, but also on some one-use random token.
This illustrates a very important point. Encryption is really easy to
get completely wrong. If you need something that is truly secure, you
probably need to borrow something that someone else has written.