Securing sessions and admin
It is very dangerous to publicly expose the admin application and the appadmin controllers unless they run over HTTPS. Moreover, your password and credentials should never be transmitted unencrypted. This is true for web2py and any other web application.
In your applications, if they require authentication, you should make the session cookies secure with:
session.secure()
An easy way to setup a secure production environment on a server is to first stop web2py and then remove all the parameters_*.py
files from the web2py installation folder. Then start web2py without a password. This will completely disable admin and appadmin.
nohup python web2py --nogui -p 8001 -i 127.0.0.1 -a '' &
Next, start a second web2py instance accessible only from localhost:
nohup python web2py --nogui -p 8002 -i 127.0.0.1 -a '<ask>'
and create an SSH tunnel from the local machine (the one from which you wish to access the administrative interface) to the server (the one where web2py is running, example.com), using:
ssh -L 8002:127.0.0.1:8002 username@example.com
Now you can access the administrative interface locally via the web browser at localhost:8002
.
This configuration is secure because admin is not reachable when the tunnel is closed (the user is logged out).
This solution is secure on shared hosts if and only if other users do not have read access to the folder that contains web2py; otherwise users may be able to steal session cookies directly from the server.