~azzar1/unity/add-show-desktop-key

« back to all changes in this revision

Viewing changes to ivle/dispatch/request.py

  • Committer: William Grant
  • Date: 2010-02-25 13:53:09 UTC
  • Revision ID: grantw@unimelb.edu.au-20100225135309-nfuzipcjj9zfu4ma
Set 'secure' flag on cookies if served over a direct or proxied HTTPS connection.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
    import mod_python.Session
30
30
    import mod_python.Cookie
31
31
    import mod_python.util
 
32
    import mod_python.apache
32
33
except ImportError:
33
34
    # This needs to be importable from outside Apache.
34
35
    pass
40
41
from ivle.webapp.base.plugins import CookiePlugin
41
42
import ivle.webapp.security
42
43
 
 
44
 
 
45
class PotentiallySecureFileSession(mod_python.Session.FileSession):
 
46
    """A mod_python FileSession that sets secure cookie when appropriate.
 
47
 
 
48
    A secure cookie will be set if the request itself is over HTTPS, or if
 
49
    a proxy in front has set X-Forwarded-Proto: https. Otherwise the cookie
 
50
    will be insecure.
 
51
    """
 
52
    def make_cookie(self):
 
53
        cookie = super(PotentiallySecureFileSession, self).make_cookie()
 
54
        if (self._req.is_https() or
 
55
            self._req.headers_in.get('X-Forwarded-Proto') == 'https'):
 
56
            cookie.secure = True
 
57
        return cookie
 
58
 
 
59
 
43
60
class Request:
44
61
    """An IVLE request object. This is presented to the IVLE apps as a way of
45
62
    interacting with the web server and the dispatcher.
255
272
        """
256
273
        # Cache the session object and set the timeout to 24 hours.
257
274
        if not hasattr(self, 'session'):
258
 
            self.session = mod_python.Session.FileSession(self.apache_req,
259
 
                                               timeout = 60 * 60 * 24)
 
275
            self.session = PotentiallySecureFileSession(
 
276
                self.apache_req, timeout = 60 * 60 * 24)
260
277
        return self.session
261
278
 
262
279
    def get_fieldstorage(self):