【问题标题】:Whitelist Domain Authentication Laravel白名单域认证 Laravel
【发布时间】:2015-12-10 14:30:42
【问题描述】:

我正在寻找只允许某些域访问我的 laravel 应用程序的最佳方法。我目前正在使用 Laravel 5.1,如果引用域不在白名单域中,我正在使用中间件进行重定向。

class Whitelist {

    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */

    public function handle($request, Closure $next)
    {
        //requesting URL
        $referer = Request::server('HTTP_REFERER');

        //parse url to match base in table
        $host = parse_url($referer, PHP_URL_HOST);
        $host = str_replace("www.", "", $host);

        //Cached query to whitelisted domains - 1400 = 24 hours
        $whiteList = Cache::remember('whitelist_domains', 1400, function(){
            $query = WhiteListDomains::lists('domain')->all();
            return $query;
        });

        //Check that referring domain is whitelisted or itself?
        if(in_array($host, $whiteList)){
            return $next($request);
        }else{
            header('HTTP/1.0 403 Forbidden');
            die('You are not allowed to access this file.');
        }
    }
}

有没有更好的方法来做这件事,还是我走在正确的轨道上?

任何帮助将不胜感激。

谢谢。

【问题讨论】:

  • 当你说“我正在寻找只允许某些域访问我的 laravel 应用程序的最佳方式”时。你到底是什么意思?用户必须在这些域之一上,还是必须由这些域之一推荐?
  • 我认为这是一个干净又好的解决方案

标签: laravel authentication dns middleware whitelist


【解决方案1】:

你走在正确的轨道上,实施似乎很好。

但是,不要相信 HTTP_REFERER 作为身份验证/识别的手段,因为它很容易被修改。

【讨论】:

    猜你喜欢
    • 2016-07-23
    • 2019-11-05
    • 1970-01-01
    • 1970-01-01
    • 2017-12-14
    • 2015-08-23
    • 2017-01-29
    • 2021-11-04
    • 2018-12-24
    相关资源
    最近更新 更多