Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with twig 3.9 #343

Open
jderusse opened this issue Apr 22, 2024 · 1 comment · May be fixed by #344
Open

Incompatibility with twig 3.9 #343

jderusse opened this issue Apr 22, 2024 · 1 comment · May be fixed by #344

Comments

@jderusse
Copy link

Since twigphp/Twig#3999 we cannot use ob_ method to get the generated output.
As a result, the the output generated by the CSPNode is empty.
Which lead to an exception Invalid script, you should use a single <script> tag.

My template twig is:

            {% cspscript %}
                <script>
                  alert('foo')
                </script>
            {% endcspscript %}

the generated PHP code is


        // line 315
        yield "            ";
        ob_start();
        yield "                <script>
                  alert('foo')
                </script>
            ";
        $this->env->getRuntime('Nelmio\SecurityBundle\Twig\CSPRuntime')->getListener()->addSha('script-src', 'sha384-Ee2u6OPPCwK16NVPQ56ORx7yfwYmCmO+bYzRi4OsT+wo/iiP9f8p/+7GNTdT2++t');
echo ob_get_clean();
        // line 320
        yield "        ";

The content of ob_get_clean(); is "".

@jderusse jderusse linked a pull request Apr 22, 2024 that will close this issue
@Tjeerd
Copy link

Tjeerd commented Apr 26, 2024

Yup, most of my pipelines are failing this week because of this update to Twig. Because our default, and enforced, security policy is to use NelmioSecurityBundle , this has quite an impact.

Thanks to @jderusse for the fix/improvement. Let's get it merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants