Skip to content

Commit 2e29133

Browse files
jensensstevepiercy
andauthored
Apply suggestions from code review
Co-authored-by: Steve Piercy <[email protected]>
1 parent 3e1cb52 commit 2e29133

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

docs/classic-ui/csrf.md

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ myst:
44
"description": "How to protect Plone against CSRF attacks."
55
"property=og:description": "How to protect Plone against CSRF attacks."
66
"property=og:title": "Cross-Site Request Forgery protection in Plone"
7-
"keywords": "CSRF, security, token, protection"
7+
"keywords": "CSRF, security, token, protection, Cross-Site Request Forgery"
88
---
99

1010
(classic-ui-csrf-label)=
@@ -26,20 +26,20 @@ If the token is missing or invalid, the request is rejected.
2626

2727
## Auto protection
2828

29-
In Plone, CSRF protection is done almost transparently by [plone.protect](https://pypi.org/project/plone.protect/).
29+
In Plone, CSRF protection is done almost transparently by [`plone.protect`](https://pypi.org/project/plone.protect/).
3030
One important aspect of `plone.protect` is that it performs the CSRF token validation at the database transaction commit time (at the end of the request), rather than at the beginning of the request.
3131
This means that the view can execute and make changes to the database, but the changes will not be persisted unless a valid CSRF token is present in the request.
3232

33-
When a logged-in user requests a page, Plone automatically includes the CSRF token in all forms by applying a transform (using `plone.transformchain`) that adds a hidden field with the token.
33+
When a logged-in user requests a page, Plone automatically includes the CSRF token in all forms by applying a transform (using `plone.transformchain`) that adds a hidden input with its value set to the token.
3434
This includes, but is not limited to the following:
3535

3636
- add and edit forms
37-
- control-panels
38-
- custom z3c-forms
37+
- control panels
38+
- custom z3c forms
3939

4040
## Manual protection
4141

42-
To ensure that code that is not part of a database transaction, such as code that writes to an external API or a service that is not automatically included in the transaction mechanism, is protected, you will need to manually implement protection for that code.
42+
To ensure that code that is not part of a database transactionsuch as code that writes to an external API or a service that is not automatically included in the transaction mechanismis protected, you will need to manually implement protection for that code.
4343

4444
`plone.protect` offers the `@protect` decorator.
4545
The decorator expects a callable to perform the check.
@@ -63,7 +63,7 @@ Usage example:
6363

6464
### HTTP POST check with `PostOnly`
6565

66-
Checks whether the request is an HTTP POST and raise `Unauthorized` if not.
66+
Checks whether the request is an HTTP POST request, and raises `Unauthorized` if not.
6767
This helps to mitigate clicks on malicious links.
6868

6969
Usage example:
@@ -78,7 +78,7 @@ def write_to_api_or_service(self):
7878
...
7979
```
8080

81-
## How to add a CSRF-Token to a Link or Form
81+
## How to add a CSRF-token to a link or form
8282

8383
To pass a token you need either to:
8484

@@ -94,7 +94,7 @@ To add a token as an HTTP GET parameter to a link in a template, you can utilize
9494
</tal:authenticator>
9595
```
9696

97-
To add a hidden field with a token to a form in a template, the above view can be used too like this:
97+
To add a hidden field with a token to a form in a template, the above view can be used as follows:
9898

9999
```html
100100
<span tal:replace="structure context/@@authenticator/authenticator"/>
@@ -144,10 +144,12 @@ final_url = urlunparse(
144144
To allow certain objects to be modified and written to the database without protection, follow these steps:
145145

146146
1. Identify the modified object as a single object in the database.
147-
2. If an attribute of the object is a "persistent" attribute (e.g., a PersistentDict or PersistentList instance, a BTree, or an annotation), use this instead.
147+
2. If an attribute of the object is a "persistent" attribute (for example, a `PersistentDict` or `PersistentList` instance, a `BTree`, or an `annotation`), use this instead.
148148
3. Use the `safeWrite` function to mark the object as safe for writing.
149149

150-
Note: This is the preferred method for allowing modification and writing of specific objects to the database.
150+
```{note}
151+
This is the preferred method for allowing modification and writing of specific objects to the database.
152+
```
151153

152154
```python
153155
from plone.protect.utils import safeWrite

0 commit comments

Comments
 (0)