A free open source IT asset/license management system
Signature Acceptance: Fixed #20008 - make the max png size a variable
snipee2fce269693a
diff --git a/.env.example b/.env.exampleindex c70dde8798..fd5970d28e 100644--- a/.env.example+++ b/.env.example@@ -9,13 +9,6 @@ APP_TIMEZONE='UTC'APP_LOCALE='en-US'MAX_RESULTS=500-# --------------------------------------------# TRUSTED PROXY SETTINGS-# --------------------------------------------# (See config/trustedproxy.php for details)-APP_TRUSTED_PROXIES=""-APP_TRUSTED_HEADERS=""-# --------------------------------------------# REQUIRED: UPLOADED FILE STORAGE SETTINGS# --------------------------------------------@@ -25,7 +18,6 @@ PUBLIC_FILESYSTEM_DISK=local_public#PRIVATE_FILESYSTEM_DISK=s3_private#PUBLIC_FILESYSTEM_DISK=s3_public-# --------------------------------------------# REQUIRED: DATABASE SETTINGS# --------------------------------------------@@ -47,7 +39,6 @@ DB_CHARSET=utf8mb4DB_COLLATION=utf8mb4_unicode_ciDB_SANITIZE_BY_DEFAULT=false-# --------------------------------------------# OPTIONAL: SSL DATABASE SETTINGS# --------------------------------------------@@ -116,7 +107,6 @@ MICROSOFT_GRAPH_SAVE_TO_SENT_ITEMS=false# --------------------------------------------IMAGE_LIB=gd-# --------------------------------------------# OPTIONAL: BACKUP SETTINGS# Backup filesystem configuration@@ -163,7 +153,7 @@ BS_TABLE_DEEPLINK=true# --------------------------------------------# OPTIONAL: SECURITY HEADER SETTINGS# ---------------------------------------------APP_TRUSTED_PROXIES=192.168.1.1,10.0.0.1+ALLOW_IFRAMING=falseREFERRER_POLICY=same-originENABLE_CSP=true@@ -171,6 +161,13 @@ ADDITIONAL_CSP_URLS=nullCORS_ALLOWED_ORIGINS=nullENABLE_HSTS=false+# -------------------------------------------+# TRUSTED PROXY SETTINGS+# -------------------------------------------+# (See config/trustedproxy.php for details)+APP_TRUSTED_PROXIES=192.168.1.1,10.0.0.1+APP_TRUSTED_HEADERS=""+# --------------------------------------------# OPTIONAL: CACHE SETTINGS# --------------------------------------------@@ -273,6 +270,12 @@ CSV_ESCAPE_FORMULAS=trueLIVEWIRE_URL_PREFIX=nullMAX_UNPAGINATED=5000+# ACCEPTANCE_SIGNATURE_MAX_DIMENSION bounds the signature PNG width AND height+# in pixels on the server-side guard. Default 6000. Raise if legitimate+# high-DPI browsers hit the "no signature detected" error. Higher ceilings+# use proportionally more memory per acceptance.+ACCEPTANCE_SIGNATURE_MAX_DIMENSION=6000+# --------------------------------------------# OPTIONAL: SAML SETTINGS# --------------------------------------------@@ -299,7 +302,6 @@ SCIM_STANDARDS_COMPLIANCE=false# --------------------------------------------WEBHOOK_ALLOW_INTERNAL_TARGETS=false-# --------------------------------------------# OPTIONAL: SYNC ADAPTER SETTINGS# --------------------------------------------diff --git a/app/Http/Controllers/Account/AcceptanceController.php b/app/Http/Controllers/Account/AcceptanceController.phpindex cf11553ad9..d2b5fc58ee 100644--- a/app/Http/Controllers/Account/AcceptanceController.php+++ b/app/Http/Controllers/Account/AcceptanceController.php@@ -177,15 +177,24 @@ class AcceptanceController extends Controller// width/height is rejected without imagecreatefromstring// decoding the raster or the flatten path allocating a second// same-size buffer. IMAGETYPE_PNG is enforced because the- // signature-pad JavaScript creates only PNG files.+ // signature-pad JavaScript creates only PNG files.+ //+ // Dimension ceiling is operator-tunable via the+ // ACCEPTANCE_SIGNATURE_MAX_DIMENSION env var.+ $maxSignatureDimension = (int) config('app.acceptance_signature_max_dimension', 6000);$imgInfo = @getimagesizefromstring($decoded_image);- if ($imgInfo === false- || $imgInfo[2] !== IMAGETYPE_PNG- || $imgInfo[0] > 6000- || $imgInfo[1] > 6000- ) {+ if ($imgInfo === false || $imgInfo[2] !== IMAGETYPE_PNG) {return redirect()->back()->with('error', trans('general.shitty_browser'));}+ if ($imgInfo[0] > $maxSignatureDimension || $imgInfo[1] > $maxSignatureDimension) {+ // Specific error for the operator-tunable dimension+ // cap so a user on a high-DPI browser doesn't get+ // the misleading "use a more modern browser" message+ // when their browser is fine and their signature is+ // just physically too wide. The message tells the+ // user what to try and the admin what to tune.+ return redirect()->back()->with('error', trans('general.signature_too_large', ['max' => $maxSignatureDimension]));+ }// Flatten the signature's transparent background onto// white and canonically re-encode. Fail-closed if thatdiff --git a/config/app.php b/config/app.phpindex f555f76ba0..f4ab3e0d66 100755--- a/config/app.php+++ b/config/app.php@@ -632,6 +632,21 @@ return ['max_unpaginated_records' => env('MAX_UNPAGINATED', '10000'),+ /*+ |--------------------------------------------------------------------------+ | Acceptance Signature Max Dimension+ |--------------------------------------------------------------------------+ | Upper bound (in pixels) on the width AND height of a signature PNG+ | uploaded on asset acceptance. The 6000 default covers typical retina+ | and 5K displays with headroom. Operators whose users produce+ | signatures above this ceiling (8K / scaled high-DPI panels) can+ | raise it via ACCEPTANCE_SIGNATURE_MAX_DIMENSION in .env. Each pixel+ | adds proportional memory per acceptance because the flatten path+ | allocates one same-size buffer during server-side re-encoding.+ */++ 'acceptance_signature_max_dimension' => (int) env('ACCEPTANCE_SIGNATURE_MAX_DIMENSION', 6000),+/*|--------------------------------------------------------------------------| Report Execution Time Limitdiff --git a/resources/lang/en-US/general.php b/resources/lang/en-US/general.phpindex 00de3dd059..f1a87b0b7c 100644--- a/resources/lang/en-US/general.php+++ b/resources/lang/en-US/general.php@@ -599,6 +599,7 @@ return ['backup_delete_not_allowed' => 'Deleting backups has been disabled in the .env file. Contact support or your systems administrator.','additional_files' => 'Additional Files','shitty_browser' => 'No signature detected. If you are using an older browser, please use a more modern browser to complete your asset acceptance.',+ 'signature_too_large' => 'Your signature image is larger than this installation allows (:max px per side). Try resizing your browser window to a smaller size and signing again. If this keeps happening, ask your administrator to raise the ACCEPTANCE_SIGNATURE_MAX_DIMENSION setting.','bulk_soft_delete' => 'Also soft-delete these users. Their item history will remain intact unless/until you purge deleted records in the Admin Settings.','bulk_checkin_delete_success' => 'Your selected users have been deleted and their items have been checked in.','bulk_checkin_success' => 'The items for the selected users have been checked in.',diff --git a/tests/Feature/CheckoutAcceptances/AcceptanceSignatureImageValidationTest.php b/tests/Feature/CheckoutAcceptances/AcceptanceSignatureImageValidationTest.phpindex b2761a8a7b..ed3b6569c8 100644--- a/tests/Feature/CheckoutAcceptances/AcceptanceSignatureImageValidationTest.php+++ b/tests/Feature/CheckoutAcceptances/AcceptanceSignatureImageValidationTest.php@@ -34,6 +34,7 @@ class AcceptanceSignatureImageValidationTest extends TestCaseob_start();imagepng($canvas);$bytes = (string) ob_get_clean();+return $bytes;}@@ -97,10 +98,59 @@ class AcceptanceSignatureImageValidationTest extends TestCase'signature_output' => 'data:image/png;base64,'.base64_encode($bombHeader),];- $this->actingAs($target)+ $response = $this->actingAs($target)+ ->post(route('account.store-acceptance', $acceptance), $payload)+ ->assertSessionHas('error');++ // Assert the dimension-cap-specific message (not the generic+ // "no signature detected" shitty_browser string) so the user+ // sees why their legitimate browser is being rejected and what+ // to do about it.+ $this->assertSame(+ trans('general.signature_too_large', ['max' => 6000]),+ $response->getSession()->get('error'),+ );++ $acceptance->refresh();+ $this->assertNull($acceptance->accepted_at);+ $this->assertEmpty(Storage::disk()->files('private_uploads/signatures'));+ }++ public function test_signature_dimension_cap_is_operator_tunable_via_config(): void+ {+ // Operators on 8K / scaled high-DPI monitors have been reported+ // to produce legitimate signatures above the 6000 default.+ // Lower the ceiling to prove the config knob is actually read:+ // a tiny real PNG that passes the default 6000 ceiling (and+ // succeeds end-to-end today) now trips the dimension cap when+ // the operator-tunable ceiling is set below its declared size.+ // Covers the inverse direction of the oversized-dimensions test+ // which already proves the default rejects 10000x10000.+ Storage::fake();+ $this->enableRequiredSignatures();+ config(['app.acceptance_signature_max_dimension' => 1]);++ $target = User::factory()->create();+ $acceptance = $this->pendingAcceptance($target);++ // A 2x2 real PNG. Under the default 6000 ceiling this would+ // pass the dimension check and reach the flatten re-encode.+ // With the override at 1px it must be rejected at the+ // dimension cap before any pixel buffer is allocated.+ $payload = [+ 'asset_acceptance' => 'accepted',+ 'signature_output' => 'data:image/png;base64,'.base64_encode($this->tinyPng()),+ ];++ $response = $this->actingAs($target)->post(route('account.store-acceptance', $acceptance), $payload)->assertSessionHas('error');+ $this->assertSame(+ trans('general.signature_too_large', ['max' => 1]),+ $response->getSession()->get('error'),+ );+$acceptance->refresh();$this->assertNull($acceptance->accepted_at);$this->assertEmpty(Storage::disk()->files('private_uploads/signatures'));