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

Improved an error message related to controllers#27499

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

Merged
fabpot merged 1 commit intosymfony:masterfromjaviereguiluz:controller_error
Jun 27, 2018

Conversation

@javiereguiluz
Copy link
Member

QA
Branch?master
Bug fix?no
New feature?yes
BC breaks?no
Deprecations?no
Tests pass?yes
Fixed tickets-
LicenseMIT
Doc PR-

This proposal is irrelevant for experienced users but it may be useful for newcomers. After having delivered several introductory Symfony training, I can say that when someone addsreturn "some string..."; in their controller, the error message is confusing:

before

Maybe we can reword it a bit? (I'm open for suggestions to improve the error message)

after

ScullWM, linaori, and yceruto reacted with thumbs up emoji
@ScullWM
Copy link
Contributor

Great for newcomers!
Just guessing, expect giving bad habbit to newcomers, why don't Symfony create a Response with this given string ?

@javiereguiluz
Copy link
MemberAuthor

@ScullWM allowing to return strings was discussed in the past (specially because "some frameworks" allow to do that). But it was decided to keep requiringResponse objects. At first it might be like a bad decision, but it helps newcomers realize that Symfony apps are always about HTTP Request/Response workflow. No matter if it's a silly "Hello World" app or the most complex app ever created. It's always the same: you are given a Request object and you must return a Response object.

That's why I think we should keep the current behaviour: if people learn about Request/Response soon, they will understand Symfony easier.

ScullWM, plozmun, lyrixx, and noniagriconomie reacted with thumbs up emoji

@lyrixx
Copy link
Member

@javiereguiluz Is your master branch a bit outdated ? Because I made a patch recently that display a "better" trace that highlight the controller. And I can not see it on your screenshot.

Anyway, 👍 with this PR.

@javiereguiluz
Copy link
MemberAuthor

@lyrixx the code change and the screenshot were done in a Symfony 4.1 app and then I copied the code to the master branch 🙈

@linaori
Copy link
Contributor

You can always create your own listener that transforms the string into a response. The SensioFrameworkExtraBundle does this for arrays with the@Template annotation.

@nicolas-grekasnicolas-grekas modified the milestones:4.2,nextJun 5, 2018
$response =$event->getResponse();
}else {
$msg =sprintf('The controller must return a response (%s given).',$this->varToString($response));
$msg =sprintf('The controller must return aSymfony\Component\HttpFoundation\Response object but it returned: %s.',is_string($response) ?sprintf('"%s" string',$response) :$this->varToString($response));

Choose a reason for hiding this comment

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

I'd suggest moving theis_string check inside thevarToString method

javiereguiluz reacted with thumbs up emoji
}

if (is_string($var)) {
returnsprintf('"%s" string',$var);
Copy link
Member

Choose a reason for hiding this comment

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

Here,$var can be very long, I would strip the string in such cases, maybe using the first 200 or so chars.

javiereguiluz reacted with thumbs up emoji
Copy link
Member

Choose a reason for hiding this comment

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

Using a generated string in an exception message makes me nervous (it can contain end-user submitted values).

javiereguiluz reacted with thumbs up emoji
@javiereguiluz
Copy link
MemberAuthor

I've updated this feature to trim long strings.

Before:

before

After:

after


About this other comment from Fabien (#27499 (comment)) I'm not sure how to solve it. Thanks!

@javiereguiluz
Copy link
MemberAuthor

javiereguiluz commentedJun 27, 2018
edited
Loading

Thanks to Twig's automatic escaping, I think we're good here. I've tested with some of the examples given by OWASP to prevent XSS (https://www.owasp.org/index.php/Testing_for_Reflected_Cross_site_scripting_(OTG-INPVAL-001)) and it looks like it's working:

xss-error-page

Can anyone spot other "attack vectors" in this code? Thanks

$response =$event->getResponse();
}else {
$msg =sprintf('The controller must return aresponse (%s given).',$this->varToString($response));
$msg =sprintf('The controller must return aSymfony\Component\HttpFoundation\Response object but it returned %s.',$this->varToString($response));

Choose a reason for hiding this comment

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

Maybe add double quotes around the ...\Request

@fabpot
Copy link
Member

Thank you@javiereguiluz.

@fabpotfabpot merged commit7510c3a intosymfony:masterJun 27, 2018
fabpot added a commit that referenced this pull requestJun 27, 2018
…ereguiluz)This PR was squashed before being merged into the 4.2-dev branch (closes#27499).Discussion----------Improved an error message related to controllers| Q             | A| ------------- | ---| Branch?       | master| Bug fix?      | no| New feature?  | yes| BC breaks?    | no| Deprecations? | no| Tests pass?   | yes| Fixed tickets | -| License       | MIT| Doc PR        | -This proposal is irrelevant for experienced users but it may be useful for newcomers. After having delivered several introductory Symfony training, I can say that when someone adds `return "some string...";` in their controller, the error message is confusing:![before](https://user-images.githubusercontent.com/73419/40959468-0faf790a-689d-11e8-9ce1-f6e0caf4b113.png)Maybe we can reword it a bit? (I'm open for suggestions to improve the error message)![after](https://user-images.githubusercontent.com/73419/40959505-29747070-689d-11e8-834e-92bf18760469.png)Commits-------7510c3a Improved an error message related to controllers
@nicolas-grekasnicolas-grekas removed this from thenext milestoneNov 1, 2018
@nicolas-grekasnicolas-grekas added this to the4.2 milestoneNov 1, 2018
This was referencedNov 3, 2018
Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

@fabpotfabpotfabpot approved these changes

@nicolas-grekasnicolas-grekasnicolas-grekas approved these changes

Assignees

No one assigned

Projects

None yet

Milestone

4.2

Development

Successfully merging this pull request may close these issues.

7 participants

@javiereguiluz@ScullWM@lyrixx@linaori@fabpot@nicolas-grekas@carsonbot

[8]ページ先頭

©2009-2025 Movatter.jp