Skip to content

Commit 4c3c074

Browse files
authored
Merge pull request #6 from GreenMeteor/dev
Fix: Nonce
2 parents e0ff3aa + 2a44bbd commit 4c3c074

File tree

3 files changed

+21
-15
lines changed

3 files changed

+21
-15
lines changed

Module.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use Yii;
66
use yii\helpers\Url;
7+
use humhub\libs\Html;
78
use humhub\components\Module as BaseModule;
89

910
class Module extends BaseModule
@@ -31,12 +32,15 @@ public function getTitle()
3132
public function getHtmlCode()
3233
{
3334
$htmlCode = $this->settings->get('htmlCode');
35+
3436
if (empty($htmlCode)) {
3537
return '';
3638
}
39+
3740
return $htmlCode;
3841
}
3942

43+
4044
public function getOrder()
4145
{
4246
$sortOrder = $this->settings->get('sortOrder');

widgets/CodeboxFrame.php

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,17 +3,14 @@
33
namespace humhub\modules\codebox\widgets;
44

55
use Yii;
6+
use humhub\libs\Html;
67
use humhub\components\Widget;
7-
use humhub\modules\web\security\helpers\Security;
88

99
/**
1010
* CodeboxFrame adds HTML snippet code to all layouts extended by config.php
1111
*/
1212
class CodeboxFrame extends Widget
1313
{
14-
15-
public $contentContainer;
16-
1714
/**
1815
* @inheritdoc
1916
*/
@@ -31,7 +28,16 @@ public function run()
3128
return '';
3229
}
3330

34-
return $this->render('codeboxframe', ['title' => $title, 'htmlCode' => $htmlCode, $sortOrder => 'sortOrder', 'nonce' => Security::getNonce()]);
31+
// Generate nonce attribute
32+
$nonce = Html::nonce();
33+
34+
// Check if {{nonce}} placeholder exists in htmlCode
35+
if (strpos($htmlCode, 'nonce={{nonce}}') !== false) {
36+
// Replace {{nonce}} with the generated nonce value
37+
$htmlCode = str_replace('nonce={{nonce}}', $nonce, $htmlCode);
38+
}
39+
40+
return $this->render('codeboxframe', ['title' => $title, 'htmlCode' => $htmlCode, 'sortOrder' => $sortOrder, 'nonce' => $nonce]);
3541
}
3642

3743
}

widgets/views/codeboxframe.php

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,10 @@
77

88
<div class="panel panel-default panel-codebox" id="panel-codebox">
99
<?= PanelMenu::widget(['id' => 'panel-codebox']); ?>
10-
<div class="panel-heading">
11-
<strong><?= Html::encode($title) ?></strong>
12-
</div>
13-
<div class="panel-body">
14-
15-
<?= Html::beginTag('div') ?>
16-
<?= $htmlCode ?>
17-
<?= Html::endTag('div'); ?>
18-
19-
</div>
10+
<div class="panel-heading">
11+
<strong><?= Html::encode($title) ?></strong>
12+
</div>
13+
<div class="panel-body">
14+
<?= $htmlCode ?>
15+
</div>
2016
</div>

0 commit comments

Comments
 (0)