From cf6a63c03bbb913dc51cf2070f028121944d3605 Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Thu, 2 Aug 2018 11:18:37 +0200 Subject: [PATCH 1/5] ~ make debugbar loading under csp Signed-off-by: Christoph Potas --- application/Filters/DebugToolbar.php | 4 +++- system/Debug/Toolbar/toolbarloader.js.php | 24 +++++++++++++++++++---- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/application/Filters/DebugToolbar.php b/application/Filters/DebugToolbar.php index 878a52387923..d28b45554a19 100644 --- a/application/Filters/DebugToolbar.php +++ b/application/Filters/DebugToolbar.php @@ -71,9 +71,11 @@ public function after(RequestInterface $request, ResponseInterface $response) } $script = PHP_EOL - . '' + . '' + . '' . PHP_EOL; if (strpos($response->getBody(), '') !== false) diff --git a/system/Debug/Toolbar/toolbarloader.js.php b/system/Debug/Toolbar/toolbarloader.js.php index 7aafb90ad652..e55e8b33db0b 100644 --- a/system/Debug/Toolbar/toolbarloader.js.php +++ b/system/Debug/Toolbar/toolbarloader.js.php @@ -18,12 +18,28 @@ function loadDoc(time) { if (!toolbar) { toolbar = document.createElement('div'); toolbar.setAttribute('id', 'toolbarContainer'); - toolbar.innerHTML = this.responseText; document.body.appendChild(toolbar); - } else { - toolbar.innerHTML = this.responseText; } - eval(document.getElementById("toolbar_js").innerHTML); + // get csp blocked parts + let Style; + let Script; + { + let PosBeg = this.responseText.indexOf( '>', this.responseText.indexOf( '' ); + Style = this.responseText.substr( PosBeg, PosEnd - PosBeg ); + document.getElementById( 'debugbar_dynamic_style' ).innerHTML = Style; + this.responseText = this.responseText.substr( PosEnd + 8 ); + } + { + + let PosBeg = this.responseText.indexOf( '>', this.responseText.indexOf( '' ); + Script = this.responseText.substr( PosBeg, PosEnd - PosBeg ); + document.getElementById( 'debugbar_dynamic_script' ).innerHTML = Script; + this.responseText = this.responseText.substr( PosEnd + 9 ); + } + + toolbar.innerHTML = this.responseText; if (typeof ciDebugBar === 'object') { ciDebugBar.init(); } From 7e20b3f68383fd9c6af56f83e343212ada98a57a Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Thu, 2 Aug 2018 11:38:42 +0200 Subject: [PATCH 2/5] ~ replace most inline styles with css rules Signed-off-by: Christoph Potas --- system/Debug/Toolbar/Views/_config.tpl.php | 2 +- system/Debug/Toolbar/Views/_database.tpl.php | 2 +- system/Debug/Toolbar/Views/_events.tpl.php | 2 +- system/Debug/Toolbar/Views/_files.tpl.php | 2 +- system/Debug/Toolbar/Views/_history.tpl.php | 4 +-- system/Debug/Toolbar/Views/toolbar.css | 35 ++++++++++++++++++++ system/Debug/Toolbar/Views/toolbar.tpl.php | 8 ++--- 7 files changed, 45 insertions(+), 10 deletions(-) diff --git a/system/Debug/Toolbar/Views/_config.tpl.php b/system/Debug/Toolbar/Views/_config.tpl.php index 7e3f2bcc4700..b05ce5f7775f 100644 --- a/system/Debug/Toolbar/Views/_config.tpl.php +++ b/system/Debug/Toolbar/Views/_config.tpl.php @@ -1,4 +1,4 @@ -

+

Read the CodeIgniter docs...

diff --git a/system/Debug/Toolbar/Views/_database.tpl.php b/system/Debug/Toolbar/Views/_database.tpl.php index ace8da2c95eb..b5cf1a43a7d7 100644 --- a/system/Debug/Toolbar/Views/_database.tpl.php +++ b/system/Debug/Toolbar/Views/_database.tpl.php @@ -1,7 +1,7 @@ - + diff --git a/system/Debug/Toolbar/Views/_events.tpl.php b/system/Debug/Toolbar/Views/_events.tpl.php index 72be9b97c696..88d732f41d5d 100644 --- a/system/Debug/Toolbar/Views/_events.tpl.php +++ b/system/Debug/Toolbar/Views/_events.tpl.php @@ -1,7 +1,7 @@
TimeTime Query String
- + diff --git a/system/Debug/Toolbar/Views/_files.tpl.php b/system/Debug/Toolbar/Views/_files.tpl.php index 7328e39bc4b3..9c992ab715c3 100644 --- a/system/Debug/Toolbar/Views/_files.tpl.php +++ b/system/Debug/Toolbar/Views/_files.tpl.php @@ -8,7 +8,7 @@ {/userFiles} {coreFiles} - + {/coreFiles} diff --git a/system/Debug/Toolbar/Views/_history.tpl.php b/system/Debug/Toolbar/Views/_history.tpl.php index e777b89d2abf..9db00ecc4679 100644 --- a/system/Debug/Toolbar/Views/_history.tpl.php +++ b/system/Debug/Toolbar/Views/_history.tpl.php @@ -13,10 +13,10 @@ {files} - - + diff --git a/system/Debug/Toolbar/Views/toolbar.css b/system/Debug/Toolbar/Views/toolbar.css index 079157021d92..e3b92a67964a 100644 --- a/system/Debug/Toolbar/Views/toolbar.css +++ b/system/Debug/Toolbar/Views/toolbar.css @@ -356,3 +356,38 @@ display: none !important; } } + +/** +simple styles to replace inline styles + */ +.debug-bar-width30 { + width: 30%; +} + +.debug-bar-width10 { + width: 10%; +} + +.debug-bar-width70p { + width: 70px; +} + +.debug-bar-width140p { + width: 140px; +} + +.debug-bar-width20e { + width: 20em; +} + +.debug-bar-width6r { + width: 6rem; +} + +.debug-bar-ndisplay { + display: none; +} + +.debug-bar-alignRight { + text-align: right; +} diff --git a/system/Debug/Toolbar/Views/toolbar.tpl.php b/system/Debug/Toolbar/Views/toolbar.tpl.php index 44baeab7619a..c04ac82a1904 100644 --- a/system/Debug/Toolbar/Views/toolbar.tpl.php +++ b/system/Debug/Toolbar/Views/toolbar.tpl.php @@ -5,7 +5,7 @@ -"; + + $styleCount++; } return $output; diff --git a/system/Debug/Toolbar/Views/toolbar.css b/system/Debug/Toolbar/Views/toolbar.css index e3b92a67964a..64caffaaeb8d 100644 --- a/system/Debug/Toolbar/Views/toolbar.css +++ b/system/Debug/Toolbar/Views/toolbar.css @@ -391,3 +391,11 @@ simple styles to replace inline styles .debug-bar-alignRight { text-align: right; } + +.debug-bar-alignLeft { + text-align: left; +} + +.debug-bar-noverflow { + overflow: hidden; +} diff --git a/system/Debug/Toolbar/Views/toolbar.tpl.php b/system/Debug/Toolbar/Views/toolbar.tpl.php index c04ac82a1904..e290df6ff3a2 100644 --- a/system/Debug/Toolbar/Views/toolbar.tpl.php +++ b/system/Debug/Toolbar/Views/toolbar.tpl.php @@ -102,7 +102,7 @@ - +
TimeTime Event Name Times Called
{name}{name} {path}
+ {datetime}{datetime} {status} {method} {url}
@@ -270,5 +270,11 @@ setData($config)->render('_config.tpl') ?> - + diff --git a/system/Debug/Toolbar/toolbarloader.js.php b/system/Debug/Toolbar/toolbarloader.js.php index 01f20dcc4a20..d1e09df0eb11 100644 --- a/system/Debug/Toolbar/toolbarloader.js.php +++ b/system/Debug/Toolbar/toolbarloader.js.php @@ -20,23 +20,34 @@ function loadDoc(time) { toolbar.setAttribute('id', 'toolbarContainer'); document.body.appendChild(toolbar); } + + // copy for easier manipulation + let responseText = this.responseText; + // get csp blocked parts // the style block is the first and starts at 0 { - let PosBeg = this.responseText.indexOf( '>', this.responseText.indexOf( '' ); - document.getElementById( 'debugbar_dynamic_style' ).innerHTML = this.responseText.substr( PosBeg, PosEnd ) - this.responseText = this.responseText.substr( PosEnd + 8 ); + let PosBeg = responseText.indexOf( '>', responseText.indexOf( '', PosBeg ); + document.getElementById( 'debugbar_dynamic_style' ).innerHTML = responseText.substr( PosBeg, PosEnd ) + responseText = responseText.substr( PosEnd + 8 ); } // the script block starts right after style blocks ended { - let PosBeg = this.responseText.indexOf( '>', this.responseText.indexOf( '' ); - document.getElementById( 'debugbar_dynamic_script' ).innerHTML = this.responseText.substr( PosBeg, PosEnd - PosBeg ); - this.responseText = this.responseText.substr( PosEnd + 9 ); + let PosBeg = responseText.indexOf( '>', responseText.indexOf( '' ); + document.getElementById( 'debugbar_dynamic_script' ).innerHTML = responseText.substr( PosBeg, PosEnd - PosBeg ); + responseText = responseText.substr( PosEnd + 9 ); + } + // check for last style block + { + let PosBeg = responseText.indexOf( '>', responseText.lastIndexOf( '', PosBeg ); + document.getElementById( 'debugbar_dynamic_style' ).innerHTML += responseText.substr( PosBeg, PosEnd - PosBeg ); + responseText = responseText.substr( 0, PosBeg ); } - toolbar.innerHTML = this.responseText; + toolbar.innerHTML = responseText; if (typeof ciDebugBar === 'object') { ciDebugBar.init(); } From 14328f9b044e8a22515d15f862ac5322493c3f49 Mon Sep 17 00:00:00 2001 From: Christoph Potas Date: Thu, 2 Aug 2018 13:27:48 +0200 Subject: [PATCH 5/5] ~ fix last style tag position + added data: to image source (csp) -> fix icons not shown Signed-off-by: Christoph Potas --- system/Debug/Toolbar.php | 5 +++++ system/Debug/Toolbar/Views/toolbar.tpl.php | 14 +++++++------- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/system/Debug/Toolbar.php b/system/Debug/Toolbar.php index 8c401800df49..7f46f354ae24 100644 --- a/system/Debug/Toolbar.php +++ b/system/Debug/Toolbar.php @@ -196,6 +196,11 @@ public function run($startTime, $totalTime, $request, $response): string $data['config'] = \CodeIgniter\Debug\Toolbar\Collectors\Config::display(); + if( $response->CSP !== null ) + { + $response->CSP->addImageSrc( 'data:' ); + } + return json_encode($data); } diff --git a/system/Debug/Toolbar/Views/toolbar.tpl.php b/system/Debug/Toolbar/Views/toolbar.tpl.php index e290df6ff3a2..9ec05e4ee5b6 100644 --- a/system/Debug/Toolbar/Views/toolbar.tpl.php +++ b/system/Debug/Toolbar/Views/toolbar.tpl.php @@ -270,11 +270,11 @@ setData($config)->render('_config.tpl') ?> - +