Skip to content

[Csrf] Moved CSRF component outside Security namespace #36423

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

Closed
wants to merge 1 commit into from

Conversation

wouterj
Copy link
Member

@wouterj wouterj commented Apr 11, 2020

Q A
Branch? master
Bug fix? no
New feature? no
Deprecations? yes
Tickets n/a
License MIT
Doc PR tbd

This PR moves the CSRF component outside the Security namespace.

Advantages

Considerations

  • For renaming classes, I tried using the same techniques as where done in the Messenger component (ref [Messenger] Move Transports to separate packages #35422). I need to test it in a real application to see if the BC layers are working as expected.

  • I think this requires changes to the subtree split configuration.

  • The symfony/security-csrf should probably be marked as deprecated on packagist.

  • The TokenNotFoundException used to extend Symfony\Component\Security\Core\Exception\RuntimeException. I've changed this to \RuntimeException, to remove the dependency on the (completely irrelevant) symfony/security-core package. Previously this was considered a BC break ([Security] Remove dependency on security-core from security-csrf #16494), but as we're now moving all classes anyway, I think this is probably the only moment we can make such a change.

@@ -11,7 +11,7 @@

namespace Symfony\Bridge\Twig\Extension;

use Symfony\Component\Security\Csrf\CsrfTokenManagerInterface;
use Symfony\Component\Csrf\CsrfTokenManagerInterface;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ALL similar changes are BC breaks

Copy link
Member Author

@wouterj wouterj Apr 12, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure about this? There is a class_alias between the old and the new namespace.

I just tested this by linking the new CSRF component, and the old CSRF component + twig bridge into the vendor/ directory (+ autoload config). Then this code works as expected (without error, but with the deprecation):

<?php

require_once 'vendor/autoload.php';

use Symfony\Component\Security\Csrf\CsrfTokenManager;
use Symfony\Bridge\Twig\Extension\CsrfRuntime;

$manager = new CsrfTokenManager();
$runtime = new CsrfRuntime($manager);

echo $runtime->getCsrfToken('foo');

* CSRF not directly related on the rest of Security (nor has dependencies on it)
* CSRF is usable in any form or request
* CSRF is configured through the FrameworkBundle
* This allows re-introducing the `symfony/security` component (see symfony#33558)
@wouterj wouterj force-pushed the security/separate-csrf branch from ab71cd1 to bca5f15 Compare April 12, 2020 14:05
@wouterj
Copy link
Member Author

wouterj commented Apr 15, 2020

I just found #34004 (comment) . Would it make sense to only deprecate CSRF and not introduce Symfony\Component\Csrf (ref https://scotthelme.co.uk/csrf-is-dead/)?

@javiereguiluz
Copy link
Member

@wouterj even if that's true ... do you think that 100% of web apps are going to be updated immediately to stop using CSRF? Looks unlikely ... so I think we should go on with this PR.

@nicolas-grekas
Copy link
Member

If browsers implement all that is needed to protect against csrf, there's nothing to upgrade. I think this is worth considering yes: planning to drop the component altogether.

@nicolas-grekas
Copy link
Member

The plan could be to update the documentation first, then deprecate in 5.4 or even 6.1.

@wouterj
Copy link
Member Author

wouterj commented Apr 15, 2020

@javiereguiluz the nice thing about deprecation is that there is no need for immediate change. The CSRF component will be around until at least November 2024 if we deprecate it now (and given that it does only depend on 1 exception class from security, we can also add Symfony 6 support to it, extending it's life even longer).

If we're considering to remove the component in Symfony 6 (or at least: no longer install it in core components), I don't think it makes sense to do the change in this PR. When in the 5.x lifecycle we're deprecating this component wouldn't really matter for this. (I agree that first updating the docs and then deprecating might be a better plan)

@fabpot
Copy link
Member

fabpot commented Apr 15, 2020

I agree with the deprecation of the CSRF feature in 5.1.

@stof
Copy link
Member

stof commented Apr 15, 2020

Unfortunately, for software targetting enterprise, IE 11 is not dead yet. And so CSRF is not dead yet either there.

@wouterj
Copy link
Member Author

wouterj commented Apr 15, 2020

According to https://caniuse.com/#feat=same-site-cookie-attribute , IE 11 on Windows 10 does support the SameSite cookie attribute. Windows 8(.1) reaches end of life at January 10 2023. So this is within eol for 5.4, and I think it's fair to release a 5.4 version that supports symfony/security-core:^6.0 as well.

@stof
Copy link
Member

stof commented Apr 15, 2020

Well, even the EOL defined by Microsoft does not reflect the reality of enterprises, due to the time it takes them to migrate. Windows 7 reached its EOL in January 2020, but over the last 90 days, my stats for Incenteev reveal that my pages views for Windows users are still 33% for Windows 7, 10% for Windows 8.x and 57% for Windows 10 (and things get even worse if I restrict stats to page views done with IE, as Windows 7 then reaches 70%).
And having to stay on Symfony 5.4 LTS until its end of support just because symfony/form 6 assumes that CSRF is not an issue anymore would be a bad news (we would loose any other improvement to Symfony). I'd rather see what the need for CSRF is at the time of the 6.0 release than 3 or 4 years later, to make the decision.

@stof
Copy link
Member

stof commented Apr 15, 2020

And deprecating CSRF in 5.1 means that you consider that CSRF is dead in May 2020 (when 5.1 is released), not in January 2023. And that's definitely not the case in the enterprise world.

@wouterj
Copy link
Member Author

wouterj commented Apr 15, 2020

Ah, "just because symfony/form 6 assumes that CSRF is not an issue anymore would be a bad news " is a very valid point imho. The integration of CSRF lives in all other components, so deprecating the CSRF component would mean removing the integrations from the other components in 6.0.

In any case, I think what still applies is to close this PR and revisit it for 5.4: We either deprecate & drop CSRF or we move CSRF to the root component namespace.

@fabpot
Copy link
Member

fabpot commented Apr 15, 2020

Ok, let's close this PR then and revisit the issue when we will work on 5.4.

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

Successfully merging this pull request may close these issues.

6 participants