Skip to content

Fix 'headers already sent' warning in extensionController - #9230

Closed
andris155 wants to merge 3 commits into
FreshRSS:edgefrom
andris155:patch-1
Closed

andris155 wants to merge 3 commits into
FreshRSS:edgefrom
andris155:patch-1

Conversation

@andris155

@andris155 andris155 commented Aug 22, 2026 •

Copy link
Copy Markdown
Contributor

Closes #9229

Changes proposed in this pull request:

This PR fixes a "Cannot modify header information - headers already sent" warning that occurs when serving extension files (like custom CSS) via extensionController.php.
It's done by rendering the extension file in the view instead of echoing it, so that it matches the order of operations:

  • execute action -> declare csp header -> render view
    instead of:
  • execute action -> start output by printing the extension file's contents (!) -> declare csp header (output already started, prints warning) -> render view (which was empty before)

How to test the feature manually:

With this change:

  1. Go to FreshRSS UserCSS extension config
  2. Enable the UserCSS and set the CSS code in it.
  3. Go to FreshRSS feeds page.
  4. Hit the ctrl + F5 button and see no errors in the nginx log.

CSS file: style.css

Pull request checklist:

  • clear commit messages
  • code manually tested
  • unit tests written (optional if too hard)
  • documentation updated

Additional information can be found in the documentation.

@Alkarex Alkarex added this to the 1.30.0 milestone Aug 22, 2026
@Alkarex Alkarex added Minz Pull requests that update Minz code Extension 🔌 Bug (unconfirmed) issues that could not be reproduced yet and removed Minz Pull requests that update Minz code labels Aug 22, 2026
Comment thread app/Controllers/extensionController.php Outdated
if (file_exists(DATA_PATH . '/no-cache.txt') || !httpConditional($mtime, cacheSeconds: 604800, cachePrivacy: 2)) {
echo $extension->getFile($filename);
}
exit;

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's used as exit() elsewhere. (Also I somewhat wonder if it shouldn't be in Dispatcher, but I suppose that's neither here nor there.)

if ($redirect) {
header('Location: ' . Minz_Url::display($url, 'php', 'root'));
exit();

@Inverle

Inverle commented Aug 23, 2026

Copy link
Copy Markdown
Member

I made changes to use the approach from the export action instead:

header('Content-Type: ' . $content_type);
header('Content-disposition: attachment; filename="' . $filename . '"');
$this->view->_layout(null);
$this->view->content = $content;

The view is rendered by the framework after it sets the CSP header, this line specifically:

header('Content-Security-Policy: ' . implode('; ', $policies));

But I did not see any PHP warnings even before adding the exit; or the approach above, so testing welcome.

@Inverle Inverle added Bug (confirmed) 🐞 issues that are reproducible and removed Bug (unconfirmed) issues that could not be reproduced yet labels Aug 23, 2026
@Inverle

Inverle commented Aug 23, 2026

Copy link
Copy Markdown
Member

Related: #3035 (comment)

@Frenzie

Frenzie commented Aug 23, 2026

Copy link
Copy Markdown
Member

I made changes to use the approach from the export action instead:

Right, that's the same thing as what I was alluding to, just without special casing a null view.

But I did not see any PHP warnings even before adding the exit; or the approach above, so testing welcome.

Same, as I said.

@andris155

andris155 commented Aug 23, 2026 •

Copy link
Copy Markdown
Contributor Author

I made changes to use the approach from the export action instead:

header('Content-Type: ' . $content_type);
header('Content-disposition: attachment; filename="' . $filename . '"');
$this->view->_layout(null);
$this->view->content = $content;

The view is rendered by the framework after it sets the CSP header, this line specifically:

header('Content-Security-Policy: ' . implode('; ', $policies));

But I did not see any PHP warnings even before adding the exit; or the approach above, so testing welcome.

With your changes works perfectly without PHP warnings.

@andris155 andris155 closed this by deleting the head repository Sep 4, 2026
Alkarex pushed a commit that referenced this pull request Sep 6, 2026
#9267)

Closes #9229

I restored my accidently deleted patches with @Inverle fixes. This fix is still works perfectly. Sorry. (#9230)

How to test the feature manually:

With this change:
1. Go to FreshRSS UserCSS extension config
2. Enable the UserCSS and set the CSS code in it.
3. Go to FreshRSS feeds page.
4. Hit the ctrl + F5 button and see no errors in the nginx log.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Bug (confirmed) 🐞 issues that are reproducible Extension 🔌

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug] UserCSS headers already sent by php error

4 participants