Files
FreshRSS/lib/core-extensions/UserCSS/extension.php
T
Alexandre Alapetite 8ffddc11f8 More security for extension files: nosniff (#9593)
Global `X-Content-Type-Options: nosniff`
And follow-up of #7753
2026-11-20 13:54:09 +01:00

45 lines
1.2 KiB
PHP

<?php
declare(strict_types=1);
final class UserCSSExtension extends Minz_Extension {
public string $css_rules = '';
private const FILENAME = 'style.css';
#[\Override]
public function init(): void {
parent::init();
$this->registerTranslates();
if ($this->hasFile(self::FILENAME)) {
Minz_View::appendStyle($this->getFileUrl(self::FILENAME, isStatic: false));
}
}
#[\Override]
public function handleConfigureAction(): void {
parent::init();
$this->registerTranslates();
if (FreshRSS_Auth::requestReauth()) {
return;
}
if (Minz_Request::isPost()) {
$css_rules = Minz_Request::paramString('css-rules', plaintext: true);
$this->saveFile(self::FILENAME, $css_rules);
FreshRSS_UserDAO::touch();
// Redirect (Post/Redirect/Get) so the next page is built after the save,
// with a fresh cache-busting URL for the updated stylesheet
Minz_Request::good(_t('feedback.conf.updated'), [
'c' => 'extension', 'a' => 'configure', 'params' => ['e' => $this->getName()],
]);
}
$this->css_rules = '';
if ($this->hasFile(self::FILENAME)) {
$this->css_rules = htmlspecialchars($this->getFile(self::FILENAME) ?? '', ENT_NOQUOTES, 'UTF-8');
}
}
}