File tree Expand file tree Collapse file tree 2 files changed +56
-7
lines changed
Expand file tree Collapse file tree 2 files changed +56
-7
lines changed Original file line number Diff line number Diff line change @@ -27,12 +27,23 @@ public function collect(): void
2727 return ;
2828 }
2929
30- Context::addHidden ('session ' , [
31- 'data ' => $ this ->redactPayload (Session::all ()),
32- 'flash ' => [
33- 'old ' => Session::get ('_flash.old ' , []),
34- 'new ' => Session::get ('_flash.new ' , []),
35- ],
36- ]);
30+ $ data = collect (Session::all ())
31+ ->except (['_token ' , '_flash ' ])
32+ ->toArray ();
33+
34+ $ session = [
35+ 'data ' => $ this ->redactPayload ($ data ),
36+ ];
37+
38+ $ flash = [
39+ 'old ' => Session::get ('_flash.old ' , []),
40+ 'new ' => Session::get ('_flash.new ' , []),
41+ ];
42+
43+ if (! empty ($ flash ['old ' ]) || ! empty ($ flash ['new ' ])) {
44+ $ session ['flash ' ] = $ flash ;
45+ }
46+
47+ Context::addHidden ('session ' , $ session );
3748 }
3849}
Original file line number Diff line number Diff line change 3232
3333 expect (Context::hasHidden ('session ' ))->toBeFalse ();
3434});
35+
36+ it ('strips empty flash data from session ' , function () {
37+ Session::start ();
38+ Session::put ('key ' , 'value ' );
39+
40+ $ this ->collector ->collect ();
41+
42+ $ session = Context::getHidden ('session ' );
43+
44+ expect ($ session )->not ->toHaveKey ('flash ' );
45+ expect ($ session ['data ' ])->not ->toHaveKey ('_flash ' );
46+ });
47+
48+ it ('preserves non-empty flash data ' , function () {
49+ Session::start ();
50+ Session::put ('key ' , 'value ' );
51+ Session::flash ('message ' , 'Hello World ' );
52+
53+ $ this ->collector ->collect ();
54+
55+ $ session = Context::getHidden ('session ' );
56+
57+ expect ($ session )->toHaveKey ('flash ' );
58+ expect ($ session ['flash ' ]['new ' ])->toContain ('message ' );
59+ });
60+
61+ it ('strips _token from session data ' , function () {
62+ Session::start ();
63+ Session::put ('key ' , 'value ' );
64+ Session::put ('_token ' , 'csrf-token-value ' );
65+
66+ $ this ->collector ->collect ();
67+
68+ $ session = Context::getHidden ('session ' );
69+
70+ expect ($ session ['data ' ])->not ->toHaveKey ('_token ' );
71+ expect ($ session ['data ' ]['key ' ])->toBe ('value ' );
72+ });
You can’t perform that action at this time.
0 commit comments