Problem/Motivation
Basic and composite elements are not rendered in the same way. If HTML markup is submitted to a Text Field, it's displayed as plain text. If HTML markup is submitted to a composite element, like Name, the HTML is rendered (<script> tags are still stripped, so this is not a XSS vulnerability). I noticed it specifically when a user a submitted an image in an image tag to a name field.
Steps to reproduce
- Start from a fresh Drupal 9.5 install
- Install the webform module (version 6.1.5)
- Create a webform
- Add a Text Field to the webform
- Add a Name Field to the webform (simplest case: only have first name visible, but it doesn't matter)
- Create a submission to the webform with the value
<img src="https://dummyimage.com/100x100/000/fff">entered for both the Text Field and the Name Field - View the new submission and see that the image is rendered in the Name Field but displayed as plain text in the Text Field.
Proposed resolution
Attached is a patch file with my proposed solution. I replaced #markup with #plain_text to match how values are rendered for Basic Elements (line 1652 in WebformElementBase.php). This makes their behavior consistent and prevents users submitting images when they aren't expected to.
Remaining tasks
There may be functionality in compositive elements that rely on using #markup that I'm not aware of. For myself, none of the composite elements: Address, Contact, Custom, Link, Location, Name, Telephone advanced were used with the expectation of HTML, so it works well enough.
| Comment | File | Size | Author |
|---|---|---|---|
| #8 | After-patch.png | 45.87 KB | kasliwal_harshit |
| #8 | Before-patch.png | 39.58 KB | kasliwal_harshit |
| #6 | webform.webform.issue_3369135.yml | 5.18 KB | jrockowitz |
| #6 | 3369135-6.patch | 1.63 KB | jrockowitz |
| #3 | webform_composite_field.patch | 481 bytes | billodeau |
Comments
Comment #2
billodeau commentedComment #3
billodeau commentedComment #5
cilefen commentedThis looks like a bug report to me.
Comment #6
jrockowitz commentedThe attached webform replicates the issue and the attached patch fixes it.
Comment #7
kasliwal_harshit commentedReviewed This Issue , The given patch (#6 / 3369135-6.patch) is getting applied Successfully now user can only submit the text values in both name and text field . Attaching the screenshot for the same.
We can move this to RTBC+1, Thanks.
Comment #8
kasliwal_harshit commentedComment #9
jrockowitz commentedComment #10
jrockowitz commented