File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -19,6 +19,10 @@ private function runningInConsole(): bool
1919 return $ _ENV ['APP_RUNNING_IN_CONSOLE ' ] === 'true ' ;
2020 }
2121
22+ if (isset ($ _ENV ['FLARE_FAKE_WEB_REQUEST ' ])) {
23+ return false ;
24+ }
25+
2226 return in_array (php_sapi_name (), ['cli ' , 'phpdb ' ]);
2327 }
2428}
Original file line number Diff line number Diff line change 1313use Facade \FlareClient \Http \Client ;
1414use Facade \FlareClient \Middleware \AddGlows ;
1515use Facade \FlareClient \Middleware \AnonymizeIp ;
16+ use Facade \FlareClient \Middleware \CensorRequestBodyFields ;
1617use Illuminate \Contracts \Container \Container ;
1718use Illuminate \Pipeline \Pipeline ;
1819use Throwable ;
@@ -231,6 +232,10 @@ public function anonymizeIp()
231232 return $ this ;
232233 }
233234
235+ public function censorRequestBodyFields (array $ fieldNames )
236+ {
237+ $ this ->registerMiddleware (new CensorRequestBodyFields ($ fieldNames ));
238+ }
234239
235240 public function createReport (Throwable $ throwable ): Report
236241 {
Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Facade \FlareClient \Middleware ;
4+
5+ use Facade \FlareClient \Report ;
6+
7+ class CensorRequestBodyFields
8+ {
9+ protected $ fieldNames = [];
10+
11+ public function __construct (array $ fieldNames )
12+ {
13+ $ this ->fieldNames = $ fieldNames ;
14+ }
15+
16+ public function handle (Report $ report , $ next )
17+ {
18+
19+ $ context = $ report ->allContext ();
20+
21+ foreach ($ this ->fieldNames as $ fieldName ) {
22+ if (isset ($ context ['request_data ' ]['body ' ][$ fieldName ])) {
23+ $ context ['request_data ' ]['body ' ][$ fieldName ] = '<CENSORED> ' ;
24+ }
25+ }
26+
27+ $ report ->userProvidedContext ($ context );
28+
29+ return $ next ($ report );
30+ }
31+ }
Original file line number Diff line number Diff line change @@ -126,6 +126,23 @@ public function it_can_anonymize_the_ip()
126126 ]);
127127 }
128128
129+ /** @test */
130+ public function it_can_censor_request_data ()
131+ {
132+ $ _ENV ['FLARE_FAKE_WEB_REQUEST ' ] = true ;
133+ $ _POST ['user ' ] = 'john@example.com ' ;
134+ $ _POST ['password ' ] = 'secret ' ;
135+
136+ $ this ->flare ->censorRequestBodyFields (['user ' , 'password ' ]);
137+
138+ $ this ->reportException ();
139+
140+ $ this ->fakeClient ->assertLastRequestContains ('context.request_data.body ' , [
141+ 'user ' => '<CENSORED> ' ,
142+ 'password ' => '<CENSORED> ' ,
143+ ]);
144+ }
145+
129146 /** @test */
130147 public function it_can_merge_user_provided_context ()
131148 {
You can’t perform that action at this time.
0 commit comments