Skip to content

[HttpFoundation] JSONP callback validation #20127

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 3 commits into from
Closed

[HttpFoundation] JSONP callback validation #20127

wants to merge 3 commits into from

Conversation

ro0NL
Copy link
Contributor

@ro0NL ro0NL commented Oct 2, 2016

Q A
Branch? "master"
Bug fix? yes
New feature? yes
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #17923
License MIT
Doc PR reference to the documentation PR, if any

Maybe this is too small for a new dep, but at least it's stable. Symfony itself will make no assumption on validation by default, ie. things should keep working as usual.

@javiereguiluz
Copy link
Member

For now I'm 👎 because the replaced feature is minuscule and introducing a new dependency is not worth it (specially now, that Symfony is furiously removing dependencies ... even between its components).

@theofidry
Copy link
Contributor

To be fair @javiereguiluz the dependency in question is fairly small as well, its scope is the scope of the feature.

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 2, 2016

Understand.. however if im correct the philosophy is to not reinvent the wheel.

Problem is we cant workaround symfony's out-of-the-box validation.

@theofidry
Copy link
Contributor

@ro0NL you can workaround it by overriding it, it's a public method. You're PR is not changing anything in this regard.

@wouterj
Copy link
Member

wouterj commented Oct 2, 2016

please note that this is introducing an optional dependency.

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 2, 2016

@theofidry fair enough :) but still is cumbersome imo.

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 2, 2016

We could also just copy the "right" regex.. i'd prefer the dependency though.

@fabpot
Copy link
Member

fabpot commented Oct 3, 2016

IIUC, if you don't install the dependency, the callback is not validated anymore?

Anyway, I don't see why we should depend on an external library for that. Is there any issue with our code? If yes, let's fix it. But as that's not something that changes over time, I don't see the advantage of depending on something else.

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 3, 2016

if you don't install the dependency, the callback is not validated anymore?

Correct.. I dont mind forcing validation either, but if so, it should be correct. So basically there are 2 viable options;

  • make it a hard dependency
  • copy/fix the regex

Im not sure we should keep patching the regex whenever it shows being incorrect, ie. a stable/tested version is available => https://github.com/willdurand/JsonpCallbackValidator.

@fabpot
Copy link
Member

fabpot commented Oct 3, 2016

Let's fix our regex.

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 3, 2016

Shall we just take https://github.com/willdurand/JsonpCallbackValidator/blob/master/src/JsonpCallbackValidator.php#L11 then? (// taken from ...) And forget about reserved keywords.. or take those as well?

@fabpot
Copy link
Member

fabpot commented Oct 3, 2016

You can take everything (and don't forget to include all the author/license information with it).

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 3, 2016

👍 ill have a look tonight.

@ro0NL
Copy link
Contributor Author

ro0NL commented Oct 3, 2016

@fabpot ready. I kept the unicode support as well.. so basically we only added support for bracket notation.. (taken from willdurand/JsonpCallbackValidator).

https://regex101.com/r/bSdU1i/2

@@ -89,11 +89,16 @@ public static function fromJsonString($data = null, $status = 200, $headers = ar
public function setCallback($callback = null)
{
if (null !== $callback) {
// taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/
$pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*+$/u';
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed the possessive + as this wont affect number of steps to match due ^$.

// taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/
$pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*+$/u';
// taken from http://www.geekality.net/2011/08/03/valid-javascript-identifier/ and https://github.com/willdurand/JsonpCallbackValidator
$pattern = '/^[$_\p{L}][$_\p{L}\p{Mn}\p{Mc}\p{Nd}\p{Pc}\x{200C}\x{200D}]*(?:\[(?:"(?:\\\.|[^"\\\])*"|\'(?:\\\.|[^\'\\\])*\'|\d+)\])*?$/u';
Copy link
Member

Choose a reason for hiding this comment

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

You need to add the copyright and the license

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Can you have a look.. not sure i did it correct.

@fabpot
Copy link
Member

fabpot commented Oct 5, 2016

👍

1 similar comment
@dunglas
Copy link
Member

dunglas commented Oct 5, 2016

👍

@fabpot
Copy link
Member

fabpot commented Oct 5, 2016

Thank you @ro0NL.

fabpot added a commit that referenced this pull request Oct 5, 2016
This PR was submitted for the master branch but it was merged into the 2.7 branch instead (closes #20127).

Discussion
----------

[HttpFoundation] JSONP callback validation

| Q             | A
| ------------- | ---
| Branch?       | "master"
| Bug fix?      | yes
| New feature?  | yes
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | #17923
| License       | MIT
| Doc PR        | reference to the documentation PR, if any

Maybe this is too small for a new dep, but at least it's stable. Symfony itself will make no assumption on validation by default, ie. things should keep working as usual.

Commits
-------

1159f8b [HttpFoundation] JSONP callback validation
@fabpot fabpot closed this Oct 5, 2016
@ro0NL ro0NL deleted the http-foundation/jsonp-callback-validation branch October 5, 2016 19:18
fabpot added a commit that referenced this pull request Oct 7, 2016
This PR was merged into the 3.2-dev branch.

Discussion
----------

Fix typo in copyright comment

| Q             | A
| ------------- | ---
| Branch?       | master
| Tests pass?   | yes
| License       | MIT

This was merged on 3.2 in #20127

Commits
-------

8619c7f Fix typo in copyright comment
This was referenced Oct 27, 2016
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.

7 participants