Skip to content

Commit 5302cab

Browse files
authored
refactor: hide server and env variable non local environment
1 parent a52330a commit 5302cab

File tree

1 file changed

+17
-4
lines changed

1 file changed

+17
-4
lines changed

src/Exception/Handler/PrettyPageHandler.php

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ class PrettyPageHandler extends Handler
8888
'_FILES' => [],
8989
'_COOKIE' => [],
9090
'_SESSION' => [],
91-
'_SERVER' => [],
91+
'' => [],
9292
'_ENV' => [],
9393
];
9494

@@ -150,7 +150,7 @@ public function __construct()
150150
$this->searchPaths[] = __DIR__ . "/../Resources";
151151

152152
// blacklist php provided auth based values
153-
$this->blacklist('_SERVER', 'PHP_AUTH_PW');
153+
$this->blacklist('', 'PHP_AUTH_PW');
154154

155155
$this->templateHelper = new TemplateHelper();
156156

@@ -266,8 +266,8 @@ public function handle()
266266
"Files" => isset($_FILES) ? $this->masked($_FILES, '_FILES') : [],
267267
"Cookies" => $this->masked($_COOKIE, '_COOKIE'),
268268
"Session" => isset($_SESSION) ? $this->masked($_SESSION, '_SESSION') : [],
269-
"Server/Request Data" => $this->masked($_SERVER, '_SERVER'),
270-
"Environment Variables" => $this->masked($_ENV, '_ENV'),
269+
"Server/Request Data" => $this->isLocal() ? $this->masked($_SERVER, '_SERVER') : [],
270+
"Environment Variables" => $this->isLocal() ? $this->masked($_ENV, '_ENV') : [],
271271
],
272272
];
273273

@@ -439,6 +439,19 @@ public function handleUnconditionally($value = null)
439439
return $this;
440440
}
441441

442+
/**
443+
* is Local Environment
444+
* Check if the application is running in a local environment.
445+
*
446+
* @return bool True if running locally, otherwise false.
447+
*/
448+
public function isLocal(): bool
449+
{
450+
return ($_SERVER['APP_ENV'] ?? '') === 'local'
451+
|| in_array($_SERVER['REMOTE_ADDR'] ?? '', ['127.0.0.1', '::1'], true);
452+
}
453+
454+
442455
/**
443456
* Adds an editor resolver.
444457
*

0 commit comments

Comments
 (0)