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

Appearance settings

[Validator] check for empty host when calling checkdnsrr() #22109

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 16 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add empty check on host in other methods + add unit tests
Add empty on host in other methods where checkdnsrr is called and add unit tests to prevent future regressions
  • Loading branch information
apetitpa authored and apetitpa committed Mar 27, 2017
commit b7f6db6a6f99f3b220b724e2a10b3788d0cd204e
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public function validate($value, Constraint $constraint)
*/
private function checkMX($host)
{
if (null === $host || '' === $host) {
if ('' === $host) {
return false;
}

Copy link
Contributor

Choose a reason for hiding this comment

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

preferred empty host condition in return statement

Expand All @@ -134,6 +134,10 @@ private function checkMX($host)
*/
private function checkHost($host)
{
if ('' === $host) {
return false;
}

return $this->checkMX($host) || (checkdnsrr($host, 'A') || checkdnsrr($host, 'AAAA'));
Copy link
Contributor

Choose a reason for hiding this comment

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

preferred empty host condition in return statement

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public function validate($value, Constraint $constraint)
if ($constraint->checkDNS) {
$host = parse_url($value, PHP_URL_HOST);

if (!checkdnsrr($host, 'ANY')) {
if ('' === $host || !checkdnsrr($host, 'ANY')) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Perhaps switch to !is_string($host) due possible false or null return values.

Copy link
Author

Choose a reason for hiding this comment

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

I think this is a good idea. I'll do it thank you.

$this->context->buildViolation($constraint->dnsMessage)
->setParameter('{{ value }}', $this->formatValue($host))
->setCode(Url::INVALID_URL_ERROR)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -229,4 +229,10 @@ public function testHostnameIsProperlyParsed()

$this->assertNoViolation();
}

public function testEmptyHostReturnsFalse()
{
$this->assertFalse($this->validator->checkMX(''));
$this->assertFalse($this->validator->checkHost(''));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,7 @@ public function getInvalidUrls()
array('http://example.com/exploit.html?<script>alert(1);</script>'),
array('http://example.com/exploit.html?hel lo'),
array('http://example.com/exploit.html?not_a%hex'),
array('http:/.com'),
);
}

Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.