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

Check for disallowed BB codes in the content #5946

Merged
merged 1 commit into from
Jun 18, 2024
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
2 changes: 2 additions & 0 deletions wcfsetup/install/files/acp/templates/articleAdd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,8 @@
<small class="innerError">
{if $errorType == 'empty'}
{lang}wcf.global.form.error.empty{/lang}
{elseif $errorType == 'disallowedBBCodes'}
{lang}wcf.message.error.disallowedBBCodes{/lang}
{else}
{lang}wcf.acp.article.content.error.{@$errorType}{/lang}
{/if}
Expand Down
27 changes: 27 additions & 0 deletions wcfsetup/install/files/lib/acp/form/ArticleAddForm.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use wcf\data\user\User;
use wcf\form\AbstractForm;
use wcf\system\attachment\AttachmentHandler;
use wcf\system\bbcode\BBCodeHandler;
use wcf\system\cache\builder\ArticleCategoryLabelCacheBuilder;
use wcf\system\exception\UserInputException;
use wcf\system\html\input\HtmlInputProcessor;
Expand Down Expand Up @@ -424,6 +425,8 @@ public function validate()
}
}

$this->setDisallowedBBCodes();

if ($this->isMultilingual) {
foreach (LanguageFactory::getInstance()->getLanguages() as $language) {
// title
Expand All @@ -441,6 +444,12 @@ public function validate()
'com.woltlab.wcf.article.content',
0
);

$disallowedBBCodes = $this->htmlInputProcessors[$language->languageID]->validate();
if (!empty($disallowedBBCodes)) {
WCF::getTPL()->assign('disallowedBBCodes', $disallowedBBCodes);
throw new UserInputException('content', 'disallowedBBCodes');
}
}
} else {
// title
Expand All @@ -454,6 +463,12 @@ public function validate()

$this->htmlInputProcessors[0] = new HtmlInputProcessor();
$this->htmlInputProcessors[0]->process($this->content[0], 'com.woltlab.wcf.article.content', 0);

$disallowedBBCodes = $this->htmlInputProcessors[0]->validate();
if (!empty($disallowedBBCodes)) {
WCF::getTPL()->assign('disallowedBBCodes', $disallowedBBCodes);
throw new UserInputException('content', 'disallowedBBCodes');
}
}

$this->validateLabelIDs();
Expand Down Expand Up @@ -616,6 +631,8 @@ public function readData()
}
}
}

$this->setDisallowedBBCodes();
}

/**
Expand Down Expand Up @@ -677,4 +694,14 @@ public function assignVariables()
'tmpHash' => $this->tmpHash,
]);
}

protected function setDisallowedBBCodes(): void
{
BBCodeHandler::getInstance()->setDisallowedBBCodes(
\explode(
',',
WCF::getSession()->getPermission('user.message.disallowedBBCodes')
)
);
}
}
Loading