Skip to content
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
6 changes: 3 additions & 3 deletions libraries/src/Document/Renderer/Html/ScriptsRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -256,23 +256,23 @@ private function renderInlineElement($item) : string

$buffer .= $tab . '<script';
$buffer .= $this->renderAttributes($attribs);
$buffer .= '>' . $lnEnd;
$buffer .= '>';

// This is for full XHTML support.
if ($this->_doc->_mime !== 'text/html')
{
$buffer .= $tab . $tab . '//<![CDATA[' . $lnEnd;
Copy link
Contributor

Choose a reason for hiding this comment

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

Will this CData tag still work without the line break above? Honestly don't know enough here to be sure.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

How to trigger that stuff anyway? Does joomla actually support something different than html and json?

Copy link
Contributor

Choose a reason for hiding this comment

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

In the template of your choice something like $this->setMimeEncoding('application/xhtml+xml')

Copy link
Contributor

Choose a reason for hiding this comment

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

Technically it does support these things - but I think it dates back to XHTML support. We can probably get rid of it (we should try and track back it's introduction first). But if we leave it in it should work

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I mean in terms of out of scope I assume if you're running an xhtml mime type it won't work with csp ;)

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this mean it can be removed?

Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

I honestly have no clue. It’s probably safe. But I’m not certain either. I certainly have no clue if the CDATA tag has any use anymore - again I suspect it’s legacy. But I’m not certain

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I mean in terms of out of scope I assume if you're running an xhtml mime type it won't work with csp ;)

Right we would not try to add hashes there we only do for HTML: https://github.com/joomla/joomla-cms/blob/4.0-dev/plugins/system/httpheaders/httpheaders.php#L140

}

$buffer .= $content . $lnEnd;
$buffer .= $content;

// See above note
if ($this->_doc->_mime !== 'text/html')
{
$buffer .= $tab . $tab . '//]]>' . $lnEnd;
}

$buffer .= $tab . '</script>' . $lnEnd;
$buffer .= '</script>' . $lnEnd;

return $buffer;
}
Expand Down
6 changes: 3 additions & 3 deletions libraries/src/Document/Renderer/Html/StylesRenderer.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,23 +250,23 @@ private function renderInlineElement($item) : string

$buffer .= $tab . '<style';
$buffer .= $this->renderAttributes($attribs);
$buffer .= '>' . $lnEnd;
$buffer .= '>';

// This is for full XHTML support.
if ($this->_doc->_mime !== 'text/html')
{
$buffer .= $tab . $tab . '/*<![CDATA[*/' . $lnEnd;
}

$buffer .= $content . $lnEnd;
$buffer .= $content;

// See above note
if ($this->_doc->_mime !== 'text/html')
{
$buffer .= $tab . $tab . '/*]]>*/' . $lnEnd;
}

$buffer .= $tab . '</style>' . $lnEnd;
$buffer .= '</style>' . $lnEnd;

return $buffer;
}
Expand Down
11 changes: 7 additions & 4 deletions plugins/system/httpheaders/httpheaders.php
Original file line number Diff line number Diff line change
Expand Up @@ -174,9 +174,12 @@ public function applyHashesToCspRule(): void
// Generate the hashes for the style-src
$inlineStyles = is_array($headData['style']) ? $headData['style'] : [];

foreach ($inlineStyles as $type => $styleContent)
foreach ($inlineStyles as $type => $styles)
{
$styleHashes[] = "'sha256-" . base64_encode(hash('sha256', $styleContent, true)) . "'";
foreach ($styles as $hash => $styleContent)
{
$styleHashes[] = "'sha256-" . base64_encode(hash('sha256', $styleContent, true)) . "'";
}
}
}

Expand Down Expand Up @@ -413,12 +416,12 @@ private function compileAutomaticCspHeaderRules(): array
$cspHeaderCollection = array_merge($cspHeaderCollection, array_fill_keys(['default-src'], ''));
}

if (!isset($cspHeaderCollection['script-src']) && $nonceEnabled)
if (!isset($cspHeaderCollection['script-src']) && ($scriptHashesEnabled || $nonceEnabled))
{
$cspHeaderCollection = array_merge($cspHeaderCollection, array_fill_keys(['script-src'], ''));
}

if (!isset($cspHeaderCollection['style-src']) && $nonceEnabled)
if (!isset($cspHeaderCollection['style-src']) && ($scriptHashesEnabled || $nonceEnabled))
{
$cspHeaderCollection = array_merge($cspHeaderCollection, array_fill_keys(['style-src'], ''));
}
Expand Down