Skip to content

Allow tainted scripts to extract text from some fields#52705

Merged
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
sysrqb:eng/Allow-tainted-scripts-to-extract-text-from-some-fields
Oct 23, 2025
Merged

Allow tainted scripts to extract text from some fields#52705
webkit-commit-queue merged 1 commit intoWebKit:mainfrom
sysrqb:eng/Allow-tainted-scripts-to-extract-text-from-some-fields

Conversation

@sysrqb
Copy link
Contributor

@sysrqb sysrqb commented Oct 21, 2025

614b6dc

Allow tainted scripts to extract text from some fields
https://bugs.webkit.org/show_bug.cgi?id=301157
rdar://161669359

Reviewed by Wenson Hsieh.

The form control protection prevents tainted scripts from accessing the value
of all text form fields. That protection causes some web compatibility issues
that we can fix by slightly relaxing the restriction which is what I'm doing in
this patch. We can let tainted scripts extract the value if that element was
created by a tainted script and it wasn't modified by user input.

Test: Tools/TestWebKitAPI/Tests/WebKitCocoa/ScriptTrackingPrivacyTests.mm

* Source/WebCore/html/HTMLFormControlElement.cpp:
(WebCore::m_wasCreatedByTaintedScript):
(WebCore::m_wasChangedSinceLastFormControlChangeEvent): Deleted.
* Source/WebCore/html/HTMLFormControlElement.h:
(WebCore::HTMLFormControlElement::wasCreatedByTaintedScript const):
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::value const):
* Source/WebCore/html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::value const):
* Source/WebCore/html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::didEditInnerTextValue):
(WebCore::HTMLTextFormControlElement::wasChangeEverUserEdit const):
(WebCore::HTMLTextFormControlElement::shouldApplyScriptTrackingPrivacyProtection const):
* Source/WebCore/html/HTMLTextFormControlElement.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ScriptTrackingPrivacyTests.mm:
(TestWebKitAPI::(ScriptTrackingPrivacyTests, DirectFormFieldAccess)):

Canonical link: https://commits.webkit.org/302031@main

ec2e341

Misc iOS, visionOS, tvOS & watchOS macOS Linux Windows Apple Internal
✅ 🧪 style ✅ 🛠 ios ✅ 🛠 mac ✅ 🛠 wpe ✅ 🛠 win ⏳ 🛠 ios-apple
✅ 🧪 bindings ✅ 🛠 ios-sim ✅ 🛠 mac-AS-debug ✅ 🧪 wpe-wk2 ❌ 🧪 win-tests ⏳ 🛠 mac-apple
✅ 🧪 webkitperl ✅ 🧪 ios-wk2 ✅ 🧪 api-mac ✅ 🧪 api-wpe ✅ 🛠 vision-apple
✅ 🧪 ios-wk2-wpt ✅ 🧪 mac-wk1 ✅ 🛠 wpe-cairo
✅ 🧪 api-ios ✅ 🧪 mac-wk2 ✅ 🛠 gtk
✅ 🛠 vision ✅ 🧪 mac-AS-debug-wk2 ✅ 🧪 gtk-wk2
✅ 🛠 vision-sim ✅ 🧪 mac-wk2-stress ✅ 🧪 api-gtk
✅ 🛠 🧪 merge ✅ 🧪 vision-wk2 ✅ 🧪 mac-intel-wk2 ✅ 🛠 playstation
✅ 🛠 tv ✅ 🛠 mac-safer-cpp ⏳ 🛠 jsc-armv7
✅ 🛠 tv-sim ⏳ 🧪 jsc-armv7-tests
✅ 🛠 watch
✅ 🛠 watch-sim

@sysrqb sysrqb self-assigned this Oct 21, 2025
@sysrqb sysrqb added the Forms For bugs specific to form elements (checkboxes, buttons, text fields, etc.) label Oct 21, 2025
@webkit-ews-buildbot webkit-ews-buildbot added the merging-blocked Applied to prevent a change from being merged label Oct 21, 2025
@sysrqb sysrqb removed the merging-blocked Applied to prevent a change from being merged label Oct 21, 2025
@sysrqb sysrqb force-pushed the eng/Allow-tainted-scripts-to-extract-text-from-some-fields branch from 25aae35 to 0ecd3e6 Compare October 21, 2025 18:54
@sysrqb sysrqb requested a review from whsieh October 21, 2025 18:55
@sysrqb sysrqb marked this pull request as ready for review October 21, 2025 18:55
@sysrqb sysrqb requested review from cdumez and rniwa as code owners October 21, 2025 18:55
@@ -155,6 +155,7 @@ void HTMLTextFormControlElement::didEditInnerTextValue(bool wasUserEdit)
LOG(Editing, "HTMLTextFormControlElement %p didEditInnerTextValue", this);

