Skip to content

Instantly share code, notes, and snippets.

@mateusgf
Created October 22, 2015 17:42
Show Gist options
  • Save mateusgf/9a0e3adb2d4f48f23936 to your computer and use it in GitHub Desktop.
Save mateusgf/9a0e3adb2d4f48f23936 to your computer and use it in GitHub Desktop.
Laravel url validation Security vulnerability
<?php
/**
* Imagine if this came from the request or a database entry editable by the user.
* The Laravel URL validator relies on PHP's filter_var() method which considers
* file:// and php:// valid URLs. The vast majority of Laravel users probably
* expect this validator to only validate http:// & https://
* @link http://www.php.net/manual/en/wrappers.php
*/
Route::get('/', function () {
$url = 'file:///etc/hosts';
$validator = \Validator::make
(
['url' => $url],
['url' => 'url']
);
if ($validator->passes()) {
return file_get_contents($url);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment