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

« back to all changes in this revision

Viewing changes to ivle/dispatch/__init__.py

  • Committer: William Grant
  • Date: 2010-02-23 08:48:09 UTC
  • mfrom: (1673 trunk)
  • mto: This revision was merged to the branch mainline in revision 1674.
  • Revision ID: grantw@unimelb.edu.au-20100223084809-du6dvsxrjhw15ytr
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
import os
31
31
import os.path
32
32
import urllib
 
33
import urlparse
33
34
import cgi
34
35
import traceback
35
36
import logging
44
45
import ivle.webapp.security
45
46
from ivle.webapp.base.plugins import ViewPlugin, PublicViewPlugin
46
47
from ivle.webapp.base.xhtml import XHTMLView, XHTMLErrorView
47
 
from ivle.webapp.errors import HTTPError, Unauthorized, NotFound
 
48
from ivle.webapp.errors import BadRequest, HTTPError, NotFound, Unauthorized
48
49
from ivle.webapp.publisher import Publisher, PublishingError
49
50
from ivle.webapp import ApplicationRoot
50
51
 
157
158
                    raise Unauthorized('Unauthorized: %s' % view)
158
159
                else:
159
160
                    raise Unauthorized()
 
161
 
 
162
            # Non-GET requests from other sites leave us vulnerable to
 
163
            # CSRFs. Block them.
 
164
            referer = req.headers_in.get('Referer')
 
165
            if (referer is None or
 
166
                urlparse.urlparse(req.headers_in.get('Referer')).netloc !=
 
167
                    req.hostname):
 
168
                if req.method != 'GET' and not view.offsite_posts_allowed:
 
169
                    raise BadRequest(
 
170
                        "Non-GET requests from external sites are forbidden "
 
171
                        "for security reasons.")
 
172
 
160
173
            # Render the output
161
174
            view.render(req)
162
175
        except HTTPError, e:
205
218
            XHTMLErrorView(req, NotFound(), e[0]).render(req)
206
219
 
207
220
        return req.OK
 
221
    finally:
 
222
        req.store.close()
208
223
 
209
224
def handle_unknown_exception(req, exc_type, exc_value, exc_traceback):
210
225
    """