Skip to content

Commit 6ae19a6

Browse files
author
Luke Towers
committed
Implement support for backend.allow_unsafe_markdown and improve support for Swoole
1 parent f85039b commit 6ae19a6

File tree

2 files changed

+33
-7
lines changed

2 files changed

+33
-7
lines changed

formwidgets/BlogMarkdown.php

+27-7
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@
2020
*/
2121
class BlogMarkdown extends MarkdownEditor
2222
{
23+
/**
24+
* {@inheritDoc}
25+
*/
2326
public function init()
2427
{
2528
$this->viewPath = base_path().'/modules/backend/formwidgets/markdowneditor/partials';
@@ -29,12 +32,28 @@ public function init()
2932
parent::init();
3033
}
3134

35+
/**
36+
* {@inheritDoc}
37+
*/
3238
protected function loadAssets()
3339
{
3440
$this->assetPath = '/modules/backend/formwidgets/markdowneditor/assets';
3541
parent::loadAssets();
3642
}
3743

44+
/**
45+
* Disable HTML cleaning on the widget level since the PostModel will handle it
46+
*
47+
* @return boolean
48+
*/
49+
protected function shouldCleanHtml()
50+
{
51+
return false;
52+
}
53+
54+
/**
55+
* {@inheritDoc}
56+
*/
3857
public function onRefresh()
3958
{
4059
$content = post($this->formField->getName());
@@ -46,6 +65,11 @@ public function onRefresh()
4665
];
4766
}
4867

68+
/**
69+
* Handle images being uploaded to the blog post
70+
*
71+
* @return void
72+
*/
4973
protected function checkUploadPostback()
5074
{
5175
if (!post('X_BLOG_IMAGE_UPLOAD')) {
@@ -90,11 +114,9 @@ protected function checkUploadPostback()
90114
];
91115

92116
$response = Response::make()->setContent($result);
93-
$response->send();
117+
$this->controller->setResponse($response);
94118

95-
die();
96-
}
97-
catch (Exception $ex) {
119+
} catch (Exception $ex) {
98120
$message = $uploadedFileName
99121
? Lang::get('cms::lang.asset.error_uploading_file', ['name' => $uploadedFileName, 'error' => $ex->getMessage()])
100122
: $ex->getMessage();
@@ -105,9 +127,7 @@ protected function checkUploadPostback()
105127
];
106128

107129
$response = Response::make()->setContent($result);
108-
$response->send();
109-
110-
die();
130+
$this->controller->setResponse($response);
111131
}
112132
}
113133
}

models/Post.php

+6
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,12 @@ public static function formatHtml($input, $preview = false)
189189
{
190190
$result = Markdown::parse(trim($input));
191191

192+
// Check to see if the HTML should be cleaned from potential XSS
193+
$user = BackendAuth::getUser();
194+
if (!$user || !$user->hasAccess('backend.allow_unsafe_markdown')) {
195+
$result = Html::clean($result);
196+
}
197+
192198
if ($preview) {
193199
$result = str_replace('<pre>', '<pre class="prettyprint">', $result);
194200
}

0 commit comments

Comments
 (0)