Introduction
============
This package contains utilities that can help protect parts of Plone
or applications build on top of the Plone framework.
1. Restricting to HTTP POST
===========================
a) Using decorator
------------------
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 operates only on HTTP requests; other types of requests
are not checked.
b) Passing request to a function validator
------------------------------------------
Simply::
from plone.protect import PostOnly
...
PostOnly(self.context.REQUEST)
...
2. Form authentication (CSRF)
=============================
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.
Generating the token
--------------------
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.
If you want to create the token value programmatically, use the following::
from plone.protect.authenticator import createToken
token = createToken()
Validating the token
--------------------
a) Zope Component Architecture way
**********************************
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((context, request), name=u"authenticator")
if not authenticator.verify():
raise Unauthorized
b) Using decorator
******************
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
c) Passing request to a function validator
******************************************
Or just::
from plone.protect import CheckAuthenticator
...
CheckAuthenticator(self.context.REQUEST)
...
Headers
-------
You can also pass in the token by using the header ``X-CSRF-TOKEN``. This can be
useful for AJAX requests.
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 (case sensitive)**.
Customized Form Authentication
------------------------------
If you'd like use a different authentication token for different forms,
you can provide an extra string to use with the token::
<tal:authenticator tal:define="authenticator context/@@authenticator">
<span tal:replace="structure python: authenticator.authenticator('a-form-related-value')"/>
</tal:authenticator>
To verify::
authenticator=getMultiAdapter((context, request), name=u"authenticator")
if not authenticator.verify('a-form-related-value'):
raise Unauthorized
With the decorator::
from plone.protect import CustomCheckAuthenticator
from plone.protect import protect
@protect(CustomCheckAuthenticator('a-form-related-value'))
def manage_doSomething(self, param, REQUEST=None):
pass
Automatic CSRF Protection
=========================
Since version 3, plone.protect provides automatic CSRF protection. It does
this by automatically including the auth token to all internal forms when
the user requesting the page is logged in.
Additionally, whenever a particular request attempts to write to the ZODB,
it'll check for the existence of a correct auth token.
Allowing write on read programmatically
---------------------------------------
When you need to allow a known write on read, you've got several options.
Adding a CSRF token to your links
**********************************
If you've got a GET request that causes a known write on read, your first
option should be to simply add a CSRF token to the URLs that result in that
request. ``plone.protect`` provides the ``addTokenToUrl`` function for this
purpose::
from plone.protect.utils import addTokenToUrl
url = addTokenToUrl(url)
If you just want to allow an object to be writable on a request...
******************************************************************
You can use the ``safeWrite`` helper function::
from plone.protect.utils import safeWrite
safeWrite(myobj, request)
Marking the entire request as safe
**********************************
Just add the ``IDisableCSRFProtection`` interface to the current request
object::
from plone.protect.interfaces import IDisableCSRFProtection
from zope.interface import alsoProvides
alsoProvides(request, IDisableCSRFProtection)
Warning! When you do this, the current request is susceptible to CSRF
exploits so do any required CSRF protection manually.
Clickjacking Protection
=======================
plone.protect also provides, by default, clickjacking protection since
version 3.0.
To protect against this attack, Plone uses the X-Frame-Options
header. plone.protect will set the X-Frame-Options value to ``SAMEORIGIN``.
To customize this value, you can set it to a custom value for a custom view
(e.g. ``self.request.response.setHeader('X-Frame-Options', 'ALLOWALL')``),
override it at your proxy server, or you can set the environment variable of
``PLONE_X_FRAME_OPTIONS`` to whatever value you'd like plone.protect to set
this to globally.
You can opt out of this by making the environment variable empty.
Disable All Automatic CSRF Protection
=====================================
To disable all automatic CSRF protection, set the environment variable
``PLONE_CSRF_DISABLED`` value to ``true``.
.. Warning::
It is very dangerous to do this. Do not do this unless the ZEO client
with this setting is not public and you know what you are doing.
.. Note::
This doesn't disable explicit and manual CSRF protection checks.
Fixing CSRF Protection failures in tests
========================================
If you get ``Unauthorized`` errors in tests due to unprotected form submission
where normally automatic protection would be in place you can use the following
blueprint to protect your forms::
from plone.protect.authenticator import createToken
from ..testing import MY_INTEGRATION_TESTING_LAYER
import unittest
class MyTest(unittest.TestCase):
layer = MY_INTEGRATION_TESTING_LAYER
def setUp(self):
self.request = self.layer['request']
# Disable plone.protect for these tests
self.request.form['_authenticator'] = createToken()
# Eventuelly you find this also useful
self.request.environ['REQUEST_METHOD'] = 'POST'
Notes
=====
This package monkey patches a number of modules in order to better handle CSRF
protection::
- Archetypes add forms, add csrf
- Zope2 object locking support
- pluggable auth csrf protection
If you are using a proxy cache in front of your site, be aware that
you will need to clear the entry for ``++resource++protect.js`` every
time you update this package or you will find issues with modals while
editing content.
Compatibility
=============
``plone.protect`` version 3 was made for Plone 5. You can use it on
Plone 4 for better protection, but you will need the
``plone4.csrffixes`` hotfix package as well to avoid getting
needless warnings or errors. See the `hotfix announcement`_ and the
`hotfix page`_.
.. _`hotfix announcement`: https://plone.org/products/plone/security/advisories/security-vulnerability-20151006-csrf
.. _`hotfix page`: https://plone.org/products/plone-hotfix/releases/20151006
Changelog
=========
.. You should *NOT* be adding new change log entries to this file.
You should create a file in the news directory instead.
For helpful instructions, please see:
https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst
.. towncrier release notes start
5.0.2 (2024-10-31)
------------------
Bug fixes:
- Fix tinymce patch of `tinymce.utils.XHR` to not break in TinyMCE 6 where this has been removed.
[petschki] (#106)
5.0.1 (2024-01-22)
------------------
Internal:
- Update configuration files.
[plone devs] (6e36bcc4, 7723aeaf)
5.0.0 (2023-04-15)
------------------
New features:
- Drop support for Python <3.8. (5390ebc6)
Bug fixes:
- Do not hard-depend on `plone.portlets`.
Prepare for Plone with portlets optional.
@jensens (#99)
Internal:
- Update configuration files.
[plone devs] (a9dd65cc)
4.1.8 (2022-12-16)
------------------
Bug fixes:
- Testing: explicitly set response content type header to html. [jeromeperrin] (#97)
4.1.7 (2022-12-02)
------------------
Bug fixes:
- Add missing z3c.zcmlhook dependency. [icemac] (#96)
4.1.6 (2020-09-26)
------------------
Bug fixes:
- Fixed deprecation warning for ``webdav.Lockable.LockableItem``.
[maurits] (#3130)
4.1.5 (2020-04-21)
------------------
Bug fixes:
- Minor packaging updates. (#1)
4.1.4 (2020-03-13)
------------------
Bug fixes:
- Remove deprecation warnings (#90)
4.1.3 (2019-08-23)
------------------
Bug fixes:
- When marking an OOBTree as safe, also mark its buckets as safe. Fixes issues with objects that have many annotations. (#88)
4.1.2 (2019-02-13)
------------------
Bug fixes:
- Avoid deprecation warnings. [gforcada] (#87)
4.1.1 (2018-12-11)
------------------
Breaking changes:
- Remove five.globalrequest dependency.
It has been deprecated upstream (Zope 4).
[gforcada]
4.1.0 (2018-11-02)
------------------
Breaking changes:
- Adapt to changed visibility of `buildfacade` in
`AccessControl.requestmethod`. Requires AccessControl >= 4.0b6
[tschorr]
Bug fixes:
- More Python 2 / 3 compatibility
[pbauer, MatthewWilkes]
- Fix marmoset monkey patching for Python 3
[jensens]
- Don't patch until zcml loaded
[davisagli]
- Put the marmoset on a leash (reset csrf-checks after tests)
[davisagli]
4.0.1 (2018-07-16)
------------------
Bug fixes:
- Fix package dependencies;
``cssselect`` has been an extra of ``lxml`` since 2014 (closes `#79 <https://github.com/plone/plone.protect/issues/79>`_).
[hvelarde]
- Fixed tests to work with merged plone.login
[jensens]
4.0.0 (2018-07-16)
------------------
Breaking changes:
- Version 3.1.3 introduced a Python 3 compatibility fix that broke some Python 2 versions with a ``SyntaxError``.
Reports are mostly for Python 2.7.8 and lower, but also one for 2.7.14, but only on Travis.
So this marks a breaking change.
The incompatibility will be reverted on branch 3.x.
Version 3.1.4 should be safe to use again.
See `issue 74 <https://github.com/plone/plone.protect/issues/74>`_.
and `issue 75 <https://github.com/plone/plone.protect/issues/75>`_.
[maurits]
Bug fixes:
- Avoid CSRF warnings due to generating image scales
stored in a plone.scale.storage.ScalesDict.
[davisagli]
3.1.3 (2018-04-04)
------------------
Bug fixes:
- More Python 2 / 3 compatibility.
Warning: this gives a SyntaxError on Python 2.7.8 or lower.
See `issue 74 <https://github.com/plone/plone.protect/issues/74>`_.
[pbauer]
3.1.2 (2018-02-02)
------------------
Bug fixes:
- Transform does not log a warning for empty responses
(Fixes https://github.com/plone/plone.protect/issues/15)
[fRiSi]
- Add Python 2 / 3 compatibility
[vincero]
3.1.1 (2017-08-27)
------------------
Bug fixes:
- README wording tweaks
[tkimnguyen]
3.1 (2017-08-14)
----------------
New features:
- Log forbidden URLs.
Fixes https://github.com/plone/plone.protect/issues/66
[gforcada]
3.0.26 (2017-08-04)
-------------------
New features:
- Catch ``AttributeError`` on transform.
[hvelarde]
3.0.25 (2017-07-18)
-------------------
Bug fixes:
- Fix logging to no longer write traceback to stdout, but include it in the
logging message instead.
[jone]
3.0.24 (2017-07-03)
-------------------
Bug fixes:
- Remove unittest2 dependency
[kakshay21]
3.0.23 (2016-11-26)
-------------------
Bug fixes:
- Allow ``confirm-action`` for all contexts, instead of only Plone Site root.
This avoids an error when calling it on a subsite.
Fixes `issue #51 <https://github.com/plone/plone.protect/issues/51>`_.
[maurits]
- Code Style: utf8-headers, import sorting, new style namespace declaration, autopep8
[jensens]
- Fix #57: Html must contain "body", otherwise plone.protect breaks.
[jensens]
3.0.22 (2016-11-17)
-------------------
Bug fixes:
- avoid zope.globalrequest.getRequest()
[tschorr]
3.0.21 (2016-10-05)
-------------------
Bug fixes:
- Avoid regenerating image scale over and over in Plone 4.
Avoid (unnoticed) error when refreshing lock in Plone 4,
plus a few other cases that were handled by plone4.csrffixes.
Fixes https://github.com/plone/plone.protect/issues/47
[maurits]
3.0.20 (2016-09-08)
-------------------
Bug fixes:
- Only try the confirm view for urls that are in the portal.
This applies PloneHotfix20160830. [maurits]
- Removed ``RedirectTo`` patch. The patch has been merged to
``Products.CMFFormController`` 3.0.7 (Plone 4.3 and 5.0) and 3.1.2
(Plone 5.1). Note that we are not requiring those versions in our
``setup.py``, because the code in this package no longer needs it.
[maurits]
3.0.19 (2016-08-19)
-------------------
New:
- Added protect.js from plone4.csrffixes. This adds an ``X-CSRF-TOKEN``
header to ajax requests.
Fixes https://github.com/plone/plone.protect/issues/42
[maurits]
Fixes:
- Use zope.interface decorator.
[gforcada]
3.0.18 (2016-02-25)
-------------------
Fixes:
- Fixed AttributeError when calling ``safeWrite`` on a
``TestRequest``, because this has no ``environ.``. [maurits]
3.0.17 (2015-12-07)
-------------------
Fixes:
- Internationalized button in confirm.pt.
[vincentfretin]
3.0.16 (2015-11-05)
-------------------
Fixes:
- Make sure transforms don't fail on redirects.
[lgraf]
3.0.15 (2015-10-30)
-------------------
- make sure to always compare content type with a string when checking
if we should show the confirm-action view.
[vangheem]
- Internationalized confirm.pt
[vincentfretin]
- Disable editable border for @@confirm-action view.
[lgraf]
- Make title and description show up on @@confirm-action view.
[lgraf]
- Allow views to override 'X-Frame-Options' by setting the response header
manually.
[alecm]
- Avoid parsing redirect responses (this avoids a warning on the log files).
[gforcada]
3.0.14 (2015-10-08)
-------------------
- Handle TypeError caused by getToolByName on an
invalid context
[vangheem]
- You can opt out of clickjacking protection by setting the
environment variable ``PLONE_X_FRAME_OPTIONS`` to an empty string.
[maurits]
- Be more flexible in parsing the ``PLONE_CSRF_DISABLED`` environment
variable. We are no longer case sensitive, and we accept ``true``,
``t``, ``yes``, ``y``, ``1`` as true values.
[maurits]
- Avoid TypeError when checking the content-type header.
[maurits]
3.0.13 (2015-10-07)
-------------------
- Always force html serializer as the XHTML variant seems
to cause character encoding issues
[vangheem]
3.0.12 (2015-10-06)
-------------------
- Do not check writes to temporary storage like session storage
[davisagli]
3.0.11 (2015-10-06)
-------------------
- play nicer with inline JavaScript
[vangheem]
3.0.10 (2015-10-06)
-------------------
- make imports backward compatible
[vangheem]
3.0.9 (2015-09-27)
------------------
- patch pluggable auth with marmoset patch because
the patch would not apply otherwise depending on
somewhat-random import order
[vangheem]
- get auto-csrf protection working on the zope root
[vangheem]
3.0.8 (2015-09-20)
------------------
- conditionally patch Products.PluggableAuthService if needed
[vangheem]
- Do not raise ComponentLookupError on transform
[vangheem]
3.0.7 (2015-07-24)
------------------
- Fix pluggable auth CSRF warnings on zope root. Very difficult to reproduce.
Just let plone.protect do it's job also on zope root.
[vangheem]
3.0.6 (2015-07-20)
------------------
- Just return if the request object is not valid.
[vangheem]
3.0.5 (2015-07-20)
------------------
- fix pluggable auth CSRF warnings
[vangheem]
- fix detecting safe object writes on non-GET requests
[vangheem]
- instead of using _v_safe_write users should now use the safeWrite function
in plone.protect.auto
[vangheem]
3.0.4 (2015-05-13)
------------------
- patch locking functions to use _v_safe_write attribute
[vangheem]
- Be able to use _v_safe_write attribute to specify objects are safe to write
[vangheem]
3.0.3 (2015-03-30)
------------------
- handle zope root not having IKeyManager Utility and CRSF protection
not being supported on zope root requests yet
[vangheem]
3.0.2 (2015-03-13)
------------------
- Add ITransform.transformBytes for protect transform to fix compatibility
with plone.app.blocks' ESI-rendering
[atsoukka]
3.0.1 (2014-11-01)
------------------
- auto CSRF protection: check for changes on all the storages
[mamico]
- CSRF test fixed
[mamico]
3.0.0 (2014-04-13)
------------------
- auto-rotate keyrings
[vangheem]
- use specific keyring for protected forms
[vangheem]
- add automatic clickjacking protection(thanks to Manish Bhattacharya)
[vangheem]
- add automatic CSRF protection
[vangheem]
2.0.2 (2012-12-09)
------------------
- Use constant time comparison to verify the authenticator. This is part of the
fix for https://plone.org/products/plone/security/advisories/20121106/23
[davisagli]
- Add MANIFEST.in.
[WouterVH]
- Add ability to customize the token created.
[vangheem]
2.0 - 2010-07-18
----------------
- Update license to BSD following board decision.
http://lists.plone.org/pipermail/membership/2009-August/001038.html
[elro]
2.0a1 - 2009-11-14
------------------
- Removed deprecated AuthenticateForm class and zope.deprecation dependency.
[hannosch]
- Avoid deprecation warning for the sha module in Python 2.6.
[hannosch]
- Specify package dependencies
[hannosch]
1.1 - 2008-06-02
----------------
- Add an optional GenericSetup profile to make it easier to install
plone.protect.
[mj]
1.0 - 2008-04-19
----------------
- The protect decorator had a serious design flaw which broke it. Added
proper tests for it and fixed the problems.
[wichert]
1.0rc1 - 2008-03-28
-------------------
- 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]
Raw data
{
"_id": null,
"home_page": "https://github.com/plone/plone.protect",
"name": "plone.protect",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.8",
"maintainer_email": null,
"keywords": "zope security CSRF",
"author": "Plone Foundation",
"author_email": "plone-developers@lists.sourceforge.net",
"download_url": "https://files.pythonhosted.org/packages/18/c9/52b4e1adac5b931d65007fdc29e9b8ef922c59ea00e4635c2f1ac79c327a/plone_protect-5.0.2.tar.gz",
"platform": null,
"description": "Introduction\n============\n\nThis package contains utilities that can help protect parts of Plone\nor applications build on top of the Plone framework.\n\n\n1. Restricting to HTTP POST\n===========================\n\na) Using decorator\n------------------\n\nIf you only need to allow HTTP POST requests you can use the *PostOnly*\nchecker::\n\n from plone.protect import PostOnly\n from plone.protect import protect\n\n @protect(PostOnly)\n def manage_doSomething(self, param, REQUEST=None):\n pass\n\nThis checker operates only on HTTP requests; other types of requests\nare not checked.\n\nb) Passing request to a function validator\n------------------------------------------\n\nSimply::\n\n from plone.protect import PostOnly\n\n ...\n PostOnly(self.context.REQUEST)\n ...\n\n2. Form authentication (CSRF)\n=============================\n\nA common problem in web applications is Cross Site Request Forgery or CSRF.\nThis is an attack method in which an attacker tricks a browser to do a HTTP\nform submit to another site. To do this the attacker needs to know the exact\nform parameters. Form authentication is a method to make it impossible for an\nattacker to predict those parameters by adding an extra authenticator which\ncan be verified.\n\nGenerating the token\n--------------------\n\nTo use the form authenticator you first need to insert it into your form.\nThis can be done using a simple TAL statement inside your form::\n\n <span tal:replace=\"structure context/@@authenticator/authenticator\"/>\n\nthis will produce a HTML input element with the authentication information.\n\nIf you want to create the token value programmatically, use the following::\n\n from plone.protect.authenticator import createToken\n token = createToken()\n\nValidating the token\n--------------------\n\na) Zope Component Architecture way\n**********************************\n\nNext you need to add logic somewhere to verify the authenticator. This\ncan be done using a call to the authenticator view. For example::\n\n authenticator=getMultiAdapter((context, request), name=u\"authenticator\")\n if not authenticator.verify():\n raise Unauthorized\n\nb) Using decorator\n******************\n\nYou can do the same thing more conveniently using the ``protect`` decorator::\n\n from plone.protect import CheckAuthenticator\n from plone.protect import protect\n\n @protect(CheckAuthenticator)\n def manage_doSomething(self, param, REQUEST=None):\n pass\n\nc) Passing request to a function validator\n******************************************\n\nOr just::\n\n from plone.protect import CheckAuthenticator\n\n ...\n CheckAuthenticator(self.context.REQUEST)\n ...\n\nHeaders\n-------\n\nYou can also pass in the token by using the header ``X-CSRF-TOKEN``. This can be\nuseful for AJAX requests.\n\n\nProtect decorator\n=================\n\nThe most common way to use plone.protect is through the ``protect``\ndecorator. This decorator takes a list of *checkers* as parameters: each\nchecker will check a specific security aspect of the request. For example::\n\n from plone.protect import protect\n from plone.protect import PostOnly\n\n @protect(PostOnly)\n def SensitiveMethod(self, REQUEST=None):\n # This is only allowed with HTTP POST requests.\n\nThis **relies** on the protected method having a parameter called **REQUEST (case sensitive)**.\n\nCustomized Form Authentication\n------------------------------\n\nIf you'd like use a different authentication token for different forms,\nyou can provide an extra string to use with the token::\n\n <tal:authenticator tal:define=\"authenticator context/@@authenticator\">\n <span tal:replace=\"structure python: authenticator.authenticator('a-form-related-value')\"/>\n </tal:authenticator>\n\nTo verify::\n\n authenticator=getMultiAdapter((context, request), name=u\"authenticator\")\n if not authenticator.verify('a-form-related-value'):\n raise Unauthorized\n\nWith the decorator::\n\n from plone.protect import CustomCheckAuthenticator\n from plone.protect import protect\n\n @protect(CustomCheckAuthenticator('a-form-related-value'))\n def manage_doSomething(self, param, REQUEST=None):\n pass\n\n\nAutomatic CSRF Protection\n=========================\n\nSince version 3, plone.protect provides automatic CSRF protection. It does\nthis by automatically including the auth token to all internal forms when\nthe user requesting the page is logged in.\n\nAdditionally, whenever a particular request attempts to write to the ZODB,\nit'll check for the existence of a correct auth token.\n\n\nAllowing write on read programmatically\n---------------------------------------\n\nWhen you need to allow a known write on read, you've got several options.\n\nAdding a CSRF token to your links\n**********************************\n\nIf you've got a GET request that causes a known write on read, your first\noption should be to simply add a CSRF token to the URLs that result in that\nrequest. ``plone.protect`` provides the ``addTokenToUrl`` function for this\npurpose::\n\n from plone.protect.utils import addTokenToUrl\n\n url = addTokenToUrl(url)\n\n\nIf you just want to allow an object to be writable on a request...\n******************************************************************\n\nYou can use the ``safeWrite`` helper function::\n\n from plone.protect.utils import safeWrite\n\n safeWrite(myobj, request)\n\n\nMarking the entire request as safe\n**********************************\n\nJust add the ``IDisableCSRFProtection`` interface to the current request\nobject::\n\n from plone.protect.interfaces import IDisableCSRFProtection\n from zope.interface import alsoProvides\n\n alsoProvides(request, IDisableCSRFProtection)\n\nWarning! When you do this, the current request is susceptible to CSRF\nexploits so do any required CSRF protection manually.\n\n\nClickjacking Protection\n=======================\n\nplone.protect also provides, by default, clickjacking protection since\nversion 3.0.\n\nTo protect against this attack, Plone uses the X-Frame-Options\nheader. plone.protect will set the X-Frame-Options value to ``SAMEORIGIN``.\n\nTo customize this value, you can set it to a custom value for a custom view\n(e.g. ``self.request.response.setHeader('X-Frame-Options', 'ALLOWALL')``),\noverride it at your proxy server, or you can set the environment variable of\n``PLONE_X_FRAME_OPTIONS`` to whatever value you'd like plone.protect to set\nthis to globally.\n\nYou can opt out of this by making the environment variable empty.\n\n\nDisable All Automatic CSRF Protection\n=====================================\n\nTo disable all automatic CSRF protection, set the environment variable\n``PLONE_CSRF_DISABLED`` value to ``true``.\n\n.. Warning::\n\n It is very dangerous to do this. Do not do this unless the ZEO client\n with this setting is not public and you know what you are doing.\n\n.. Note::\n This doesn't disable explicit and manual CSRF protection checks.\n\n\nFixing CSRF Protection failures in tests\n========================================\n\nIf you get ``Unauthorized`` errors in tests due to unprotected form submission\nwhere normally automatic protection would be in place you can use the following\nblueprint to protect your forms::\n\n from plone.protect.authenticator import createToken\n from ..testing import MY_INTEGRATION_TESTING_LAYER\n import unittest\n\n class MyTest(unittest.TestCase):\n\n layer = MY_INTEGRATION_TESTING_LAYER\n\n def setUp(self):\n self.request = self.layer['request']\n # Disable plone.protect for these tests\n self.request.form['_authenticator'] = createToken()\n # Eventuelly you find this also useful\n self.request.environ['REQUEST_METHOD'] = 'POST'\n\n\nNotes\n=====\n\nThis package monkey patches a number of modules in order to better handle CSRF\nprotection::\n\n - Archetypes add forms, add csrf\n - Zope2 object locking support\n - pluggable auth csrf protection\n\nIf you are using a proxy cache in front of your site, be aware that\nyou will need to clear the entry for ``++resource++protect.js`` every\ntime you update this package or you will find issues with modals while\nediting content.\n\n\nCompatibility\n=============\n\n``plone.protect`` version 3 was made for Plone 5. You can use it on\nPlone 4 for better protection, but you will need the\n``plone4.csrffixes`` hotfix package as well to avoid getting\nneedless warnings or errors. See the `hotfix announcement`_ and the\n`hotfix page`_.\n\n.. _`hotfix announcement`: https://plone.org/products/plone/security/advisories/security-vulnerability-20151006-csrf\n.. _`hotfix page`: https://plone.org/products/plone-hotfix/releases/20151006\n\nChangelog\n=========\n\n.. You should *NOT* be adding new change log entries to this file.\n You should create a file in the news directory instead.\n For helpful instructions, please see:\n https://github.com/plone/plone.releaser/blob/master/ADD-A-NEWS-ITEM.rst\n\n.. towncrier release notes start\n\n5.0.2 (2024-10-31)\n------------------\n\nBug fixes:\n\n\n- Fix tinymce patch of `tinymce.utils.XHR` to not break in TinyMCE 6 where this has been removed.\n [petschki] (#106)\n\n\n5.0.1 (2024-01-22)\n------------------\n\nInternal:\n\n\n- Update configuration files.\n [plone devs] (6e36bcc4, 7723aeaf)\n\n\n5.0.0 (2023-04-15)\n------------------\n\nNew features:\n\n\n- Drop support for Python <3.8. (5390ebc6)\n\n\nBug fixes:\n\n\n- Do not hard-depend on `plone.portlets`.\n Prepare for Plone with portlets optional.\n @jensens (#99)\n\n\nInternal:\n\n\n- Update configuration files.\n [plone devs] (a9dd65cc)\n\n\n4.1.8 (2022-12-16)\n------------------\n\n\nBug fixes:\n\n- Testing: explicitly set response content type header to html. [jeromeperrin] (#97)\n\n\n4.1.7 (2022-12-02)\n------------------\n\nBug fixes:\n\n\n- Add missing z3c.zcmlhook dependency. [icemac] (#96)\n\n\n4.1.6 (2020-09-26)\n------------------\n\nBug fixes:\n\n\n- Fixed deprecation warning for ``webdav.Lockable.LockableItem``.\n [maurits] (#3130)\n\n\n4.1.5 (2020-04-21)\n------------------\n\nBug fixes:\n\n\n- Minor packaging updates. (#1)\n\n\n4.1.4 (2020-03-13)\n------------------\n\nBug fixes:\n\n\n- Remove deprecation warnings (#90)\n\n\n4.1.3 (2019-08-23)\n------------------\n\nBug fixes:\n\n\n- When marking an OOBTree as safe, also mark its buckets as safe. Fixes issues with objects that have many annotations. (#88)\n\n\n4.1.2 (2019-02-13)\n------------------\n\nBug fixes:\n\n\n- Avoid deprecation warnings. [gforcada] (#87)\n\n\n4.1.1 (2018-12-11)\n------------------\n\nBreaking changes:\n\n- Remove five.globalrequest dependency.\n It has been deprecated upstream (Zope 4).\n [gforcada]\n\n\n4.1.0 (2018-11-02)\n------------------\n\nBreaking changes:\n\n- Adapt to changed visibility of `buildfacade` in\n `AccessControl.requestmethod`. Requires AccessControl >= 4.0b6\n [tschorr]\n\nBug fixes:\n\n- More Python 2 / 3 compatibility\n [pbauer, MatthewWilkes]\n\n- Fix marmoset monkey patching for Python 3\n [jensens]\n\n- Don't patch until zcml loaded\n [davisagli]\n\n- Put the marmoset on a leash (reset csrf-checks after tests)\n [davisagli]\n\n\n4.0.1 (2018-07-16)\n------------------\n\nBug fixes:\n\n- Fix package dependencies;\n ``cssselect`` has been an extra of ``lxml`` since 2014 (closes `#79 <https://github.com/plone/plone.protect/issues/79>`_).\n [hvelarde]\n\n- Fixed tests to work with merged plone.login\n [jensens]\n\n\n4.0.0 (2018-07-16)\n------------------\n\nBreaking changes:\n\n- Version 3.1.3 introduced a Python 3 compatibility fix that broke some Python 2 versions with a ``SyntaxError``.\n Reports are mostly for Python 2.7.8 and lower, but also one for 2.7.14, but only on Travis.\n So this marks a breaking change.\n The incompatibility will be reverted on branch 3.x.\n Version 3.1.4 should be safe to use again.\n See `issue 74 <https://github.com/plone/plone.protect/issues/74>`_.\n and `issue 75 <https://github.com/plone/plone.protect/issues/75>`_.\n [maurits]\n\nBug fixes:\n\n- Avoid CSRF warnings due to generating image scales\n stored in a plone.scale.storage.ScalesDict.\n [davisagli]\n\n\n3.1.3 (2018-04-04)\n------------------\n\nBug fixes:\n\n- More Python 2 / 3 compatibility.\n Warning: this gives a SyntaxError on Python 2.7.8 or lower.\n See `issue 74 <https://github.com/plone/plone.protect/issues/74>`_.\n [pbauer]\n\n\n3.1.2 (2018-02-02)\n------------------\n\nBug fixes:\n\n- Transform does not log a warning for empty responses\n (Fixes https://github.com/plone/plone.protect/issues/15)\n [fRiSi]\n\n- Add Python 2 / 3 compatibility\n [vincero]\n\n\n3.1.1 (2017-08-27)\n------------------\n\nBug fixes:\n\n- README wording tweaks\n [tkimnguyen]\n\n\n3.1 (2017-08-14)\n----------------\n\nNew features:\n\n- Log forbidden URLs.\n Fixes https://github.com/plone/plone.protect/issues/66\n [gforcada]\n\n\n3.0.26 (2017-08-04)\n-------------------\n\nNew features:\n\n- Catch ``AttributeError`` on transform.\n [hvelarde]\n\n\n3.0.25 (2017-07-18)\n-------------------\n\nBug fixes:\n\n- Fix logging to no longer write traceback to stdout, but include it in the\n logging message instead.\n [jone]\n\n\n3.0.24 (2017-07-03)\n-------------------\n\nBug fixes:\n\n- Remove unittest2 dependency\n [kakshay21]\n\n\n3.0.23 (2016-11-26)\n-------------------\n\nBug fixes:\n\n- Allow ``confirm-action`` for all contexts, instead of only Plone Site root.\n This avoids an error when calling it on a subsite.\n Fixes `issue #51 <https://github.com/plone/plone.protect/issues/51>`_.\n [maurits]\n\n- Code Style: utf8-headers, import sorting, new style namespace declaration, autopep8\n [jensens]\n\n- Fix #57: Html must contain \"body\", otherwise plone.protect breaks.\n [jensens]\n\n\n3.0.22 (2016-11-17)\n-------------------\n\nBug fixes:\n\n- avoid zope.globalrequest.getRequest()\n [tschorr]\n\n\n3.0.21 (2016-10-05)\n-------------------\n\nBug fixes:\n\n- Avoid regenerating image scale over and over in Plone 4.\n Avoid (unnoticed) error when refreshing lock in Plone 4,\n plus a few other cases that were handled by plone4.csrffixes.\n Fixes https://github.com/plone/plone.protect/issues/47\n [maurits]\n\n\n3.0.20 (2016-09-08)\n-------------------\n\nBug fixes:\n\n- Only try the confirm view for urls that are in the portal.\n This applies PloneHotfix20160830. [maurits]\n\n- Removed ``RedirectTo`` patch. The patch has been merged to\n ``Products.CMFFormController`` 3.0.7 (Plone 4.3 and 5.0) and 3.1.2\n (Plone 5.1). Note that we are not requiring those versions in our\n ``setup.py``, because the code in this package no longer needs it.\n [maurits]\n\n\n3.0.19 (2016-08-19)\n-------------------\n\nNew:\n\n- Added protect.js from plone4.csrffixes. This adds an ``X-CSRF-TOKEN``\n header to ajax requests.\n Fixes https://github.com/plone/plone.protect/issues/42\n [maurits]\n\nFixes:\n\n- Use zope.interface decorator.\n [gforcada]\n\n\n3.0.18 (2016-02-25)\n-------------------\n\nFixes:\n\n- Fixed AttributeError when calling ``safeWrite`` on a\n ``TestRequest``, because this has no ``environ.``. [maurits]\n\n\n3.0.17 (2015-12-07)\n-------------------\n\nFixes:\n\n- Internationalized button in confirm.pt.\n [vincentfretin]\n\n\n3.0.16 (2015-11-05)\n-------------------\n\nFixes:\n\n- Make sure transforms don't fail on redirects.\n [lgraf]\n\n\n3.0.15 (2015-10-30)\n-------------------\n\n- make sure to always compare content type with a string when checking\n if we should show the confirm-action view.\n [vangheem]\n\n- Internationalized confirm.pt\n [vincentfretin]\n\n- Disable editable border for @@confirm-action view.\n [lgraf]\n\n- Make title and description show up on @@confirm-action view.\n [lgraf]\n\n- Allow views to override 'X-Frame-Options' by setting the response header\n manually.\n [alecm]\n\n- Avoid parsing redirect responses (this avoids a warning on the log files).\n [gforcada]\n\n3.0.14 (2015-10-08)\n-------------------\n\n- Handle TypeError caused by getToolByName on an\n invalid context\n [vangheem]\n\n- You can opt out of clickjacking protection by setting the\n environment variable ``PLONE_X_FRAME_OPTIONS`` to an empty string.\n [maurits]\n\n- Be more flexible in parsing the ``PLONE_CSRF_DISABLED`` environment\n variable. We are no longer case sensitive, and we accept ``true``,\n ``t``, ``yes``, ``y``, ``1`` as true values.\n [maurits]\n\n- Avoid TypeError when checking the content-type header.\n [maurits]\n\n\n3.0.13 (2015-10-07)\n-------------------\n\n- Always force html serializer as the XHTML variant seems\n to cause character encoding issues\n [vangheem]\n\n3.0.12 (2015-10-06)\n-------------------\n\n- Do not check writes to temporary storage like session storage\n [davisagli]\n\n3.0.11 (2015-10-06)\n-------------------\n\n- play nicer with inline JavaScript\n [vangheem]\n\n\n3.0.10 (2015-10-06)\n-------------------\n\n- make imports backward compatible\n [vangheem]\n\n\n3.0.9 (2015-09-27)\n------------------\n\n- patch pluggable auth with marmoset patch because\n the patch would not apply otherwise depending on\n somewhat-random import order\n [vangheem]\n\n- get auto-csrf protection working on the zope root\n [vangheem]\n\n\n3.0.8 (2015-09-20)\n------------------\n\n- conditionally patch Products.PluggableAuthService if needed\n [vangheem]\n\n- Do not raise ComponentLookupError on transform\n [vangheem]\n\n\n3.0.7 (2015-07-24)\n------------------\n\n- Fix pluggable auth CSRF warnings on zope root. Very difficult to reproduce.\n Just let plone.protect do it's job also on zope root.\n [vangheem]\n\n\n3.0.6 (2015-07-20)\n------------------\n\n- Just return if the request object is not valid.\n [vangheem]\n\n\n3.0.5 (2015-07-20)\n------------------\n\n- fix pluggable auth CSRF warnings\n [vangheem]\n\n- fix detecting safe object writes on non-GET requests\n [vangheem]\n\n- instead of using _v_safe_write users should now use the safeWrite function\n in plone.protect.auto\n [vangheem]\n\n\n3.0.4 (2015-05-13)\n------------------\n\n- patch locking functions to use _v_safe_write attribute\n [vangheem]\n\n- Be able to use _v_safe_write attribute to specify objects are safe to write\n [vangheem]\n\n\n3.0.3 (2015-03-30)\n------------------\n\n- handle zope root not having IKeyManager Utility and CRSF protection\n not being supported on zope root requests yet\n [vangheem]\n\n3.0.2 (2015-03-13)\n------------------\n\n- Add ITransform.transformBytes for protect transform to fix compatibility\n with plone.app.blocks' ESI-rendering\n [atsoukka]\n\n\n3.0.1 (2014-11-01)\n------------------\n\n- auto CSRF protection: check for changes on all the storages\n [mamico]\n\n- CSRF test fixed\n [mamico]\n\n\n3.0.0 (2014-04-13)\n------------------\n\n- auto-rotate keyrings\n [vangheem]\n\n- use specific keyring for protected forms\n [vangheem]\n\n- add automatic clickjacking protection(thanks to Manish Bhattacharya)\n [vangheem]\n\n- add automatic CSRF protection\n [vangheem]\n\n\n2.0.2 (2012-12-09)\n------------------\n\n- Use constant time comparison to verify the authenticator. This is part of the\n fix for https://plone.org/products/plone/security/advisories/20121106/23\n [davisagli]\n\n- Add MANIFEST.in.\n [WouterVH]\n\n- Add ability to customize the token created.\n [vangheem]\n\n\n2.0 - 2010-07-18\n----------------\n\n- Update license to BSD following board decision.\n http://lists.plone.org/pipermail/membership/2009-August/001038.html\n [elro]\n\n2.0a1 - 2009-11-14\n------------------\n\n- Removed deprecated AuthenticateForm class and zope.deprecation dependency.\n [hannosch]\n\n- Avoid deprecation warning for the sha module in Python 2.6.\n [hannosch]\n\n- Specify package dependencies\n [hannosch]\n\n1.1 - 2008-06-02\n----------------\n\n- Add an optional GenericSetup profile to make it easier to install\n plone.protect.\n [mj]\n\n1.0 - 2008-04-19\n----------------\n\n- The protect decorator had a serious design flaw which broke it. Added\n proper tests for it and fixed the problems.\n [wichert]\n\n1.0rc1 - 2008-03-28\n-------------------\n\n- Rename plone.app.protect to plone.protect: there is nothing Plone-specific\n about the functionality in this package and it really should be used outside\n of Plone as well.\n [wichert]\n\n- Made utils.protect work with Zope >= 2.11.\n [stefan]\n\n1.0b1 - March 7, 2008\n---------------------\n\n- Refactor the code to offer a generic protect decorator for methods\n which takes a list of checkers as options. Add checkers for both the\n authenticator verification and HTTP POST-only.\n [wichert]\n\n1.0a1 - January 27, 2008\n------------------------\n\n- Initial release\n [wichert]\n",
"bugtrack_url": null,
"license": "BSD",
"summary": "Security for browser forms",
"version": "5.0.2",
"project_urls": {
"Homepage": "https://github.com/plone/plone.protect"
},
"split_keywords": [
"zope",
"security",
"csrf"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "5e6fe04fee079fae952e074d0db4a1e73665fa6bded6fe64f985ca3bf8194687",
"md5": "606b64d5dc98e0ecb29cd0a0bc228904",
"sha256": "aed731433f5193b26aa2fda94ca83226b6aa01a3634aaa74da1bd7ed7cf35c28"
},
"downloads": -1,
"filename": "plone.protect-5.0.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "606b64d5dc98e0ecb29cd0a0bc228904",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8",
"size": 31701,
"upload_time": "2024-10-31T21:55:46",
"upload_time_iso_8601": "2024-10-31T21:55:46.178021Z",
"url": "https://files.pythonhosted.org/packages/5e/6f/e04fee079fae952e074d0db4a1e73665fa6bded6fe64f985ca3bf8194687/plone.protect-5.0.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "18c952b4e1adac5b931d65007fdc29e9b8ef922c59ea00e4635c2f1ac79c327a",
"md5": "88b5bc54b8d2cc8e1e0ee8430c523912",
"sha256": "26a7d6f0a0b7987a2714fd3ddff052c50831879b8f6f6482ee7d83cd871366e4"
},
"downloads": -1,
"filename": "plone_protect-5.0.2.tar.gz",
"has_sig": false,
"md5_digest": "88b5bc54b8d2cc8e1e0ee8430c523912",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8",
"size": 35127,
"upload_time": "2024-10-31T21:55:48",
"upload_time_iso_8601": "2024-10-31T21:55:48.905155Z",
"url": "https://files.pythonhosted.org/packages/18/c9/52b4e1adac5b931d65007fdc29e9b8ef922c59ea00e4635c2f1ac79c327a/plone_protect-5.0.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-10-31 21:55:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "plone",
"github_project": "plone.protect",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"tox": true,
"lcname": "plone.protect"
}