? ? ? Pending

User tests: Successful: Unsuccessful:

avatar zero-24
zero-24
15 May 2020

Summary of Changes

This PR adds an additional validation rule for CSS classes to all places where we use them. This has been found in an internal audit and has been reported to the JSST in the past. And we decided now to move it to the public tracker and because you need to have quite high permissions to set it up and we think this should be tested more widely.

Original reporter: @SniperSister, @yvesh and @bembelimen from the JSST and Khoa Bùi Đức Anh

Testing Instructions

  • apply this patch
  • go to a module or com_fields where you can add custom css classes.
  • add whatever you normally add in there.
  • make sure the filter passes that

Expected result

The filter passes only valid class names

Actual result

There is no filter and all you put in there could result into an XSS issue in the end.

Documentation Changes Required

That new rule needs to be documented.

to-do

  • Allow -1st -2st for the first value of that field
  • Allow --whatever for the first value of that field (there is no suffix support in 4.x anymore)
  • Make sure the BEM CSS (http://getbem.com/naming/) structure is still supported.
  • allow sm:justify-center
  • add an extra check for value 0 as that is a not allowed a 0 without an leading space is allowed.
avatar zero-24 zero-24 - open - 15 May 2020
avatar zero-24 zero-24 - change - 15 May 2020
Status New Pending
avatar joomla-cms-bot joomla-cms-bot - change - 15 May 2020
Category Administration com_fields com_menus com_modules com_tags Modules
avatar zero-24
zero-24 - comment - 15 May 2020

Here you can find the backport for 3.10 so extension developers can use the same validation rule in 3.10 and 4.0: #29109

avatar zero-24 zero-24 - change - 15 May 2020
Labels Added: ? ?
avatar mbabker
mbabker - comment - 15 May 2020

Since the JSST decided this can be publicly patched, a proof of concept of the issue should be included in the form of automated tests which can validate the rule is actually blocking the input that you want removed.

avatar zero-24
zero-24 - comment - 15 May 2020

Since the JSST decided this can be publicly patched, a proof of concept of the issue should be included in the form of automated tests which can validate the rule is actually blocking the input that you want removed.

Sure here an example for fields:
image

You know I'm not good with unit tests but I'm happy to add one when you help me to get it right.

avatar conconnl
conconnl - comment - 15 May 2020

@zero-24 As discussed.
A validation rule which blocks things like 1st, 2nd, -1st, -2nd in CSS classes will certainly mean that sites need to change there classes. I have never seen the use of -- it doesn't mean it isn't used.

avatar zero-24
zero-24 - comment - 15 May 2020

Thanks. just added a to-do item above to adjust the rule to allow that.

avatar zero-24 zero-24 - change - 15 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 15 May 2020
avatar mbabker
mbabker - comment - 15 May 2020

I have never seen the use of -- it doesn't mean it isn't used.

It's a pattern from the BEM CSS structure, it's just one way (of literally dozens) that someone can use to describe things in their CSS. One of the things I like about it is that it promotes class structures in a way where you aren't writing a lot of nested CSS, you're only going a couple levels deep usually.

As an example, on my site I have a container with the class of open-source-package open-source-package--has-logo open-source-package--has-topics open-source-package--abandoned where open-source-package is the base name of that block of code then open-source-package--has-logo is a modifier that says that the block contains an optional logo (which impacts the CSS Grid layout for that block) or open-source-package--abandoned being a modifier that says the block contains an abandoned package (right now unused but I could do a grayscale effect or something based on that class being present). It's not much different than Bootstrap's use of alert alert-success as an example, just a different set of characters between segments.

avatar zero-24
zero-24 - comment - 15 May 2020

OK that will add that to the list above. Thanks for the feedback ?

avatar zero-24 zero-24 - change - 15 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 15 May 2020
avatar zero-24
zero-24 - comment - 16 May 2020

To get a better picture of the values used @chmst cam up with a simple SQL Command

SELECT params FROM `#__modules` WHERE `params` like "%moduleclass_sfx%"

Would be awesome to get some samples for heavy sites so we can make sure the values still passes.You can send them to tobias.zulauf[at]community.joomla.org.

avatar brianteeman
brianteeman - comment - 16 May 2020

That would be interesting but not foolproof. Instead of whitelisting shouldnt you just be blacklisting the characters that are illegal for a css class and that can be used for xss

avatar zero-24
zero-24 - comment - 16 May 2020

That would be interesting but not foolproof. Instead of whitelisting shouldnt you just be blacklisting the characters that are illegal for a css class and that can be used for xss

I have to disagree here. There are requirements for css classes. So a validation rule for css classes should make sure only that is passed. this is what an validation rule is about.
as the validation rule here is not only against xss and also we can make sure it does not break the markup etc.

To not break the other valid use cases i asked to provide them to us so we can make sure they still passes the rules.

The main problem with xss and blocklists is the following:

  • browsers have to do wierd stuff to not break the internet
  • there are a ton of unicode caracters that can be interpreted as " for example.

Here because of the limited use case i think a whitelist should be the best aproache to the issue. So please share your usecases so we can makre sure we make it work :)

