Changeset 284660 in webkit


Ignore:
Timestamp:
Oct 21, 2021 5:46:04 PM (9 months ago)
Author:
Chris Dumez
Message:

Form submission should be cancelled if the form gets detached from inside the formdata event handler
https://bugs.webkit.org/show_bug.cgi?id=232114

Reviewed by Alex Christensen.

Source/WebCore:

Per the HTML specification [1], form submission should abort if the form cannot navigate (which is true
when the form is detached). The algorithm in the specification does the check twice, once at the very
beginning (Step 1 in the spec), and again after calling the "constructing the entry list" algorithm
(step 9 in the spec). The reason we need to do the check again is that the "constructing the entry list"
algorithm fires the "formdata" event and may thus run JavaScript and the JS can detach the form element.

In HTMLFormElement::submit(), we were doing only the "form is connected" check only at the beginning
of the function and failing to do so after constructing the FormSubmission object (which ends up constructing
the entry list). This patch fixes that.

[1] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit

Test: fast/forms/remove-form-inside-formdata-event.html

  • html/HTMLFormElement.cpp:

(WebCore::HTMLFormElement::submit):

LayoutTests:

Add layout test coverage.

  • fast/forms/remove-form-inside-formdata-event-expected.txt: Added.
  • fast/forms/remove-form-inside-formdata-event.html: Added.
Location:
trunk
Files:
2 added
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r284659 r284660  
     12021-10-21  Chris Dumez  <cdumez@apple.com>
     2
     3        Form submission should be cancelled if the form gets detached from inside the formdata event handler
     4        https://bugs.webkit.org/show_bug.cgi?id=232114
     5
     6        Reviewed by Alex Christensen.
     7
     8        Add layout test coverage.
     9
     10        * fast/forms/remove-form-inside-formdata-event-expected.txt: Added.
     11        * fast/forms/remove-form-inside-formdata-event.html: Added.
     12
    1132021-10-21  Eric Hutchison  <ehutchison@apple.com>
    214
  • trunk/Source/WebCore/ChangeLog

    r284656 r284660  
     12021-10-21  Chris Dumez  <cdumez@apple.com>
     2
     3        Form submission should be cancelled if the form gets detached from inside the formdata event handler
     4        https://bugs.webkit.org/show_bug.cgi?id=232114
     5
     6        Reviewed by Alex Christensen.
     7
     8        Per the HTML specification [1], form submission should abort if the form cannot navigate (which is true
     9        when the form is detached). The algorithm in the specification does the check twice, once at the very
     10        beginning (Step 1 in the spec), and again after calling the "constructing the entry list" algorithm
     11        (step 9 in the spec). The reason we need to do the check again is that the "constructing the entry list"
     12        algorithm fires the "formdata" event and may thus run JavaScript and the JS can detach the form element.
     13
     14        In HTMLFormElement::submit(), we were doing only the "form is connected" check only at the beginning
     15        of the function and failing to do so after constructing the FormSubmission object (which ends up constructing
     16        the entry list). This patch fixes that.
     17
     18        [1] https://html.spec.whatwg.org/multipage/form-control-infrastructure.html#concept-form-submit
     19
     20        Test: fast/forms/remove-form-inside-formdata-event.html
     21
     22        * html/HTMLFormElement.cpp:
     23        (WebCore::HTMLFormElement::submit):
     24
    1252021-10-21  Chris Dumez  <cdumez@apple.com>
    226
  • trunk/Source/WebCore/html/HTMLFormElement.cpp

    r284656 r284660  
    403403    auto shouldLockHistory = processingUserGesture ? LockHistory::No : LockHistory::Yes;
    404404    auto formSubmission = FormSubmission::create(*this, submitter, m_attributes, event, shouldLockHistory, trigger);
     405
     406    if (!isConnected())
     407        return;
     408
    405409    if (m_plannedFormSubmission)
    406410        m_plannedFormSubmission->cancel();
Note: See TracChangeset for help on using the changeset viewer.