Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Security] Return 401 when using use_forward for form authentication #6957

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

Merged
merged 1 commit into from
Mar 23, 2013

Conversation

gunnarlium
Copy link
Contributor

Q A
Bug fix? yes
New feature? no
BC breaks? yes
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -
  • document the BC breaks in UPDATE and CHANGELOG

Currently, unauthenticated requests gets handled as exceptions and forwarded to the FormAuthenticationEntryPoint::start. When using use_forward = true, this method does not modify the status code, which means that final response to the end user will use a 500 status code. This is not right, as there is not a server problem, the problem is that the user is not authenticated. The status code should be 401.

This PR checks if the sub request to the form view is successful, and sets an X-Status-Code header if it is.This might break applications that rely on the 500 error code being returned for unauthenticated requests.

@@ -53,7 +53,12 @@ public function start(Request $request, AuthenticationException $authException =
if ($this->useForward) {
$subRequest = $this->httpUtils->createRequest($request, $this->loginPath);

return $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
$response = $this->httpKernel->handle($subRequest, HttpKernelInterface::SUB_REQUEST);
if ($response->getStatusCode() == 200) {
Copy link
Contributor

Choose a reason for hiding this comment

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

if (200 === $response->getStatusCode()) {

@jfsimon
Copy link
Contributor

jfsimon commented Mar 4, 2013

You're right, the response status code change is a BC break.
Therefor this PR should be based on master.

@fabpot
Copy link
Member

fabpot commented Mar 23, 2013

Can you update the CHANGELOG before I merge this PR? Thanks.

@gunnarlium
Copy link
Contributor Author

@fabpot Done.

fabpot added a commit that referenced this pull request Mar 23, 2013
This PR was merged into the master branch.

Discussion
----------

[Security] Return 401 when using use_forward for form authentication

| Q             | A
| ------------- | ---
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | yes
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

- [x] document the BC breaks in UPDATE and CHANGELOG

Currently, unauthenticated requests gets handled as exceptions and forwarded to the FormAuthenticationEntryPoint::start. When using use_forward = true, this method does not modify the status code, which means that final response to the end user will use a 500 status code. This is not right, as there is not a server problem, the problem is that the user is not authenticated. The status code should be 401.

This PR checks if the sub request to the form view is successful, and sets an X-Status-Code header if it is.This might break applications that rely on the 500 error code being returned for unauthenticated requests.

Commits
-------

b5597e8 [Security] Return 401 when using use_forward for form authentication
@fabpot fabpot closed this Mar 23, 2013
@fabpot fabpot merged commit b5597e8 into symfony:master Mar 23, 2013
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 this pull request may close these issues.

3 participants