Skip to content

Commit 2535d62

Browse files
authored
Merge pull request #8567 from ProcessMaker/bugfix/FOUR-26915
Server Version Disclosure On Error Page
2 parents d3cb6b9 + c09606b commit 2535d62

File tree

3 files changed

+93
-0
lines changed

3 files changed

+93
-0
lines changed

ProcessMaker/Http/Kernel.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ class Kernel extends HttpKernel
2727
ServerTimingMiddleware::class,
2828
Middleware\FileSizeCheck::class,
2929
Middleware\AddTenantHeaders::class,
30+
Middleware\HideServerHeaders::class,
3031
];
3132

3233
/**
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<?php
2+
3+
namespace ProcessMaker\Http\Middleware;
4+
5+
use Closure;
6+
use Illuminate\Http\Request;
7+
use Symfony\Component\HttpFoundation\Response;
8+
9+
class HideServerHeaders
10+
{
11+
/**
12+
* Headers that reveal server information and should be removed
13+
*
14+
* @var array
15+
*/
16+
private $headersToRemove = [
17+
// Server identification
18+
'Server',
19+
'X-Powered-By',
20+
'X-AspNet-Version',
21+
'X-AspNetMvc-Version',
22+
23+
// Web technologies and frameworks
24+
'X-Generator',
25+
'X-Drupal-Cache',
26+
'X-Varnish',
27+
'X-Cache',
28+
'X-Cache-Hits',
29+
'X-Framework',
30+
31+
// Load balancer and proxy information
32+
'X-Forwarded-For',
33+
'X-Real-IP',
34+
'X-Forwarded-Proto',
35+
'X-Forwarded-Host',
36+
'X-Forwarded-Server',
37+
'X-Forwarded-Port',
38+
39+
// Additional server information
40+
'X-Served-By',
41+
'X-Cache-Status',
42+
'X-Served-From',
43+
'X-Content-Source',
44+
45+
// PHP specific headers
46+
'X-PHP-Version',
47+
'X-PHP-Originating-Script',
48+
49+
// Development and debugging headers
50+
'X-Debug-Token',
51+
'X-Debug-Token-Link',
52+
'X-Symfony-Cache',
53+
];
54+
55+
/**
56+
* Handle an incoming request.
57+
*
58+
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
59+
*/
60+
public function handle(Request $request, Closure $next): Response
61+
{
62+
$response = $next($request);
63+
64+
// Only remove headers in production or when explicitly configured
65+
if ($this->shouldHideHeaders()) {
66+
// Remove all server-revealing headers
67+
foreach ($this->headersToRemove as $header) {
68+
$response->headers->remove($header);
69+
}
70+
71+
// Set a generic server header to avoid revealing the absence
72+
$response->headers->set('Server', 'ProcessMaker Server');
73+
}
74+
75+
return $response;
76+
}
77+
78+
/**
79+
* Determine if headers should be hidden based on environment
80+
*
81+
* @return bool
82+
*/
83+
private function shouldHideHeaders(): bool
84+
{
85+
// Hide headers in production or when explicitly configured
86+
return app()->environment('production') ||
87+
config('app.hide_server_headers', false);
88+
}
89+
}

config/app.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,9 @@
4141
// The timeout length for API calls, in milliseconds (0 for no timeout)
4242
'api_timeout' => env('API_TIMEOUT', 5000),
4343

44+
// Hide server headers for security (prevents information disclosure)
45+
'hide_server_headers' => env('HIDE_SERVER_HEADERS', true),
46+
4447
// Disables PHP execution in the storage directory
4548
// TODO Is this config value still used anywhere? :)
4649
'disable_php_upload_execution' => env('DISABLE_PHP_UPLOAD_EXECUTION', 0),

0 commit comments

Comments
 (0)