Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add nonce attribute to all HTML snippets automatically #315

Merged
merged 2 commits into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions controllers/AbstractCustomContainerController.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
use humhub\components\access\StrictAccess;
use humhub\modules\admin\permissions\ManageModules;
use humhub\modules\content\components\ContentContainerController;
use humhub\modules\custom_pages\helpers\Html;
use humhub\modules\custom_pages\models\ContainerPage;
use humhub\modules\custom_pages\models\ContainerSnippet;
use humhub\modules\custom_pages\models\CustomContentContainer;
Expand Down Expand Up @@ -116,8 +117,6 @@ public function renderTemplate($page, $editMode = null)
$canEdit = PagePermission::canEdit();
$editMode = ($editMode || Yii::$app->request->get('editMode')) && $canEdit;

$html = '';

if(!$canEdit && TemplateCache::exists($templateInstance)) {
$html = TemplateCache::get($templateInstance);
} else {
Expand All @@ -126,7 +125,8 @@ public function renderTemplate($page, $editMode = null)
TemplateCache::set($templateInstance, $html);
}
}
return $html;

return Html::applyScriptNonce($html);
}

/**
Expand All @@ -148,4 +148,4 @@ public function isCanEdit() {
return $this->_canEdit;
}

}
}
1 change: 1 addition & 0 deletions docs/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ Changelog
Unreleased
-------------------------
- Fix #312: Highlight the top menu entry if the current URL matches the Target Url of a "Link" custom page
- Enh #314: Add nonce attribute to all JavaScript tags in snippet templates and HTML snippets automatically

1.9.5 (November 16, 2023)
-------------------------
Expand Down
5 changes: 5 additions & 0 deletions models/Snippet.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace humhub\modules\custom_pages\models;

use humhub\modules\custom_pages\helpers\Html;
use humhub\modules\custom_pages\helpers\Url;
use humhub\modules\custom_pages\models\forms\SettingsForm;
use humhub\modules\custom_pages\modules\template\models\Template;
Expand Down Expand Up @@ -111,6 +112,10 @@ public function getAllowedTemplateSelection()
*/
public function getPageContent()
{
if ($this->type == HtmlType::ID) {
return Html::applyScriptNonce($this->page_content);
}

return $this->page_content;
}

Expand Down
Loading