【问题标题】:Laravel what does the session table column "payload" contain, and how can I access this data?Laravel 会话表列“有效负载”包含什么,我如何访问这些数据?
【发布时间】:2016-04-28 04:13:37
【问题描述】:

我从本地会话表中获取了唯一的值,我是唯一的登录用户。

$data = DB::table('sessions')->get();

如果我返回 base64_decoded 有效载荷:

    return  base64_decode($data[0]->payload);

我得到了看起来像加密的 json。

a:5:{s:6:"_token";s:40:"IlIvr7p3qxeMRg0NxSaITHvIZ1c2HGCh5QSj8wIG";s:9:"_previous";a:1:{s:3:"url";s:28:"http://mytestsite.dev/index.php";}s:5:"flash";a:2:{s:3:"old";a:0:{}s:3:"new";a:0:{}}s:8:"class_id";s:2:"14";s:9:"_sf2_meta";a:3:{s:1:"u";i:1453341204;s:1:"c";i:1453331047;s:1:"l";s:1:"0";}}

有没有一种安全的方法来解密这个 JSON 以使用 Laravel 方法检索用户 ID?

进一步调查可能是会话表不包含用户信息,它只是用于与浏览器cookie匹配?

如果是这种情况,我的最终问题是如何合理地确定哪些用户当前已登录,而无需在每次页面加载时不断在用户记录上创建更新/插入,如下所示:Can someone explain session table laravel

_________________________更新

好吧,通过我进一步的研究,我发现浏览器中的 cookie 是会话记录的加密 id。

        return Crypt::decrypt($cookie);

这留下了最后一个问题,有效载荷列包含什么?

【问题讨论】:

  • That's not JSON。好像是UBJSON
  • “我得到了看起来像加密的 json。”
  • 您尝试在您提供的 UBJSON 数据中的任何位置接收的用户 ID 是?
  • 我相信如此,以及其他数据。似乎它需要对身份验证过程进行逆向工程。我找到了这个,但我认为它已经过时了。 labs.mwrinfosecurity.com/blog/2014/04/11/…
  • 为什么不在logged_in_at的用户表中添加一列,每次用户登录时更新?

标签: php laravel session


【解决方案1】:

在您拥有有效负载后使用它,它将向您显示 json 对象。

print_r(unserialize(base64_decode($datas->payload))); 
dd(unserialize(base64_decode($datas->payload)));

【讨论】:

    【解决方案2】:

    好吧,看来 Laravel 5.2 已经修复了这个问题。

    Schema::create('sessions', function ($table) {
        $table->string('id')->unique();
        $table->integer('user_id')->nullable();
        $table->string('ip_address', 45)->nullable();
        $table->text('user_agent')->nullable();
        $table->text('payload');
        $table->integer('last_activity');
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-04
      • 2019-07-16
      • 2014-08-25
      • 1970-01-01
      • 1970-01-01
      • 2012-02-24
      • 2013-11-29
      • 2016-02-03
      相关资源
      最近更新 更多