Skip to main content

Security for browser forms

Project description

Introduction

This package contains utilities that can help to protect parts of Plone or applications build on top of the Plone framework.

protect decorator

The most common way to use plone.protect is through the protect decorator. This decorator takes a list of checkers as parameters: each checker will check a specific security aspect of the request. For example:

from plone.protect import protect
from plone.protect import PostOnly

@protect(PostOnly)
def SensitiveMethod(self, REQUEST=None):
    # This is only allowed with HTTP POST requests.

This relies on the protected method having a parameter called REQUEST.

HTTP POST

If you only need to allow HTTP POST requests you can use the PostOnly checker:

from plone.protect import PostOnly
from plone.protect import protect

@protect(PostOnly)
def manage_doSomething(self, param, REQUEST=None):
    pass

This checker only operators on HTTP requests; other types of requests are not checked.

Form authentication

A common problem in web applications is Cross Site Request Forgery or CSRF. This is an attack method in which an attacker tricks a browser to do a HTTP form submit to another site. To do this the attacker needs to know the exact form parameters. Form authentication is a method to make it impossible for an attacker to predict those parameters by adding an extra authenticator which can be verified.

To use the form authenticator you first need to insert it into your form. This can be done using a simple TAL statement inside your form:

<span tal:replace="structure context/@@authenticator/authenticator"/>

this will produce a HTML input element with the authentication information. Next you need to add logic somewhere to verify the authenticator. This can be done using a call to the authenticator view. For example:

authenticator=getMultiAdapter((request, context), name=u"authenticator")
if not authenticator.verify():
    raise Unauthorized

You can do the same thing more conveniently using the protect decorator:

from plone.protect import CheckAuthenticator
from plone.protect import protect

@protect(CheckAuthenticator)
def manage_doSomething(self, param, REQUEST=None):
    pass

Changelog

1.0 - April 19, 2008

  • The protect decorator had a serious design flaw which broke it. Added proper tests for it and fixed the problems. [wichert]

1.0rc1 - March 28, 2008

  • Rename plone.app.protect to plone.protect: there is nothing Plone-specific about the functionality in this package and it really should be used outside of Plone as well. [wichert]

  • Made utils.protect work with Zope >= 2.11. [stefan]

1.0b1 - March 7, 2008

  • Refactor the code to offer a generic protect decorator for methods which takes a list of checkers as options. Add checkers for both the authenticator verification and HTTP POST-only. [wichert]

1.0a1 - January 27, 2008

  • Initial release [wichert]

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

plone.protect-1.0.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

plone.protect-1.0-py2.4.egg (18.5 kB view details)

Uploaded Egg

File details

Details for the file plone.protect-1.0.tar.gz.

File metadata

  • Download URL: plone.protect-1.0.tar.gz
  • Upload date:
  • Size: 11.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for plone.protect-1.0.tar.gz
Algorithm Hash digest
SHA256 71a04881b697af3b8cee678e2de3dff8d27c3e4d44b06dec999fb6052bee4fd8
MD5 da463201541d6d01ab5ccc30f007516a
BLAKE2b-256 f4a59a2c19b3eb2d5d3041ea73c89ceaad3607bef008e3eba8c94986711fc0d0

See more details on using hashes here.

File details

Details for the file plone.protect-1.0-py2.4.egg.

File metadata

File hashes

Hashes for plone.protect-1.0-py2.4.egg
Algorithm Hash digest
SHA256 15962807e9eb2e5376f802a343feb2e0a9301216b4ffc9ea6af65b9f8fd3bbdd
MD5 0dc9af3540627273e159c6f0254ac159
BLAKE2b-256 52bf39e14603b0df117c27f95b3705ab671499d1c34e535d88b5c7e8d9d1c247

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page