avatar brianteeman
brianteeman - comment - 16 May 2020

AS you correctly point out there are rules

https://www.w3.org/TR/CSS22/grammar.html

avatar zero-24
zero-24 - comment - 16 May 2020

AS you correctly point out there are rules

yes and here we have the special case of the fist beeing a suffx so we need to take care of that too.

avatar adj9
adj9 - comment - 16 May 2020

With apply a PR and create a Breadcrumbs module with Pippo class
Click Save & Close and I've this error
image

avatar zero-24
zero-24 - comment - 16 May 2020

What error do you get?

What is a pippo class?

avatar ciar4n
ciar4n - comment - 16 May 2020

Just to mention some recent CSS frameworks have started using colon punctuation in their class names... eg. sm:justify-center

avatar adj9
adj9 - comment - 16 May 2020

I've insert the name of CSS class in advanced -> Header Class, but only the name not other.

The error is number 0


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

avatar zero-24
zero-24 - comment - 16 May 2020

Great thanks @ciar4n

I can not follow you @adj9 please post the value you added to the field.

Error code 0 seems to be something else. Maybe a screenshot helps?

avatar zero-24 zero-24 - change - 16 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 16 May 2020
avatar brianteeman
brianteeman - comment - 16 May 2020

@zero-24 I just got the same error as @adj9 after using com_patchtester. Closer inspection showed that com_pathctester failed to copy the php file - just the xml

avatar brianteeman brianteeman - test_item - 16 May 2020 - Tested unsuccessfully
avatar brianteeman
brianteeman - comment - 16 May 2020

I have tested this item ? unsuccessfully on b48edbe


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

avatar brianteeman
brianteeman - comment - 16 May 2020

After successfully applying the patch and then entering an invalid class and then save or save and close I would expect not to get
image

The invalid class is not saved but the user would not know that. Usually there would be a message indicating the invalid field and that would prevent save or save and close

avatar zero-24 zero-24 - change - 18 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 18 May 2020
avatar zero-24
zero-24 - comment - 23 May 2020

I have just looked into the issues mention here.

After successfully applying the patch and then entering an invalid class and then save or save and close I would expect not to get

Can you please point me too the exact place where you entered the value and what value you used?

I can not confirm this issue and get this warning message when i enter an invalid class name:
image

Maybe I missed one place that need I need to add the new validation rule?

@zero-24 I just got the same error as @adj9 after using com_patchtester. Closer inspection showed that com_pathctester failed to copy the php file - just the xml

Hmm @roland-d can you take a look into that when you get a minute it does not make sense to me as there is nothing special done here that could confuse the PatchTester right?

Updates

With the latest commit we now don't enforce the second rule (Identifiers cannot start with a digit, two hyphens, or a hyphen followed by a digit.) any more for the suffixes but only to the full identifier.

That fixes the following todos mention above:

