Disable integrity hashes by default, allow enabling with environment

Cloudflare auto-minifies our minified code even more (wat), which leads to issues with the resource hash, and then nothing loads. This is less likely to lead to support requests now.
This commit is contained in:
Dane Everitt 2020-09-01 19:37:05 -07:00
parent de9ec1eba6
commit 6ac12fc156
No known key found for this signature in database
GPG key ID: EEA66103B3D71F53
2 changed files with 45 additions and 33 deletions

View file

@ -82,12 +82,24 @@ class AssetHashService
*/
public function css(string $resource): string
{
return '<link href="' . $this->url($resource) . '"
rel="stylesheet preload"
as="style"
crossorigin="anonymous"
integrity="' . $this->integrity($resource) . '"
referrerpolicy="no-referrer">';
$attributes = [
'href' => $this->url($resource),
'rel' => 'stylesheet preload',
'as' => 'style',
'crossorigin' => 'anonymous',
'referrerpolicy' => 'no-referrer',
];
if (config('pterodactyl.assets.use_hash')) {
$attributes['integrity'] = $this->integrity($resource);
}
$output = '<link';
foreach ($attributes as $key => $value) {
$output .= " $key=\"$value\"";
}
return $output . '>';
}
/**
@ -100,9 +112,21 @@ class AssetHashService
*/
public function js(string $resource): string
{
return '<script src="' . $this->url($resource) . '"
integrity="' . $this->integrity($resource) . '"
crossorigin="anonymous"></script>';
$attributes = [
'src' => $this->url($resource),
'crossorigin' => 'anonymous',
];
if (config('pterodactyl.assets.use_hash')) {
$attributes['integrity'] = $this->integrity($resource);
}
$output = '<script';
foreach ($attributes as $key => $value) {
$output .= " $key=\"$value\"";
}
return $output . '></script>';
}
/**

View file

@ -102,29 +102,6 @@ return [
'high' => env('QUEUE_HIGH', 'high'),
],
/*
|--------------------------------------------------------------------------
| Console Configuration
|--------------------------------------------------------------------------
|
| Configure the speed at which data is rendered to the console.
*/
'console' => [
'count' => env('CONSOLE_PUSH_COUNT', 10),
'frequency' => env('CONSOLE_PUSH_FREQ', 200),
],
/*
|--------------------------------------------------------------------------
| Daemon Connection Details
|--------------------------------------------------------------------------
|
| Configuration for support of the new Golang based daemon.
*/
'daemon' => [
'use_new_daemon' => (bool) env('APP_USE_NEW_DAEMON', false),
],
/*
|--------------------------------------------------------------------------
| Task Timers
@ -212,4 +189,15 @@ return [
'environment_variables' => [
'P_SERVER_ALLOCATION_LIMIT' => 'allocation_limit',
],
/*
|--------------------------------------------------------------------------
| Asset Verification
|--------------------------------------------------------------------------
|
| This section controls the output format for JS & CSS assets.
*/
'assets' => [
'use_hash' => env('PTERODACTYL_USE_ASSET_HASH', false),
],
];