diff --git a/src/wuttaweb/app.py b/src/wuttaweb/app.py index 6aadc0c..8b4a610 100644 --- a/src/wuttaweb/app.py +++ b/src/wuttaweb/app.py @@ -110,7 +110,11 @@ def make_pyramid_config(settings): The config is initialized with certain features deemed useful for all apps. + + :returns: Instance of + :class:`pyramid:pyramid.config.Configurator`. """ + settings.setdefault('mako.directories', ['wuttaweb:templates']) settings.setdefault('pyramid_deform.template_search_path', 'wuttaweb:templates/deform') @@ -119,6 +123,11 @@ def make_pyramid_config(settings): # configure user authorization / authentication pyramid_config.set_security_policy(WuttaSecurityPolicy()) + # require CSRF token for POST + pyramid_config.set_default_csrf_options(require_csrf=True, + token='_csrf', + header='X-CSRF-TOKEN') + pyramid_config.include('pyramid_beaker') pyramid_config.include('pyramid_deform') pyramid_config.include('pyramid_mako') @@ -143,8 +152,6 @@ def main(global_config, **settings): will need to define their own ``main()`` function, and use that instead. """ - settings.setdefault('mako.directories', ['wuttaweb:templates']) - wutta_config = make_wutta_config(settings) pyramid_config = make_pyramid_config(settings) diff --git a/src/wuttaweb/forms/base.py b/src/wuttaweb/forms/base.py index 0974a50..42abb31 100644 --- a/src/wuttaweb/forms/base.py +++ b/src/wuttaweb/forms/base.py @@ -323,6 +323,7 @@ class Form: """ context['form'] = self context.setdefault('form_attrs', {}) + context.setdefault('request', self.request) # auto disable button on submit if self.auto_disable_submit: diff --git a/src/wuttaweb/helpers.py b/src/wuttaweb/helpers.py index c80c62f..80b9d21 100644 --- a/src/wuttaweb/helpers.py +++ b/src/wuttaweb/helpers.py @@ -38,12 +38,20 @@ instance: This module contains the following references: -* :func:`~wuttaweb.util.get_liburl()` * all names from :mod:`webhelpers2:webhelpers2.html` * all names from :mod:`webhelpers2:webhelpers2.html.tags` +* :func:`~wuttaweb.util.get_liburl()` +* :func:`~wuttaweb.util.get_csrf_token()` +* :func:`~wuttaweb.util.render_csrf_token()` (as :func:`csrf_token()`) + +.. function:: csrf_token + + This is a shorthand reference to + :func:`wuttaweb.util.render_csrf_token()`. + """ from webhelpers2.html import * from webhelpers2.html.tags import * -from wuttaweb.util import get_liburl +from wuttaweb.util import get_liburl, get_csrf_token, render_csrf_token as csrf_token diff --git a/src/wuttaweb/templates/appinfo/configure.mako b/src/wuttaweb/templates/appinfo/configure.mako new file mode 100644 index 0000000..218d092 --- /dev/null +++ b/src/wuttaweb/templates/appinfo/configure.mako @@ -0,0 +1,21 @@ +## -*- coding: utf-8; -*- +<%inherit file="/configure.mako" /> + +<%def name="form_content()"> + +