Skip to content

Comments

[4.0] Make sure the renderer does not manipulate the inline CSS and JS#28719

Merged
wilsonge merged 6 commits intojoomla:4.0-devfrom
zero-24:fix_style_script_renderer
Aug 11, 2020
Merged

[4.0] Make sure the renderer does not manipulate the inline CSS and JS#28719
wilsonge merged 6 commits intojoomla:4.0-devfrom
zero-24:fix_style_script_renderer

Conversation

@zero-24
Copy link
Contributor

@zero-24 zero-24 commented Apr 18, 2020

Pull Request for Issue #28557

Summary of Changes

Make sure there renderer does not manipulate the inline CSS and JS

Testing Instructions

Add the following lines to the index.php of the cassiopea template:

// Add inline JavaScript
Factory::getDocument()->addScriptDeclaration('
    window.event("domready", function() {
        alert("An inline JavaScript Declaration");
    });
');

// Add inline Style
Factory::getDocument()->addStyleDeclaration('
	body {
		background: #00ff00;
		color: rgb(0,0,255);
	}
');

Enable CSP (System -> Content-Security-Policy -> Options) and configure like this:
image

  • visit the frontend
  • notice that the styles and scripts are blocked before the patch
  • apply the patch
  • notice it is working now

Expected result

inline script and inline style tags are not modified by the renderer and can be whitelisted via an csp.

Actual result

the style and script renderer add some spaces and line endings that breaks the CSP hash generation.

Documentation Changes Required

none

cc @wilsonge @SharkyKZ

@zero-24
Copy link
Contributor Author

zero-24 commented Apr 18, 2020

Here is the backport to 3.x: #28720

@Bodge-IT
Copy link
Contributor

Pls overlook my ignorance, isn't it cassiopea on J4?

@zero-24
Copy link
Contributor Author

zero-24 commented Apr 18, 2020

Yes thanks fixed. I worked in parallel on protostar too :D

@richard67 richard67 changed the title [4.0] Make sure there rendere does not manipulate the inline CSS and JS [4.0] Make sure there renderer does not manipulate the inline CSS and JS Apr 18, 2020
@richard67 richard67 changed the title [4.0] Make sure there renderer does not manipulate the inline CSS and JS [4.0] Make sure the renderer does not manipulate the inline CSS and JS Apr 18, 2020
@wilsonge
Copy link
Contributor

This is going to make the source look much worse when debugging. But then again given everyone uses dev tools in browsers these days I guess it doesn't matter much either?

@zero-24
Copy link
Contributor Author

zero-24 commented Apr 18, 2020

This is going to make the source look much worse when debugging. But then again given everyone uses dev tools in browsers these days I guess it doesn't matter much either?

I have not noticed any difference in the dev tools.

@zero-24
Copy link
Contributor Author

zero-24 commented Apr 18, 2020

BTW you should not use any inline JS or Inline CSS anyway so one more reason to not use them :D

@Bodge-IT
Copy link
Contributor

Yes thans fixed. I worked in parallel on protostar too :D

Thanks Tobias, I need a bit more info as running into some wierdness.
With security policy enabled or disabled, I get this warning:
( ! ) Warning: hash() expects parameter 2 to be string, array given in F:\xampp\htdocs\j4test\plugins\system\httpheaders\httpheaders.php on line 178
Can I ignore?
Also, I'm testing this locally, that OK for this PR?

@zero-24
Copy link
Contributor Author

zero-24 commented Apr 18, 2020

Yes you can ignore it. That is an issue that has been patched here too when you apply the patch that Warning should be gone too.

// 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

@zero-24 zero-24 added this to the Joomla 4.0 milestone Jun 26, 2020
@vlaucht
Copy link

vlaucht commented Aug 4, 2020

I have tested this item ✅ successfully on 169e33e

Tested with Chrome on Win64


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28719.

@jmeintrup
Copy link

I have tested this item ✅ successfully on 169e33e

Tested successfully.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/28719.

@richard67
Copy link
Member

@wilsonge @zero-24 I'm waiting with RTC until your above discussion is resolved.

@Fedik
Copy link
Member

Fedik commented Aug 11, 2020

CDATA for xhtml/xml document, and as long as Document may be used for render XML I would keep it. Even if we never used it 😄

https://stackoverflow.com/a/66865/1000711

@zero-24
Copy link
Contributor Author

zero-24 commented Aug 11, 2020

Ok right now to me this PR looks ready than given that I do not touch the CDATA thing and that we only apply hashes on HTML sites anyway.

@wilsonge wilsonge merged commit f64ddd2 into joomla:4.0-dev Aug 11, 2020
@wilsonge
Copy link
Contributor

I'm still not 100% we're getting this right - but let's give it a go

@zero-24 zero-24 deleted the fix_style_script_renderer branch August 11, 2020 18:12
@zero-24
Copy link
Contributor Author

zero-24 commented Aug 11, 2020

Thanks please merge the backport too: #28720

dgrammatiko added a commit to dgrammatiko/joomla-cms that referenced this pull request Aug 13, 2020
…om_templates

* '4.0-dev' of github.com:joomla/joomla-cms:
  Add closing quote (joomla#30353)
  [4.0] Make sure the renderer does not manipulate the inline CSS and JS (joomla#28719)
  [4.0] Atum and Cassiopea Change alerts styling - space saving + (joomla#30294)
  Update editor versions (joomla#30340)
  [4.0][mod_menu] Add space for 'menu class' (joomla#30341)
  Optimize code for aria-current (joomla#30328)
  [4.0] Composer and npm updates 10 Aug (joomla#30334)
  [4.0] fix js code style (joomla#30335)
sakiss pushed a commit to sakiss/joomla-cms that referenced this pull request Oct 16, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

10 participants