Skip to content

[Validator] fix URL validator to detect non supported chars according to RFC 3986 #22022

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 1 commit into from

Conversation

e-moe
Copy link
Contributor

@e-moe e-moe commented Mar 16, 2017

Q A
Branch? 3.2
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #21961
License MIT
Doc PR none

@Nek-
Copy link
Contributor

Nek- commented Mar 16, 2017

Awesome. Thank you for your contribution. Your code will definitely improve Symfony code base by fixing potential security error and many projects will benefit of that.

I made some tests. This (non-valid) URL isn't validated (which is great) http://example.com/exploit.html?hel lo, I think we should add it to the test suite.


I also tested this other URL that is considered as valid but is not: http://example.com/exploit.html?tçest this is a problem with many non-ascii chars. Do you plan to fix it? Or your fix (that actually fix some things) will remain as it? It may be kept as it as there is no security issue in that case, even browsers will interpret it as standard URL.

@e-moe
Copy link
Contributor Author

e-moe commented Mar 16, 2017

@Nek- , thanks for your review! I just extended test cases with your example (http://example.com/exploit.html?hel lo). As for non-ascii chars I'm not sure. But previously they were treated as valid: https://github.com/symfony/symfony/blob/master/src/Symfony/Component/Validator/Tests/Constraints/UrlValidatorTest.php#L104

@Nek-
Copy link
Contributor

Nek- commented Mar 16, 2017

@e-moe it's valid as DNS but not as query string (where is must be url-encoded). But well, it's fine to me, I'm just noticing it.

@e-moe
Copy link
Contributor Author

e-moe commented Mar 16, 2017

oh, I see your point. If needed it can be fixed. Let's wait for other reviews and then we will be able to make a decision

Copy link
Member

@nicolas-grekas nicolas-grekas left a comment

Choose a reason for hiding this comment

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

This should be applied to 2.7, isn't it ? We need to consider if this could introduce any unwanted BC break as side effect.

const PATTERN = '~^
(%s):// # protocol
const PATTERN = '<^
(%protocol%):// # protocol
Copy link
Member

Choose a reason for hiding this comment

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

why these two changes? better not do them imho, and continue using sprintf (requires doubling the % below)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point, fixed

@nicolas-grekas nicolas-grekas added this to the 2.7 milestone Mar 17, 2017
@e-moe
Copy link
Contributor Author

e-moe commented Mar 17, 2017

@nicolas-grekas , I just fixed code based on your comments.

should I create new PR for 2.7 branch?

@e-moe
Copy link
Contributor Author

e-moe commented Mar 17, 2017

as for BC break - new constraint is more strict comparing to old version. but new one is closer to RFC

should it be considered as a BC break?

@Nek-
Copy link
Contributor

Nek- commented Mar 18, 2017

It's not a BC break! It's a fix.

@fabpot
Copy link
Member

fabpot commented Mar 22, 2017

Thank you @e-moe.

fabpot added a commit that referenced this pull request Mar 22, 2017
…s according to RFC 3986 (e-moe)

This PR was submitted for the 3.2 branch but it was merged into the 2.7 branch instead (closes #22022).

Discussion
----------

[Validator] fix URL validator to detect non supported chars according to RFC 3986

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

Commits
-------

3599c47 [Validator] fix URL validator to detect non supported chars according to RFC 3986
@fabpot fabpot closed this Mar 22, 2017
This was referenced Apr 4, 2017
@Aliance
Copy link
Contributor

Aliance commented Apr 18, 2017

I have a template link field with Url validator. By template I mean http://www.domain.com/script.php?value=${PLACEHOLDER}.
After this pr Url validator triggers an error. With the real link it is okay, but that do you recommend for me? The only way is to write my own UrlTemplate validator?

@Nek-
Copy link
Contributor

Nek- commented Apr 18, 2017

@Aliance yes.

I'm sorry to read it breaks your code but this is the attempted behavior of the URL Validator. (here was a potential security issue that is now fixed)

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.

6 participants