m_lastChangeWasUserEdit = wasUserEdit;
m_wasChangeEverUserEdit |= wasUserEdit;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
m_wasChangeEverUserEdit |= wasUserEdit;
m_wasEverChangedByUserEdit |= wasUserEdit;

Maybe m_wasEverChangedByUserEdit or m_wasEverUserEdited might read a bit more nicely?

Comment on lines +960 to +961
return protectedDocument()->requiresScriptTrackingPrivacyProtection(ScriptTrackingPrivacyCategory::FormControls)
&& (wasChangeEverUserEdit() || !wasCreatedByTaintedScript());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if you make this (wasChangeEverUserEdit() || !wasCreatedByTaintedScript()) && …, we might be able to avoid the (potentially more expensive) script tracking privacy check.

@@ -66,6 +66,7 @@ HTMLFormControlElement::HTMLFormControlElement(const QualifiedName& tagName, Doc
, m_isRequired(false)
, m_valueMatchesRenderer(false)
, m_wasChangedSinceLastFormControlChangeEvent(false)
, m_wasCreatedByTaintedScript(document.requiresScriptTrackingPrivacyProtection(ScriptTrackingPrivacyCategory::FormControls))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Might be worth adding a new argument flag to requiresScriptTrackingPrivacyProtection, which would prevent us from adding a console log message in the case where it's tainted (or perhaps, a different message, that would make it clear that returning true here doesn't, by itself, block form access).

@sysrqb sysrqb force-pushed the eng/Allow-tainted-scripts-to-extract-text-from-some-fields branch from 0ecd3e6 to ec2e341 Compare October 23, 2025 06:08
@sysrqb sysrqb added the merge-queue Applied to send a pull request to merge-queue label Oct 23, 2025
https://bugs.webkit.org/show_bug.cgi?id=301157
rdar://161669359

Reviewed by Wenson Hsieh.

The form control protection prevents tainted scripts from accessing the value
of all text form fields. That protection causes some web compatibility issues
that we can fix by slightly relaxing the restriction which is what I'm doing in
this patch. We can let tainted scripts extract the value if that element was
created by a tainted script and it wasn't modified by user input.

Test: Tools/TestWebKitAPI/Tests/WebKitCocoa/ScriptTrackingPrivacyTests.mm

* Source/WebCore/html/HTMLFormControlElement.cpp:
(WebCore::m_wasCreatedByTaintedScript):
(WebCore::m_wasChangedSinceLastFormControlChangeEvent): Deleted.
* Source/WebCore/html/HTMLFormControlElement.h:
(WebCore::HTMLFormControlElement::wasCreatedByTaintedScript const):
* Source/WebCore/html/HTMLInputElement.cpp:
(WebCore::HTMLInputElement::value const):
* Source/WebCore/html/HTMLTextAreaElement.cpp:
(WebCore::HTMLTextAreaElement::value const):
* Source/WebCore/html/HTMLTextFormControlElement.cpp:
(WebCore::HTMLTextFormControlElement::didEditInnerTextValue):
(WebCore::HTMLTextFormControlElement::wasChangeEverUserEdit const):
(WebCore::HTMLTextFormControlElement::shouldApplyScriptTrackingPrivacyProtection const):
* Source/WebCore/html/HTMLTextFormControlElement.h:
* Tools/TestWebKitAPI/Tests/WebKitCocoa/ScriptTrackingPrivacyTests.mm:
(TestWebKitAPI::(ScriptTrackingPrivacyTests, DirectFormFieldAccess)):

Canonical link: https://commits.webkit.org/302031@main
@webkit-commit-queue webkit-commit-queue force-pushed the eng/Allow-tainted-scripts-to-extract-text-from-some-fields branch from ec2e341 to 614b6dc Compare October 23, 2025 14:59
@webkit-commit-queue
Copy link
Collaborator

Committed 302031@main (614b6dc): https://commits.webkit.org/302031@main

Reviewed commits have been landed. Closing PR #52705 and removing active labels.

@webkit-commit-queue webkit-commit-queue merged commit 614b6dc into WebKit:main Oct 23, 2025
@webkit-commit-queue webkit-commit-queue removed the merge-queue Applied to send a pull request to merge-queue label Oct 23, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Forms For bugs specific to form elements (checkboxes, buttons, text fields, etc.)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants