Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

[Security][SecurityBundle] Change exception thrown by#[IsCsrfTokenValid] attribute#57622

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
eltharin wants to merge5 commits intosymfony:7.4
base:7.4
Choose a base branch
Loading
fromeltharin:csrfExceptionBehavior

Conversation

eltharin
Copy link
Contributor

@eltharineltharin commentedJul 2, 2024
edited by OskarStark
Loading

QA
Branch?7.2
Bug fix?yes
New feature?no
Deprecations?no
IssuesFix#57343
LicenseMIT
ReproducerReproducer

Change InvalidCsrfTokenException behavior :

Actually, when InvalidCsrfTokenException throw, a 403 Response is return or if there is a userAuthenticator, response is converted to 301-Redirect To Login,
For example, For a Basic Contact Form, if the CSRF is bad, I'm redirected to Login Page => Why ?
InvalidCsrfTokenException extends from AuthenticationException but a Csrf Error is not necessarily an authentication error.
And is 403 error code really associated to a CSRF error ?

So I propose to change parent from AuthenticationException to BadRequestHttpException for have a 400 Bad Request Error whitch is most adapted to CSRF error and to not have a redirection to login page;

@eltharineltharin requested a review fromchalasr as acode ownerJuly 2, 2024 08:48
@carsonbotcarsonbot added this to the7.2 milestoneJul 2, 2024
@eltharineltharin changed the titlechange Parent ExceptionInvalidCsrfTokenException - improve behaviorJul 2, 2024
@carsonbotcarsonbot changed the titleInvalidCsrfTokenException - improve behavior[Security][SecurityBundle] InvalidCsrfTokenException - improve behaviorJul 4, 2024
@OskarStarkOskarStark changed the title[Security][SecurityBundle] InvalidCsrfTokenException - improve behavior[Security][SecurityBundle] Improve behavior ofInvalidCsrfTokenExceptionJul 4, 2024
@eltharineltharinforce-pushed thecsrfExceptionBehavior branch from390fe9d to5224b66CompareJuly 11, 2024 11:18
@eltharineltharinforce-pushed thecsrfExceptionBehavior branch 2 times, most recently fromdf7f6f2 to58f68f4CompareJuly 26, 2024 11:37
@eltharin
Copy link
ContributorAuthor

seems test fail because it take old test with depedencies ??

@stof
Copy link
Member

stof commentedAug 6, 2024

TheInvalidCsrfTokenException insecurity/core is meant to be used for invalid CSRF tokens during the authentication. In that case, extending AuthenticationException is the thing we want.

To me, the issue is that theIsCsrfTokenValid attribute should not be reusing that exception.

@stof
Copy link
Member

stof commentedAug 6, 2024

Side note, theIsCsrfTokenValid attribute should probably not have been added insecurity/http. It should probably have been part ofsecurity/csrf instead.

@eltharin
Copy link
ContributorAuthor

eltharin commentedAug 6, 2024
edited
Loading

So I can keep in place InvalidCsrfTokenException and create another on in Security/Csrf extending BadRequestException and link it to the Exception throw in IsCsrfTokenValidAttributeListener ?
thanks for review

@eltharin
Copy link
ContributorAuthor

change is OK, do I move IsCsrfTokenValidAttributeListener in Security/Csrf ?

@eltharineltharin changed the title[Security][SecurityBundle] Improve behavior ofInvalidCsrfTokenException[Security][SecurityBundle] Change Exception thown by IsCsrfTokenValid AttributeAug 7, 2024
@eltharineltharin changed the title[Security][SecurityBundle] Change Exception thown by IsCsrfTokenValid Attribute[Security][SecurityBundle] Change Exception thrown by IsCsrfTokenValid AttributeAug 14, 2024
@fabpotfabpot modified the milestones:7.2,7.3Nov 20, 2024
@kbondkbond added the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelApr 17, 2025
Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

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

I think we should move the attribute/listener

eltharin reacted with thumbs up emoji
Copy link
Member

@kbondkbond left a comment

Choose a reason for hiding this comment

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

Thanks for working on this@eltharin!

Before going further withmoving the listener/attribute to security-csrf, let's see what other @symfony/mergers think. Maybe we should just focus this PR on fixing the bug and the move in a follow-up PR (or not at all).

@@ -11,6 +11,7 @@ CHANGELOG
* Add ability to fetch LDAP roles
* Add `OAuth2TokenHandlerFactory` for `AccessTokenFactory`
* Add discovery support to `OidcTokenHandler` and `OidcUserInfoTokenHandler`
* Change Exception thrown by IsCsrfTokenValid Attribute
Copy link
Member

Choose a reason for hiding this comment

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

This should be insecurity-csrf &security-http

@@ -9,17 +9,17 @@
* file that was distributed with this source code.
*/

namespace Symfony\Component\Security\Http\EventListener;
namespace Symfony\Component\Security\Csrf\EventListener;
Copy link
Member

Choose a reason for hiding this comment

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

Unfortunately, it isn't this simple, we need to keep it in both places, deprecating the one in http. See#46094 for how we did this with theSecurity helper.

@eltharin
Copy link
ContributorAuthor

Ok I revert the move and wait and see

@smnandre
Copy link
Member

Istrongly disagree here.

Regardless of whether the user is logged in, CSRF is100% an authentication problem.

CSRF is an attack that tricks the victim into submitting a malicious request. It inherits the identity and privileges of the victim…
(OWASP)

The CSRF token system -and by extension theIsCsrfTokenValid attribute- have one purpose: to ensure a request was intentionally sent by the user.

If the listener can’t validate the token, it can’t confirm that the user who sent the request is who they claim to be (again: regardless of its login status).

And not being able to confirm the identity or intent behind a request is, by definition, an authentication failure.

@eltharin
Copy link
ContributorAuthor

Istrongly disagree here.

Regardless of whether the user is logged in, CSRF is100% an authentication problem.

CSRF is an attack that tricks the victim into submitting a malicious request. It inherits the identity and privileges of the victim…
(OWASP)

The CSRF token system -and by extension theIsCsrfTokenValid attribute- have one purpose: to ensure a request was intentionally sent by the user.

If the listener can’t validate the token, it can’t confirm that the user who sent the request is who they claim to be (again: regardless of its login status).

And not being able to confirm the identity or intent behind a request is, by definition, an authentication failure.

We can keep 403 code error, the really problem is the login redirection.

@OskarStarkOskarStark changed the title[Security][SecurityBundle] Change Exception thrown by IsCsrfTokenValid Attribute[Security][SecurityBundle] Change exception thrown by#[IsCsrfTokenValid] attributeMay 6, 2025
@fabpotfabpot removed the ❄️ Feature FreezeImportant Pull Requests to finish before the next Symfony "feature freeze" labelMay 24, 2025
@fabpotfabpot modified the milestones:7.3,7.4May 26, 2025
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment
Reviewers

@kbondkbondkbond left review comments

@chalasrchalasrAwaiting requested review from chalasrchalasr is a code owner

Assignees
No one assigned
Projects
None yet
Milestone
7.4
Development

Successfully merging this pull request may close these issues.

Using IsCsrfTokenValid attribute with invalid token redirects user to login page
7 participants
@eltharin@stof@smnandre@kbond@fabpot@OskarStark@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp