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

Skip to content

[ErrorRenderer] Show generic message in non-debug mode #34197

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
Nov 4, 2019

Conversation

yceruto
Copy link
Member

@yceruto yceruto commented Oct 31, 2019

Q A
Branch? 4.4
Bug fix? no
New feature? no
Deprecations? no
Tickets -
License MIT
Doc PR -

I agree with @Tobion here #34158 (comment), so let's always show the detail message, but for 5xx errors we'll send a generic message instead.

/cc @dunglas wdyt?

@yceruto
Copy link
Member Author

yceruto commented Oct 31, 2019

(Travis dep=high failure is normal)

dunglas
dunglas previously approved these changes Oct 31, 2019
@jvasseur
Copy link
Contributor

I disagree here, exceptions messages are never meant for the end user, even for non-500. I have lots of code that throws NotFound/AccessDenied exceptions with messages that are meant for logs/debug and not for the end user.

@nicolas-grekas
Copy link
Member

There is only one way here: in non-debug mode, do the same as 4.x did before the introduction of the new components.

@jvasseur
Copy link
Contributor

One example where it could leak sensitive data is when using the Security annotation from the SensioFrameworkExtraBundle, the error message contains the expression that denied access while the error is a 403.

@dunglas dunglas dismissed their stale review October 31, 2019 09:57

See comments

@Tobion
Copy link
Contributor

Tobion commented Oct 31, 2019

I think we should make this configurable. By default, the exception messages would not be shown. Let people configure which exception classes / status codes are allowed to show the message. This is one of the few really useful features of the fos rest bundle and it should be part of the core IMO, see fos_rest.exception.messages config

@yceruto yceruto force-pushed the error_detail branch 3 times, most recently from a012a09 to 92585eb Compare October 31, 2019 12:26
@yceruto yceruto changed the title [ErrorRenderer] Hide real exception message for 5xx errors only [ErrorRenderer] Show generic message in non-debug mode Oct 31, 2019
@yceruto
Copy link
Member Author

yceruto commented Oct 31, 2019

PR Updated according to comments.

I like the @Tobion's idea of somehow returning the real message for specific friendly exceptions, e.g. validation errors related to the request, etc. Let's create a dedicated issue to discuss it. Thanks!

@fabpot
Copy link
Member

fabpot commented Nov 4, 2019

Thank you @yceruto.

fabpot added a commit that referenced this pull request Nov 4, 2019
…yceruto)

This PR was merged into the 4.4 branch.

Discussion
----------

[ErrorRenderer] Show generic message in non-debug mode

| Q             | A
| ------------- | ---
| Branch?       | 4.4
| Bug fix?      | no
| New feature?  | no
| Deprecations? | no
| Tickets       | -
| License       | MIT
| Doc PR        | -

I agree with @Tobion here #34158 (comment), so let's always show the detail message, but for 5xx errors we'll send a generic message instead.

/cc @dunglas wdyt?

Commits
-------

45f1a5e Show generic message in non-debug mode
@fabpot fabpot merged commit 45f1a5e into symfony:4.4 Nov 4, 2019
@yceruto yceruto deleted the error_detail branch November 4, 2019 13:20
if ($debug) {
$message = $exception->getMessage();
} else {
$message = 404 === $exception->getStatusCode() ? 'Sorry, the page you are looking for could not be found.' : 'Whoops, looks like something went wrong.';
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry but I'm totally👎 on this. The message does not make any sense in an API context.

Copy link
Member

Choose a reason for hiding this comment

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

Would you like a generic message like: Not Found (404 error) or do you have any other message in mind?

Copy link
Contributor

Choose a reason for hiding this comment

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

I prefer no message at all. What we put here it's arbitrary.

Copy link
Member Author

Choose a reason for hiding this comment

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

Other suggestion for this 404 message is this one:

The server has not found anything matching the Request-URI

Taken from https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html

Copy link
Member Author

@yceruto yceruto Nov 4, 2019

Choose a reason for hiding this comment

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

This is how the message would look for JSON format (non-debug mode):

{
    "title": "Not Found",
    "status": 404,
    "detail": "The server has not found anything matching the Request-URI"
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Whoops, looks like something went wrong.

Why does it say "something" went wrong when it's clear what went "wrong" based on the status code?
Why does it say "wrong" when in theory I can return a successful error code from getStatusCode?

Copy link
Member Author

Choose a reason for hiding this comment

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

Whoops, looks like something went wrong.

Why does it say "something" went wrong when it's clear what went "wrong" based on the status code?

Because I want to be more friendly with an explicit and verbose error message. It's not arbitrary, it was taken from here https://github.com/symfony/symfony/blob/2.0/src/Symfony/Component/HttpKernel/Debug/ExceptionHandler.php#L77-L83 (since Symfony 2.0)

Why does it say "wrong" when in theory I can return a successful error code from getStatusCode?

Which wouldn't make sense to me.

Copy link
Contributor

Choose a reason for hiding this comment

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

The title already gives the text explanation of the status code. Anything else is just arbitrary and I don't see why you keep insisting on the detail property.

Copy link
Member Author

Choose a reason for hiding this comment

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

Please, revert these changes if you still think it's useless and arbitrary, but then I'll be agaisnt to have "detail" property for debug mode only, because (1) it is not intended for debugging information according to rfc; (2) for the same request consistently we must return the same response, at least this would apply to the members defined in the rfc, "detail" is one of them.

Anything else is considered an "extensions". In this case "exception" property (rendered on debug mode only) is an extension property.

It's problable that we're using the wrong names here and we should have called them "message" & "trace" respectively as extensions of the problem detail for debug mode only, so we can get rid of them on non-debug mode.

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.

8 participants