ajax post laravel 安全吗?
ajax post security in laravel?
我正在 laravel 5.1 中开发应用程序,我需要使用敏感的用户数据,我想知道使用 ajax posts 而不是标准 [=19] 时的安全性=].是否建议使用 ajax,是否有执行某种受保护 ajax post 的方法?谢谢 :D
在 laravel 5.1 中,您可以使用 HTTP Middleware 来创建类似于旧版本过滤器的内容。
1:定义中间件
namespace App\Http\Middleware;
use Closure;
class BeforeMiddleware
{
public function handle($request, Closure $next)
{
// Check all your ajax stuff
return $next($request);
}
}
在定义中,您可以检查请求是 Ajax 还是其他(查看 Class Reference)并定义,例如,用户是否有权访问该特定路由.
2:给路由分配中间件
// Within App\Http\Kernel Class...
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'myMiddleware' => \Path\To\The\MiddleWare::class,
];
3: 使用路由选项数组中的中间件key
Route::post('your/route', ['middleware' => 'myMiddleware', function () {
//
}]);
我正在 laravel 5.1 中开发应用程序,我需要使用敏感的用户数据,我想知道使用 ajax posts 而不是标准 [=19] 时的安全性=].是否建议使用 ajax,是否有执行某种受保护 ajax post 的方法?谢谢 :D
在 laravel 5.1 中,您可以使用 HTTP Middleware 来创建类似于旧版本过滤器的内容。
1:定义中间件
namespace App\Http\Middleware;
use Closure;
class BeforeMiddleware
{
public function handle($request, Closure $next)
{
// Check all your ajax stuff
return $next($request);
}
}
在定义中,您可以检查请求是 Ajax 还是其他(查看 Class Reference)并定义,例如,用户是否有权访问该特定路由.
2:给路由分配中间件
// Within App\Http\Kernel Class...
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'myMiddleware' => \Path\To\The\MiddleWare::class,
];
3: 使用路由选项数组中的中间件key
Route::post('your/route', ['middleware' => 'myMiddleware', function () {
//
}]);