From e4db1a476ddcb250bb8c2c78fdf2716ef3f85b04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=A9my=20Munsch?= Date: Sat, 14 Nov 2026 16:05:52 +0100 Subject: [PATCH] refactor(infra): configure PVC-less volumes, /tmp purifier cache and S3 CSP headers --- app/Http/Middleware/SecureHeaders.php | 23 +++++++++++++++++++---- config/purifier.php | 2 +- manifest.yaml | 25 +++++++++++++++++++++++++ 3 files changed, 45 insertions(+), 5 deletions(-) diff --git a/app/Http/Middleware/SecureHeaders.php b/app/Http/Middleware/SecureHeaders.php index 59227c81..d3f92f9c 100644 --- a/app/Http/Middleware/SecureHeaders.php +++ b/app/Http/Middleware/SecureHeaders.php @@ -4,10 +4,10 @@ declare(strict_types=1); namespace App\Http\Middleware; -use Closure; use Illuminate\Http\Request; use Illuminate\Support\Facades\Config; use Illuminate\Support\Facades\Vite; +use Illuminate\Support\Str; use Symfony\Component\HttpFoundation\Response; class SecureHeaders @@ -27,9 +27,9 @@ class SecureHeaders /** * Handle an incoming request. * - * @param \Closure(\Illuminate\Http\Request):(\Illuminate\Http\Response) $next + * @param \Closure(\Illuminate\Http\Request):(\Symfony\Component\HttpFoundation\Response) $next */ - public function handle(Request $request, Closure $next): Response + public function handle(Request $request, \Closure $next): Response { $appUrl = Config::string('app.url'); $appDebug = Config::boolean('app.debug'); @@ -58,11 +58,19 @@ class SecureHeaders $this->removeUnwantedHeaders($this->unwantedHeaderList); $response = $next($request); - $response->headers->set('Referrer-Policy', 'no-referrer-when-downgrade'); + $response->headers->set('Referrer-Policy', 'strict-origin-when-cross-origin'); $response->headers->set('X-Content-Type-Options', 'nosniff'); $response->headers->set('X-XSS-Protection', '1; mode=block'); $response->headers->set('X-Frame-Options', 'SAMEORIGIN'); $response->headers->set('Strict-Transport-Security', 'max-age=31536000; includeSubDomains; preload'); + $response->headers->set('X-Permitted-Cross-Domain-Policies', 'none'); + $response->headers->set('Cross-Origin-Opener-Policy', 'same-origin-allow-popups'); + $response->headers->set('Cross-Origin-Resource-Policy', 'same-origin'); + $response->headers->set('Permissions-Policy', 'fullscreen=(self), geolocation=(self), camera=(), microphone=(), payment=()'); + $response->headers->set('Feature-Policy', "fullscreen 'self'; geolocation 'self';"); + + $s3PublicEndpoint = Str::of(Config::string('filesystems.disks.s3.url')) + ->chopEnd('/')->append('/')->value(); // * Ignore CSP on some conditions. if ( @@ -79,7 +87,10 @@ class SecureHeaders $cspPolicies = [ "default-src 'none';", "base-uri 'self';", + "form-action 'self';", + "frame-ancestors 'self';", "manifest-src 'self';", + "media-src 'self' blob: " . implode(' ', array_filter([$appUrl, $s3PublicEndpoint])) . ';', // * CKEDITOR Specific https://ckeditor.com/docs/ckeditor5/latest/installation/advanced/csp.html "connect-src 'self' " . implode(' ', [ 'https://yl.s-web.fr/', @@ -88,11 +99,15 @@ class SecureHeaders // * VITE DEV $viteDevSocket, $viteDevOrigin, + $s3PublicEndpoint, ]) . ';', "img-src 'self' data: blob: " . implode(' ', [ $viteDevOrigin, $openStreetMapTiles, + $s3PublicEndpoint, ]) . ' data:;', + "worker-src 'self' blob:;", + "object-src 'none';", 'child-src ' . implode(' ', []) . ';', "object-src 'none';", "font-src 'self' data: " . \implode(' ', [ diff --git a/config/purifier.php b/config/purifier.php index 19c70944..6f822dd0 100644 --- a/config/purifier.php +++ b/config/purifier.php @@ -23,7 +23,7 @@ declare(strict_types=1); return [ 'encoding' => 'UTF-8', 'finalize' => true, - 'cachePath' => storage_path('app/purifier'), + 'cachePath' => '/tmp/purifier', 'cacheFileMode' => 0755, 'settings' => [ 'default' => [ diff --git a/manifest.yaml b/manifest.yaml index 08864f07..d851ec04 100644 --- a/manifest.yaml +++ b/manifest.yaml @@ -106,6 +106,10 @@ spec: emptyDir: {} - name: laravel-views emptyDir: {} + - name: laravel-logs + emptyDir: {} + - name: tmp + emptyDir: {} containers: - name: ${CI_PROJECT_PATH_SLUG}-container image: $IMAGE_TAG @@ -125,6 +129,10 @@ spec: mountPath: /app/srcs/bootstrap/cache - name: laravel-views mountPath: /app/srcs/storage/framework/views + - name: laravel-logs + mountPath: /app/srcs/storage/logs + - name: tmp + mountPath: /tmp readinessProbe: httpGet: path: /up @@ -180,6 +188,15 @@ spec: envFrom: - configMapRef: name: ${CI_PROJECT_PATH_SLUG}-config-map + volumeMounts: + - name: laravel-cache + mountPath: /app/srcs/bootstrap/cache + - name: laravel-views + mountPath: /app/srcs/storage/framework/views + - name: laravel-logs + mountPath: /app/srcs/storage/logs + - name: tmp + mountPath: /tmp securityContext: # TODO : valider le POC # readOnlyRootFilesystem: true @@ -303,6 +320,10 @@ spec: emptyDir: {} - name: laravel-views emptyDir: {} + - name: laravel-logs + emptyDir: {} + - name: tmp + emptyDir: {} containers: - name: ${CI_PROJECT_PATH_SLUG}-scheduled image: $IMAGE_TAG @@ -321,6 +342,10 @@ spec: mountPath: /app/srcs/bootstrap/cache - name: laravel-views mountPath: /app/srcs/storage/framework/views + - name: laravel-logs + mountPath: /app/srcs/storage/logs + - name: tmp + mountPath: /tmp resources: requests: cpu: "${APP_CI_CPU_REQUEST}"