Skip to content

Commit 9859d0a

Browse files
authored
[DOCS] Clarify security concerns for newAction (#5853)
This change adds a clarification for typical errors that might lead to a security vulnerability in actions, where new objects are created. Existing code snippets are adapted properly. additionally, wrong usages of `IgnoreValidation` are removed from code snippets.,
1 parent 67dc66b commit 9859d0a

File tree

7 files changed

+35
-22
lines changed

7 files changed

+35
-22
lines changed

Documentation/CodeSnippets/Extbase/Annotation/IgnoreValidation.rst.txt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
class BlogController extends AbstractController
1212
{
1313
/**
14-
* Displays a form for creating a new blog
14+
* Displays a form for editing an existing blog
1515
*
16-
* @IgnoreValidation("newBlog")
16+
* @IgnoreValidation("blog")
1717
*/
18-
public function newAction(?Blog $newBlog = null): ResponseInterface
18+
public function editAction(Blog $blog): ResponseInterface
1919
{
20-
$this->view->assign('newBlog', $newBlog);
20+
$this->view->assign('blog', $blog);
2121
$this->view->assign(
2222
'administrators',
2323
$this->administratorRepository->findAll()

Documentation/CodeSnippets/Extbase/Controllers/BlogControllerNew.rst.txt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,17 +5,18 @@
55
:caption: Class T3docs\\BlogExample\\Controller\\BlogController
66
77
use Psr\Http\Message\ResponseInterface;
8+
use TYPO3\CMS\Core\Utility\GeneralUtility;
89
use T3docs\BlogExample\Domain\Model\Blog;
910
1011
class BlogController extends AbstractController
1112
{
1213
/**
1314
* Displays a form for creating a new blog
1415
*/
15-
public function newAction(?Blog $newBlog = null): ResponseInterface
16+
public function newAction(): ResponseInterface
1617
{
1718
$this->view->assignMultiple([
18-
'newBlog' => $newBlog,
19+
'newBlog' => GeneralUtility::makeInstance(Blog::class),
1920
'administrators' => $this->administratorRepository->findAll(),
2021
]);
2122
return $this->htmlResponse();

Documentation/CodeSnippets/Extbase/View/HtmlResponse.rst.txt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,21 @@
33
44
.. code-block:: php
55
:caption: Class T3docs\\BlogExample\\Controller\\BlogController
6-
:emphasize-lines: 18
6+
:emphasize-lines: 19
77
88
use Psr\Http\Message\ResponseInterface;
9+
use TYPO3\CMS\Core\Utility\GeneralUtility;
910
use T3docs\BlogExample\Domain\Model\Blog;
1011
1112
class BlogController extends AbstractController
1213
{
1314
/**
1415
* Displays a form for creating a new blog
1516
*/
16-
public function newAction(?Blog $newBlog = null): ResponseInterface
17+
public function newAction(): ResponseInterface
1718
{
1819
$this->view->assignMultiple([
19-
'newBlog' => $newBlog,
20+
'newBlog' => GeneralUtility::makeInstance(Blog::class),
2021
'administrators' => $this->administratorRepository->findAll(),
2122
]);
2223
return $this->htmlResponse();

Documentation/ExtensionArchitecture/Extbase/Reference/Annotations.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,10 @@ Read more about this on https://usetypo3.com/dtos-in-extbase/ or see a
6969
:abbr:`CRUD (Create, Read, Update, Delete)` example for this on
7070
https://github.com/garvinhicking/gh_validationdummy/
7171

72+
.. warning::
73+
`IgnoreValidation()` must not be used for domain models supporting
74+
extbase file uploads, because this leads to a property mapping error.
75+
7276
.. _extbase-annotation-orm:
7377

7478
ORM (object relational model) annotations

Documentation/ExtensionArchitecture/Extbase/Reference/Controller/ActionController.rst

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,14 +36,6 @@ parameters as this is necessary for the validation.
3636

3737
.. include:: /CodeSnippets/Extbase/Controllers/BlogControllerNew.rst.txt
3838

39-
The validation of domain object can be explicitly disabled by the annotation
40-
:php:`@TYPO3\CMS\Extbase\Annotation\IgnoreValidation`. This might be necessary
41-
in actions that show forms or create domain objects.
42-
43-
Default values can, as usual in PHP, just be indicated in the method signature.
44-
In the above case, the default value of the parameter :php:`$newBlog` is set to
45-
:php:`NULL`.
46-
4739
If the action should render the view you can return :php:`$this->htmlResponse()`
4840
as a shortcut for taking care of creating the response yourself.
4941

@@ -61,6 +53,18 @@ development system with activated debugging.
6153
:php:`errorAction()` have special meanings in initialization and error handling
6254
and are no Extbase actions.
6355

56+
.. danger::
57+
An action where a new object is constructed (e.g. `newAction`) does usually
58+
not need the argument as action property.
59+
60+
`public function newAction(?Blog $blog = null)` may be a security
61+
vulnerability, if no access checks are performed, since an attacker can
62+
provide any blog UID and view the data of the record in the form.
63+
64+
It is also not required to use the `IgnoreValidation` attribute in order
65+
for validation to work properly. Extbase takes care of assigning data
66+
to the form in case of validation failures.
67+
6468
.. _extbase_class_hierarchy-define_initialization_code:
6569

6670
Define initialization code

Documentation/ExtensionArchitecture/Extbase/Reference/Validation/Index.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,8 @@ The following rules validate each controller argument:
121121

122122
* If there is set an annotation
123123
:php:`\TYPO3\CMS\Extbase\Annotation\IgnoreValidation` for the argument,
124-
no validation is done.
124+
no validation is done. This option must not be used when working with
125+
extbase file upload, because it leads to a property mapping error.
125126

126127
* Validators added in the annotation of the action are applied.
127128

Documentation/ExtensionArchitecture/Extbase/Reference/_Annotations/_IgnoreValidation.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,20 +11,22 @@
1111

1212
final class BlogController extends ActionController
1313
{
14-
#[IgnoreValidation(['argumentName' => 'newBlog'])]
15-
public function newAction(?Blog $newBlog = null): ResponseInterface
14+
#[IgnoreValidation(['argumentName' => 'blog'])]
15+
public function editAction(Blog $blog): ResponseInterface
1616
{
1717
// Do something
18+
$this->view->assign('blog', $blog);
1819
return $this->htmlResponse();
1920
}
2021

2122
/**
2223
* Use annotations instead for compatibility with TYPO3 v11:
23-
* @IgnoreValidation("newBlog")
24+
* @IgnoreValidation("blog")
2425
*/
25-
public function newAction2(?Blog $newBlog = null): ResponseInterface
26+
public function editAction2(Blog $blog): ResponseInterface
2627
{
2728
// Do something
29+
$this->view->assign('blog', $blog);
2830
return $this->htmlResponse();
2931
}
3032
}

0 commit comments

Comments
 (0)