Skip to content

Commit 89ff00d

Browse files
Deprecate CSRF Token loading over render_esi as ESI not longer works to start a Session since Symfony 5.4, this was case in Varnish always (#401)
1 parent 12d2df1 commit 89ff00d

File tree

8 files changed

+13
-42
lines changed

8 files changed

+13
-42
lines changed

.github/workflows/test-application.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
database: mysql
8383
dependency-versions: 'highest'
8484
tools: 'composer:v2'
85-
composer-options: '--ignore-platform-reqs'
85+
composer-stability: 'dev'
8686
env:
8787
SYMFONY_DEPRECATIONS_HELPER: weak
8888
DATABASE_URL: mysql://root:root@127.0.0.1/sulu_form_test?serverVersion=5.7
@@ -124,6 +124,10 @@ jobs:
124124
# testing lowest versions.
125125
run: composer remove "*php-cs-fixer*" "*phpstan*" "*rector*" --dev --no-update
126126

127+
- name: Set composer stability
128+
if: ${{ matrix.composer-stability }}
129+
run: composer config minimum-stability ${{ matrix.composer-stability }}
130+
127131
- name: Install composer dependencies
128132
uses: ramsey/composer-install@v2
129133
with:

.php-cs-fixer.dist.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
'phpdoc_types_order' => false,
3232
'single_line_throw' => false,
3333
'single_line_comment_spacing' => false,
34+
'trailing_comma_in_multiline' => false,
3435
])
3536
->setFinder($finder);
3637

Resources/doc/csrf.md

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ sulu_form:
1212
1313
## Ajax
1414
15-
> This solution is required when pages are cached using `Varnish`:
15+
We need to add a new `Route` generates use the csrf token for the ajax based loading:
1616

1717
```yaml
1818
# config/routes/sulu_form.yaml
@@ -24,7 +24,7 @@ sulu_form.token:
2424
_requestAnalyzer: false
2525
```
2626

27-
### A. Ajax with jquery
27+
### A. Ajax without a JavaScript Framework
2828

2929
A simple example for loading the csrf token over ajax looks like this:
3030

@@ -67,7 +67,7 @@ When using [`@sulu/web`](https://github.com/sulu/web-js) / [`sulu/web-twig`](htt
6767
{%- block csrf_token_widget -%}
6868
{{ block('hidden_widget') }}
6969
70-
{% do register_component('csrf-token', { id: id, formName: form.parent.vars.name }) %}
70+
{% do prepare_component('csrf-token', { id: id, formName: form.parent.vars.name }) %}
7171
{% endblock %}
7272
```
7373

@@ -97,20 +97,3 @@ import CsrfToken from './components/csrf-token';
9797
9898
web.registerComponent('csrf-token', CsrfToken);
9999
```
100-
101-
## ESI
102-
103-
> This solution does not work with Symfony 5.4 or later. Please use ajax loading when enabling csrf protection.
104-
105-
Add the following to your form theme to overwrite the default
106-
behaviour of token generation or use the `@SuluForm/themes/basic.html.twig` theme.
107-
108-
```twig
109-
{%- block csrf_token_widget -%}
110-
{{ render_esi(controller('Sulu\\Bundle\\FormBundle\\Controller\\FormTokenController::tokenAction', {
111-
'form': form.parent.vars.name,
112-
'html': true,
113-
_requestAnalyzer: false
114-
})) }}
115-
{% endblock %}
116-
```

Resources/doc/static.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -232,14 +232,6 @@ https://github.com/symfony/symfony/blob/v2.7.0/src/Symfony/Bridge/Twig/Resources
232232
</html>
233233
```
234234

235-
ClientWebsiteBundle:forms:theme.html.twig:
236-
237-
``` twig
238-
{% block token_widget %}
239-
{ render_esi(controller('Sulu\\Bundle\\FormBundle\\Controller\\FormTokenController::tokenAction', { 'form': 'form_type_alias', 'html': true })) }}
240-
{% endblock token_widget %}
241-
```
242-
243235
## E-Mail
244236

245237
You need to create 2 emails(visitor/admin). Default Path are:

Resources/views/themes/basic.html.twig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
If a request is not cacheable (eg. POST request), we can directly render it.
3333
#}
3434
{% if app.request.isMethodCacheable %}
35+
{% deprecated 'CSRF Token over ESI is deprecated and fails since Symfony 5.4, use Ajax based CSRF Token loading, see CSRF docs.' %}
3536
{{ render_esi(controller) }}
3637
{% else %}
3738
{{ render(controller) }}

Tests/Functional/Mail/Fixtures/LoadFormFixture.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222

2323
class LoadFormFixture implements FixtureInterface
2424
{
25-
public function load(ObjectManager $manager)
25+
public function load(ObjectManager $manager): void
2626
{
2727
$form = new Form();
2828
$form->setDefaultLocale('de');

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,10 @@
3232
"symfony/validator": "^4.4 || ^5.0 || ^6.0 || ^7.0",
3333
"symfony/security-csrf": "^4.4 || ^5.0 || ^6.0 || ^7.0",
3434
"symfony/translation": "^4.4 || ^5.0 || ^6.0 || ^7.0",
35-
"twig/twig": "^1.41 || ^2.0 || ^3.0"
35+
"twig/twig": "^1.41 || ^2.6 || ^3.0"
3636
},
3737
"require-dev": {
38-
"doctrine/data-fixtures": "^1.3.3",
38+
"doctrine/data-fixtures": "^1.3.3 || ^2.0",
3939
"doctrine/doctrine-bundle": "^1.10 || ^2.0",
4040
"drewm/mailchimp-api": "^2.2",
4141
"excelwebzone/recaptcha-bundle": "^1.4.2",

phpstan-baseline.neon

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,6 @@ parameters:
4040
count: 1
4141
path: Command/FormGeneratorCommand.php
4242

43-
-
44-
message: "#^Method Sulu\\\\Bundle\\\\FormBundle\\\\Command\\\\FormGeneratorCommand\\:\\:loadTestForm\\(\\) should return Sulu\\\\Bundle\\\\FormBundle\\\\Entity\\\\Form\\|null but returns mixed\\.$#"
45-
count: 1
46-
path: Command/FormGeneratorCommand.php
47-
4843
-
4944
message: "#^Property Sulu\\\\Bundle\\\\FormBundle\\\\Configuration\\\\FormConfiguration\\:\\:\\$adminMailConfiguration \\(Sulu\\\\Bundle\\\\FormBundle\\\\Configuration\\\\MailConfigurationInterface\\) does not accept Sulu\\\\Bundle\\\\FormBundle\\\\Configuration\\\\MailConfigurationInterface\\|null\\.$#"
5045
count: 1
@@ -1385,11 +1380,6 @@ parameters:
13851380
count: 2
13861381
path: Repository/FormRepository.php
13871382

1388-
-
1389-
message: "#^Method Sulu\\\\Bundle\\\\FormBundle\\\\Repository\\\\FormRepository\\:\\:loadById\\(\\) should return Sulu\\\\Bundle\\\\FormBundle\\\\Entity\\\\Form\\|null but returns mixed\\.$#"
1390-
count: 1
1391-
path: Repository/FormRepository.php
1392-
13931383
-
13941384
message: "#^Call to an undefined method Symfony\\\\Component\\\\HttpFoundation\\\\RequestStack\\:\\:getMasterRequest\\(\\)\\.$#"
13951385
count: 1

0 commit comments

Comments
 (0)