Background information

This was originally reported as a private security issue, but has been approved for handling in the public queue by the Drupal Security Team.

Problem/Motivation

The resetForm() method provided by jquery-form is vulnerable to XSS if it is used on a label element and an attacker can control the value of the for attribute of this element.

It passes the value of this attribute to $() without making sure it does not contain HTML:

			case 'label':
				var forEl = $(el.attr('for'));

Steps to reproduce

{{ attach_library('core/internal.jquery.form') }}
<label id="label" for="&lt;img src=x onerror=alert()&gt;">Label</label>
<script>
  window.addEventListener('load', function() {
    jQuery('#label').resetForm();
  });
</script>

Proposed resolution

Drupal never uses resetForm() and the library is internal (#3293156: core/jquery.form library deprecated) so it should not be used by contrib.
The solution could be to remove resetForm() entirely since we don't use it.

Remaining tasks

User interface changes

Introduced terminology

API changes

Data model changes

Release notes snippet

Issue fork drupal-3607794

Command icon Show commands

Start within a Git clone of the project using the version control instructions.

Or, if you do not have SSH keys set up on git.drupalcode.org:

Comments

prudloff created an issue. See original summary.

prudloff’s picture

Status: Active » Needs review

Do we need a CR if the library is marked as internal?

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

I don't think so. As you mentioned no contrib should be using it, if they are I'd assume they know they are taking the risk.

catch’s picture

Status: Reviewed & tested by the community » Needs review
Issue tags: +Needs change record

In this case I think we do need a change record - while the entire library is internal, it's loaded on every form so the method is available to use, and we'll want to backport this to patch releases probably.

smustgrave’s picture

Status: Needs review » Needs work

For the CR

prudloff’s picture

Status: Needs work » Needs review
Issue tags: -Needs change record

I drafted a CR.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

I edited the CR a little. I wanted to say explicitly that there is no replacement. Also, the 2022 CR about the library being internal suggested copying the Core library in case it becomes unavailable someday. So I wanted to stress that people should not do that with this function. Otherwise it looks good.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new98 bytes

The Needs Review Queue Bot tested this issue. The merge request has merge conflicts and cannot be merged. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

prudloff’s picture

Status: Needs work » Needs review

I fixed the conflicts.

dcam’s picture

Status: Needs review » Reviewed & tested by the community

The rebase looks good.

needs-review-queue-bot’s picture

Status: Reviewed & tested by the community » Needs work
StatusFileSize
new91 bytes

The Needs Review Queue Bot tested this issue. It no longer applies to Drupal core. Therefore, this issue status is now "Needs work".

This does not mean that the patch necessarily needs to be re-rolled or the MR rebased. Read the Issue Summary, the issue tags and the latest discussion here to determine what needs to be done.

Consult the Drupal Contributor Guide to find step-by-step guides for working with issues.

brandonlira made their first commit to this issue’s fork.

brandonlira’s picture

Status: Needs work » Needs review

Rebased the MR against the latest main and resolved the conflict in OpenTelemetryPerformanceTest.php.

Kept the current main ScriptCount value and the reduced ScriptBytes value expected after removing resetForm().

smustgrave’s picture

Status: Needs review » Reviewed & tested by the community

Restoring status from #11

  • godotislate committed bbe11d6d on main
    fix: #3607794 Potential XSS in jquery.form.js
    
    By: prudloff
    By: catch
    By...
godotislate’s picture

Version: main » 11.x-dev
Status: Reviewed & tested by the community » Patch (to be ported)

Committed bbe11d6 and pushed to main. Thanks!

There's a merge conflict in the numbers for the performance test, so that'll need a separate MR for 11.x. @catch also mentioned possibly backporting to a patch release in #5, so I'll confirm that we want this for 11.4.x

brandonlira’s picture

Opened a separate MR !16653 for the 11.x port.

Ports bbe11d6d93e to 11.x and resolves the OpenTelemetryPerformanceTest.php conflict by keeping the 11.x ScriptCount and StylesheetBytes values, while reducing ScriptBytes by the same amount as the main commit.

Please let me know if anything else is needed.

Thanks!

dcam’s picture

Status: Patch (to be ported) » Reviewed & tested by the community

The only difference between the two MRs is the ScriptBytes in the performance test. Otherwise, the 11.x MR is identical to the one that went into main.

  • godotislate committed aa558c80 on 11.x
    fix: #3607794 Potential XSS in jquery.form.js
    
    By: prudloff
    By: catch
    By...
godotislate’s picture

Status: Reviewed & tested by the community » Fixed

Committed aa558c8 and pushed to 11.x. Thanks!

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

quietone’s picture

Updated and published the change record.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.