Bug 1370630 - Untrusted submit event shouldn't trigger form submission; r=smaug
Differential Revision: https://phabricator.services.mozilla.com/D28070
This commit is contained in:
@@ -46,6 +46,7 @@
|
||||
#include "mozilla/dom/FormDataEvent.h"
|
||||
#include "mozilla/dom/SubmitEvent.h"
|
||||
#include "mozilla/Telemetry.h"
|
||||
#include "mozilla/StaticPrefs_dom.h"
|
||||
#include "mozilla/StaticPrefs_prompts.h"
|
||||
#include "nsIFormSubmitObserver.h"
|
||||
#include "nsIObserverService.h"
|
||||
@@ -505,9 +506,19 @@ void HTMLFormElement::UnbindFromTree(bool aNullParent) {
|
||||
ForgetCurrentSubmission();
|
||||
}
|
||||
|
||||
static bool CanSubmit(WidgetEvent& aEvent) {
|
||||
// According to the UI events spec section "Trusted events", we shouldn't
|
||||
// trigger UA default action with an untrusted event except click.
|
||||
// However, there are still some sites depending on sending untrusted event
|
||||
// to submit form, see Bug 1370630.
|
||||
return !StaticPrefs::dom_forms_submit_trusted_event_only() ||
|
||||
aEvent.IsTrusted();
|
||||
}
|
||||
|
||||
void HTMLFormElement::GetEventTargetParent(EventChainPreVisitor& aVisitor) {
|
||||
aVisitor.mWantsWillHandleEvent = true;
|
||||
if (aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this)) {
|
||||
if (aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this) &&
|
||||
CanSubmit(*aVisitor.mEvent)) {
|
||||
uint32_t msg = aVisitor.mEvent->mMessage;
|
||||
if (msg == eFormSubmit) {
|
||||
if (mGeneratingSubmit) {
|
||||
@@ -544,7 +555,8 @@ void HTMLFormElement::WillHandleEvent(EventChainPostVisitor& aVisitor) {
|
||||
}
|
||||
|
||||
nsresult HTMLFormElement::PostHandleEvent(EventChainPostVisitor& aVisitor) {
|
||||
if (aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this)) {
|
||||
if (aVisitor.mEvent->mOriginalTarget == static_cast<nsIContent*>(this) &&
|
||||
CanSubmit(*aVisitor.mEvent)) {
|
||||
EventMessage msg = aVisitor.mEvent->mMessage;
|
||||
if (msg == eFormSubmit) {
|
||||
// let the form know not to defer subsequent submissions
|
||||
|
||||
Reference in New Issue
Block a user