]> BookStack Code Mirror - bookstack/commitdiff
Fixed LDAP_DUMP_* options when data contains binary
authorDan Brown <redacted>
Mon, 9 May 2022 14:57:50 +0000 (15:57 +0100)
committerDan Brown <redacted>
Mon, 9 May 2022 14:57:50 +0000 (15:57 +0100)
Dumping details that were binary, such as the jpegphoto data, would
cause the dump to fail on the encoding to JSON.
This change forces content to be UTF8 before dumping.
Updated existing test to cover.

Closes #3396

app/Exceptions/JsonDebugException.php
tests/Auth/LdapTest.php

index e8d61305e1232eb748b007d8c506e85ae39a0385..8acc19778e5dad7a0106edf7f9c4fe28659be52b 100644 (file)
@@ -19,10 +19,13 @@ class JsonDebugException extends Exception
     }
 
     /**
-     * Covert this exception into a response.
+     * Convert this exception into a response.
+     * We add a manual data conversion to UTF8 to ensure any binary data is presentable as a JSON string.
      */
     public function render(): JsonResponse
     {
-        return response()->json($this->data);
+        $cleaned = mb_convert_encoding($this->data, 'UTF-8');
+
+        return response()->json($cleaned);
     }
 }
index 03ef926cb07de08cd503b5cb6a0be7e4b8c94677..078940b632e45b25a30e101bc3aa10957e9a842d 100644 (file)
@@ -615,7 +615,7 @@ class LdapTest extends TestCase
 
     public function test_dump_user_details_option_works()
     {
-        config()->set(['services.ldap.dump_user_details' => true]);
+        config()->set(['services.ldap.dump_user_details' => true, 'services.ldap.thumbnail_attribute' => 'jpegphoto']);
 
         $this->commonLdapMocks(1, 1, 1, 1, 1);
         $this->mockLdap->shouldReceive('searchAndGetEntries')->times(1)
@@ -623,6 +623,8 @@ class LdapTest extends TestCase
             ->andReturn(['count' => 1, 0 => [
                 'uid' => [$this->mockUser->name],
                 'cn'  => [$this->mockUser->name],
+                // Test dumping binary data for avatar responses
+                'jpegphoto' => base64_decode('/9j/4AAQSkZJRg=='),
                 'dn'  => ['dc=test' . config('services.ldap.base_dn')],
             ]]);
 
Morty Proxy This is a proxified and sanitized view of the page, visit original site.