-
-
Notifications
You must be signed in to change notification settings - Fork 530
[3.x] Restrict tag usage and ensure proper escaping of element name, caption, and description fields #15936
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: 3.x
Are you sure you want to change the base?
Conversation
(Just to make this reference to this PR easier to get to, the above is from @Mark-H re this PR.) One quick question on the matter of XSS, and this is just to get a better understanding: Is it because of the context of these input forms being only accessible via a backend interface that XSS would not be applicable? Regardless, it seems I should consider opening it up a bit in the following ways:
|
|
Disallowing script tags is not enough. Each element can have several |
|
@Jako - Yes, it goes without saying that virtually all attributes should be discarded, especially event-based ones. ;-) |
|
MODx.util.safeHtml does this and should be quite safe. |
|
OK all, I've made several updates in the latest commit to address the concerns raised above, as well as to make the processing more complete (on the php side) and flexible by making the tag and attribute restrictions customizable via new system settings. |
027c21d to
fadf49e
Compare
fadf49e to
754a6c7
Compare
754a6c7 to
bcd2f11
Compare
Codecov ReportAttention:
Additional details and impacted files@@ Coverage Diff @@
## 3.x #15936 +/- ##
============================================
+ Coverage 17.95% 18.03% +0.08%
- Complexity 10442 10468 +26
============================================
Files 561 561
Lines 39051 39161 +110
============================================
+ Hits 7010 7062 +52
- Misses 32041 32099 +58 ☔ View full report in Codecov by Sentry. |
|
I'm kinda worried this will impact existing sites and we'll get a bunch of issues reported that users suddenly can't use whatever fancy captions and descriptions they've used in the past, but as long as the safeHtml gets covered by sufficient tests and these new restrictions get added to the documentation I don't see a technical reason to reject it. |
c6812e4 to
32106a6
Compare
|
@Mark-H @Jako @JoshuaLuckers - This is finally ready for re-review. I came back and added some tests and made a few tweaks. Not too long after Mark commented re concerns of being too limiting on caption/desc formatting, I loosened the restrictions I'd initially set up and made them fully user-customizable. |
|
@smg6511 I'm no longer involved with this project and therefore unable to review your work. I'm sorry. |
|
@JoshuaLuckers Hey - thanks for the heads up! Would you be interested in connecting on LinkedIn? I'll send you an invite if so. Don't know if there will be reason for our paths to cross again, but ya never know ;-) |
Feel free to connect: https://www.linkedin.com/in/joshualuckers/ |
Prevents saving of tags in fields that will be displayed in the interface (name, caption, description)
Cleans name, caption, and description fields on the front end (js) side before they are submitted to processors.
Allow tags and attributes as defined in new system settings. Also, created a new stripHtml method on the php side to coordinate the rules when javascript is not applicable (e.g., when elements are created or updated programmatically).
Co-authored-by: Joshua Lückers <[email protected]>
Change made by request for better maintainability.
Remove stray log stmt
Fine-tuning for additional flexibility with data attributes and scripts
Added unit test cases for new stripHTML method
7e700fd to
3f252b8
Compare
What does it do?
Strips tags and html encodes the name, caption/label, and description fields for elements—both in the back end (processors) and front end (js forms, grids, and windows). Made separate commits for processors and js in case that makes testing easier.
Why is it needed?
There should be more appropriate limitations on HTML tag usage within certain fields. The initial submission of this PR is highly restrictive, which I realize may need to be loosened depending on reviewer feedback.
How to test
grunt buildfrom within the_build/templates/defaultfolder and clear your browser cache.elements_caption_allowedtags,elements_caption_allowedattr,elements_description_allowedtags, andelements_description_allowedattr).Related issue(s)/PR(s)
Resolves #15925