Allow -1st -2st for the first value of that field
Allow --whatever for the first value of that field
Make sure the BEM CSS (http://getbem.com/naming/) structure is still supported.

allow sm:justify-center

U+003A has been added to the whitelist. thanks @ciar4n

add an extra check for value 0 as that is a not allowed a 0 without an leading space is allowed.

Added thanks @mvanvu

Thanks @coolcat-creations for your database dump. I have checked them and can confirm all of them still work now as in 3.x.

Thanks.

avatar zero-24 zero-24 - change - 23 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 23 May 2020
avatar zero-24 zero-24 - change - 23 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 23 May 2020
avatar zero-24 zero-24 - change - 23 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 23 May 2020
avatar zero-24 zero-24 - change - 23 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 23 May 2020
avatar zero-24 zero-24 - change - 23 May 2020
The description was changed
avatar zero-24 zero-24 - edited - 23 May 2020
avatar brianteeman
brianteeman - comment - 24 May 2020

css

avatar zero-24
zero-24 - comment - 24 May 2020

Ok found the reason. When you use <module> it is filtered already before it lands at the validation rule. And as this field is not required but the value is empty at that point the validation rule passes.

avatar zero-24
zero-24 - comment - 20 Jun 2020

Any other feedback or tests on this thing? Would be awesome to move this forward.

avatar chmst
chmst - comment - 20 Jun 2020

I have tested with many strings - here module breadcrumbs

Module class:
<?php echo 'huhu'; ?> was removed on save. But I got no message - onyl the "module saved"
<?php echo 'hu was changed to ?php echo 'hu .. But I got no message - onyl the "module saved"

Header Class:
<?php echo 'hu' - Warning: Invalid Field: Header class
<?php echo 'huhu'; ?> - is removed, the module is saved without warning

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

avatar zero-24
zero-24 - comment - 20 Jun 2020

All of that should have been filtered before that validation rule kicks in even right now. Can you double check that @chmst ?

avatar adj9 adj9 - test_item - 25 Jun 2020 - Not tested
avatar adj9
adj9 - comment - 25 Jun 2020

I have not tested this item.

Add a class in a new module using a field Header Class (in advanced layer), click Save & Close and I've error 0:
Schermata 2020-06-25 alle 12 55 14


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/29108.
avatar zero-24
zero-24 - comment - 26 Jun 2020

Hi i can not reproduce the issue can you please try a new install of the complete branch?

avatar zero-24 zero-24 - change - 26 Jun 2020
Labels Added: Conflicting Files
avatar zero-24
zero-24 - comment - 26 Jun 2020

conflicts solved.

avatar Quy
Quy - comment - 26 Jun 2020

@adj9 It is an issue with Patch Tester not patching correctly. Try the package installer with this PR:

https://ci.joomla.org/artifacts/joomla/joomla-cms/4.0-dev/29108/downloads/33392/

avatar zero-24 zero-24 - change - 26 Jun 2020
Labels Removed: Conflicting Files
avatar chmst
chmst - comment - 27 Jun 2020

@HLeithner The packages are not available, I get a 404. Can you have a look there?


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

avatar HLeithner
HLeithner - comment - 28 Jun 2020

PR is too old and packages got deleted already I restarted drone to get new one

avatar zero-24
zero-24 - comment - 28 Jun 2020

I updated the branch this does not trigger drone to rebuild it?

avatar zero-24
zero-24 - comment - 9 Aug 2020

Branch has been updated and packages should been rebuild now.

avatar wilsonge
wilsonge - comment - 13 Aug 2020

yes and here we have the special case of the fist beeing a suffx so we need to take care of that too.

We're no longer a suffix in J4 - it's just extra class

avatar zero-24
zero-24 - comment - 13 Aug 2020

I can not follow you? So do you want me to do changes here or is this good to go?

avatar zero-24
zero-24 - comment - 25 Aug 2020

Any follow up here @wilsonge so we can move this PR forward to be shipped?

avatar karo3 karo3 - test_item - 17 Oct 2020 - Tested unsuccessfully
avatar karo3
karo3 - comment - 17 Oct 2020

I have tested this item ? unsuccessfully on 21c4b5c

When saving modules you get the following error message:

An error has occurred.

0 Joomla\CMS\Form\Field\TextareaField::validate() rule CssIdentifier missing.


This comment was created with the J!Tracker Application at issues.joomla.org/tracker/joomla-cms/29108.
avatar zero-24
zero-24 - comment - 17 Oct 2020

0 Joomla\CMS\Form\Field\TextareaField::validate() rule CssIdentifier missing.

hmm can you confirm that the file is created after you applyed the changes or is it only issuing that error on the modules page?

avatar zero-24
zero-24 - comment - 17 Oct 2020

We're no longer a suffix in J4 - it's just extra class

Ah ok got the point I have now removed that special handling. So this is good to go.

avatar karo3 karo3 - test_item - 17 Oct 2020 - Tested successfully
avatar karo3
karo3 - comment - 17 Oct 2020

I have tested this item successfully on 1136c73

After another test using a special Joomla! update package, it now works as it should.


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

avatar degobbis degobbis - test_item - 17 Oct 2020 - Tested successfully
avatar degobbis
degobbis - comment - 17 Oct 2020

I have tested this item successfully on 1136c73

it works now as expected ?


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

avatar zero-24 zero-24 - change - 17 Oct 2020
The description was changed
avatar zero-24 zero-24 - change - 17 Oct 2020
Status Pending Ready to Commit
avatar zero-24 zero-24 - edited - 17 Oct 2020
avatar zero-24
zero-24 - comment - 17 Oct 2020

Thanks RTC.


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

avatar zero-24
zero-24 - comment - 17 Oct 2020

Thanks RTC.


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

avatar zero-24 zero-24 - change - 17 Oct 2020
The description was changed
avatar zero-24 zero-24 - edited - 17 Oct 2020
avatar zero-24 zero-24 - change - 17 Oct 2020
The description was changed
avatar zero-24 zero-24 - edited - 17 Oct 2020
avatar zero-24 zero-24 - change - 17 Oct 2020
The description was changed
avatar zero-24 zero-24 - edited - 17 Oct 2020
avatar zero-24 zero-24 - change - 17 Oct 2020
The description was changed
avatar zero-24 zero-24 - edited - 17 Oct 2020
avatar rdeutz rdeutz - change - 27 Oct 2020
Status Ready to Commit Fixed in Code Base
Closed_Date 0000-00-00 00:00:00 2020-10-27 12:38:22
Closed_By rdeutz
Labels Added: ?
avatar rdeutz rdeutz - close - 27 Oct 2020
avatar rdeutz rdeutz - merge - 27 Oct 2020

Add a Comment

Login with GitHub to post a comment