diff --git a/app/config/app.php b/app/config/app.php index abbc4d15..9ccd9b63 100644 --- a/app/config/app.php +++ b/app/config/app.php @@ -123,6 +123,7 @@ return [ 'Illuminate\Workbench\WorkbenchServiceProvider', 'Dingo\Api\Provider\ApiServiceProvider', + 'GrahamCampbell\Throttle\ThrottleServiceProvider', 'Thujohn\Rss\RssServiceProvider', 'CachetHQ\Cachet\Support\ServiceProviders\RepositoryServiceProvider', @@ -196,8 +197,9 @@ return [ 'Validator' => 'Illuminate\Support\Facades\Validator', 'View' => 'Illuminate\Support\Facades\View', - 'API' => 'Dingo\Api\Facade\API', - 'RSS' => 'Thujohn\Rss\RssFacade', + 'API' => 'Dingo\Api\Facade\API', + 'Throttle' => 'GrahamCampbell\Throttle\Facades\Throttle', + 'RSS' => 'Thujohn\Rss\RssFacade', ], diff --git a/app/config/packages/.gitkeep b/app/config/packages/.gitkeep deleted file mode 100644 index e69de29b..00000000 diff --git a/app/config/packages/graham-campbell/throttle/config.php b/app/config/packages/graham-campbell/throttle/config.php new file mode 100644 index 00000000..cc8241a8 --- /dev/null +++ b/app/config/packages/graham-campbell/throttle/config.php @@ -0,0 +1,35 @@ + null, + +]; diff --git a/app/controllers/AuthController.php b/app/controllers/AuthController.php index 900536a8..ff873a76 100644 --- a/app/controllers/AuthController.php +++ b/app/controllers/AuthController.php @@ -23,6 +23,7 @@ class AuthController extends Controller if (Auth::attempt(Input::only(['email', 'password']))) { return Redirect::intended('dashboard'); } else { + Throttle::hit(Request::instance(), 10, 10); return Redirect::back() ->withInput(Input::except('password')) ->with('error', 'Invalid email or password'); diff --git a/app/filters.php b/app/filters.php index e864343f..5092c7a6 100644 --- a/app/filters.php +++ b/app/filters.php @@ -4,6 +4,7 @@ Route::filter('is_setup', 'IsSetupFilter'); Route::filter('has_setting', 'HasSettingFilter'); Route::filter('cors', 'CORSFilter'); Route::filter('allowed_domains', 'AllowedDomainsFilter'); +Route::filter('login_throttling', 'LoginThrottlingFilter'); /* |-------------------------------------------------------------------------- diff --git a/app/filters/LoginThrottlingFilter.php b/app/filters/LoginThrottlingFilter.php new file mode 100644 index 00000000..b7839e11 --- /dev/null +++ b/app/filters/LoginThrottlingFilter.php @@ -0,0 +1,16 @@ +with('error', 'You have made too many login requests.'); + } + + return $response; + } +} diff --git a/app/routes/auth.php b/app/routes/auth.php index 8b495a2c..520a0d28 100644 --- a/app/routes/auth.php +++ b/app/routes/auth.php @@ -2,7 +2,7 @@ Route::group(['before' => 'has_setting:app_name'], function () { Route::get('/auth/login', ['before' => 'guest', 'as' => 'login', 'uses' => 'AuthController@showLogin']); - Route::post('/auth/login', ['before' => 'guest|csrf', 'as' => 'logout', 'uses' => 'AuthController@postLogin']); + Route::post('/auth/login', ['before' => 'guest|csrf|login_throttling', 'as' => 'logout', 'uses' => 'AuthController@postLogin']); }); Route::get('/auth/logout', ['before' => 'auth', 'as' => 'logout', 'uses' => 'AuthController@logoutAction']); diff --git a/composer.json b/composer.json index c3011c37..f484b87f 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ "laravel/framework": "4.2.*", "guzzlehttp/guzzle": "~5.0", "dingo/api": "0.8.*", + "graham-campbell/throttle": "~2.0", "watson/validating": "0.10.*", "thujohn/rss": "~1.0", "doctrine/dbal": "2.5.*", diff --git a/composer.lock b/composer.lock index 1f2f7007..c6227b5f 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at http://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file", "This file is @generated automatically" ], - "hash": "2b05058fab4b2fa831e500985b506c1f", + "hash": "def3f0fcb615467e21e9eccf44a39a73", "packages": [ { "name": "classpreloader/classpreloader", @@ -768,6 +768,59 @@ ], "time": "2014-10-26 09:05:09" }, + { + "name": "graham-campbell/throttle", + "version": "v2.0.1", + "source": { + "type": "git", + "url": "https://github.com/GrahamCampbell/Laravel-Throttle.git", + "reference": "0c75b729efa7dea6ec8e4182bf3f5ebe0cb9f003" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/GrahamCampbell/Laravel-Throttle/zipball/0c75b729efa7dea6ec8e4182bf3f5ebe0cb9f003", + "reference": "0c75b729efa7dea6ec8e4182bf3f5ebe0cb9f003", + "shasum": "" + }, + "require": { + "illuminate/cache": "~4.1", + "illuminate/http": "~4.1", + "illuminate/support": "~4.1", + "php": ">=5.4.7" + }, + "require-dev": { + "graham-campbell/testbench": "~1.0" + }, + "type": "library", + "autoload": { + "psr-4": { + "GrahamCampbell\\Throttle\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "Apache-2.0" + ], + "authors": [ + { + "name": "Graham Campbell", + "email": "graham@mineuk.com" + } + ], + "description": "Throttle Is A Rate Limiter For Laravel 4.1/4.2", + "keywords": [ + "Graham Campbell", + "GrahamCampbell", + "Laravel Throttle", + "Laravel-Throttle", + "framework", + "laravel", + "rate limit", + "throttle", + "throttling" + ], + "time": "2014-10-30 13:45:51" + }, { "name": "guzzlehttp/guzzle", "version": "5.1.0", @@ -3477,6 +3530,7 @@ "minimum-stability": "stable", "stability-flags": [], "prefer-stable": false, + "prefer-lowest": false, "platform": { "php": ">=5.4" },