WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED FIXED
207427
Expose "allowsContentJavaScript" on WKWebpagePreferences
https://bugs.webkit.org/show_bug.cgi?id=207427
Summary
Expose "allowsContentJavaScript" on WKWebpagePreferences
Brady Eidson
Reported
2020-02-08 10:26:12 PST
Expose "allowsContentJavaScript" on WKWebpagePreferences This will allow content (ne "markup") JS to be disabled while still allowing script from API entry points. <
rdar://problem/51534967
>
Attachments
Patch
(25.87 KB, patch)
2020-02-08 10:31 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(25.94 KB, patch)
2020-02-08 13:09 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(26.05 KB, patch)
2020-02-08 13:53 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(29.52 KB, patch)
2020-02-08 17:56 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(31.60 KB, patch)
2020-02-08 21:36 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(35.86 KB, patch)
2020-02-10 22:42 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(39.69 KB, patch)
2020-02-13 10:49 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(39.68 KB, patch)
2020-02-13 11:46 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(41.03 KB, patch)
2020-02-13 22:50 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(40.85 KB, patch)
2020-02-14 07:53 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(40.82 KB, patch)
2020-02-14 10:23 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Patch
(41.95 KB, patch)
2020-02-14 22:37 PST
,
Brady Eidson
no flags
Details
Formatted Diff
Diff
Show Obsolete
(11)
View All
Add attachment
proposed patch, testcase, etc.
Brady Eidson
Comment 1
2020-02-08 10:31:13 PST
Created
attachment 390173
[details]
Patch
Brady Eidson
Comment 2
2020-02-08 13:09:19 PST
Created
attachment 390178
[details]
Patch
Brady Eidson
Comment 3
2020-02-08 13:53:57 PST
Created
attachment 390181
[details]
Patch
Sam Weinig
Comment 4
2020-02-08 15:19:14 PST
Comment on
attachment 390181
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=390181&action=review
> Source/WebCore/loader/DocumentLoader.h:650 > + Optional<bool> m_allowsScriptMarkup;
I find Optional<bool> to be hard to reason about and not all that self documenting. In other cases I have been recommending a three state enum instead.
Brady Eidson
Comment 5
2020-02-08 17:56:21 PST
Created
attachment 390191
[details]
Patch
Brady Eidson
Comment 6
2020-02-08 17:57:31 PST
(In reply to Sam Weinig from
comment #4
)
> Comment on
attachment 390181
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=390181&action=review
> > > Source/WebCore/loader/DocumentLoader.h:650 > > + Optional<bool> m_allowsScriptMarkup; > > I find Optional<bool> to be hard to reason about and not all that self > documenting. In other cases I have been recommending a three state enum > instead.
Fair enough.
Brady Eidson
Comment 7
2020-02-08 21:36:31 PST
Created
attachment 390195
[details]
Patch
Darin Adler
Comment 8
2020-02-09 21:17:55 PST
Comment on
attachment 390195
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=390195&action=review
Looks generally good. I have some questions so I didn’t review+ or review-.
> Source/WebCore/loader/DocumentLoader.cpp:1227 > + if (m_scriptMarkupPolicy != ScriptMarkupPolicy::Default) > + m_frame->settings().setScriptMarkupEnabled(m_scriptMarkupPolicy == ScriptMarkupPolicy::Enable);
I’m concerned that applyPoliciesToSettings is not a maintainable approach long term. Things that are different-per-document-loader probably should not be stored in settings that hang off the frame. Separate thought: The behavior of ScriptMarkupPolicy::Default seems to be "leave the settings behind from the previous document"? Is that safe?
> Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm:347 > + switch (_websitePolicies->scriptMarkupPolicy()) { > + case WebCore::ScriptMarkupPolicy::Default: > + case WebCore::ScriptMarkupPolicy::Enable: > + return true; > + case WebCore::ScriptMarkupPolicy::Disable: > + return false; > + }
If you never set this property, the markup policy is different from either NO or YES. But we do not document this difference. Nor offer a way to restore this behavior. I guess this third policy means "respect a preference with no API but that might be set on the command line"?
Brady Eidson
Comment 9
2020-02-09 22:01:14 PST
(In reply to Darin Adler from
comment #8
)
> Comment on
attachment 390195
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=390195&action=review
> > Looks generally good. I have some questions so I didn’t review+ or review-. > > > Source/WebCore/loader/DocumentLoader.cpp:1227 > > + if (m_scriptMarkupPolicy != ScriptMarkupPolicy::Default) > > + m_frame->settings().setScriptMarkupEnabled(m_scriptMarkupPolicy == ScriptMarkupPolicy::Enable); > > I’m concerned that applyPoliciesToSettings is not a maintainable approach > long term. Things that are different-per-document-loader probably should not > be stored in settings that hang off the frame.
In this case, "any document loader in the page getting this" should apply to the page global settings. I 100% agree that this approach doesn't seem as general purpose as as some of the other users of it!
> Separate thought: The behavior of ScriptMarkupPolicy::Default seems to be > "leave the settings behind from the previous document"? Is that safe?
The *intention* was "If WKPreferencesRef or WKBrowsingContextGroup users had set the markup-enabled flag, and nobody set it on the WKWebsitePreferences, respect the SPI setting" But in those cases, you are 100% correct that this is what happens in effect. The SPI override really gets in the way here. I'll either determine the SPI support is no longer needed and greatly simplify this code, or I'll adjust to handle it.
> > Source/WebKit/UIProcess/API/Cocoa/WKWebpagePreferences.mm:347 > > + switch (_websitePolicies->scriptMarkupPolicy()) { > > + case WebCore::ScriptMarkupPolicy::Default: > > + case WebCore::ScriptMarkupPolicy::Enable: > > + return true; > > + case WebCore::ScriptMarkupPolicy::Disable: > > + return false; > > + } > > If you never set this property, the markup policy is different from either > NO or YES. But we do not document this difference. Nor offer a way to > restore this behavior. I guess this third policy means "respect a preference > with no API but that might be set on the command line"?
Indeed - this trinary state came about because of a conflict with the SPI code paths to this setting. As mentioned above, I'll figure out the way forward.
Brady Eidson
Comment 10
2020-02-09 22:06:13 PST
Well it's actually SPI on WKWebViewConfiguration, so that's potentially much more problematic.
Brady Eidson
Comment 11
2020-02-09 22:11:42 PST
Yup, definitely still have to support that SPI. The "dangerous" thing is accidentally allowing markup JS when somebody has asked the view to not allow it. I can do that with Settings + FrameLoaderClient instead of this ternary state.
Brady Eidson
Comment 12
2020-02-10 22:42:34 PST
Created
attachment 390346
[details]
Patch
Brady Eidson
Comment 13
2020-02-10 22:48:10 PST
(In reply to Brady Eidson from
comment #9
)
> (In reply to Darin Adler from
comment #8
> > In this case, "any document loader in the page getting this" should apply to > the page global settings.
This got me thinking as to my approach, which is now to put the "did this navigation have the markup disabled policy?" flag on the Page itself, living side-by-side with the WKPreferences-driven Settings version. Then we consult both at decision time.
Brady Eidson
Comment 14
2020-02-13 10:49:47 PST
Created
attachment 390669
[details]
Patch
Brady Eidson
Comment 15
2020-02-13 11:46:45 PST
Created
attachment 390673
[details]
Patch
Brady Eidson
Comment 16
2020-02-13 22:07:58 PST
Ouch. The key with these layout test failures is: bool Document::scriptMarkupEnabled() const { if (!settings().scriptMarkupEnabled()) return false; if (!m_frame || m_frame->document() != this) return false; return m_frame->loader().client().scriptMarkupPolicyFromMostRecentNavigation() == ScriptMarkupPolicy::Enable; } The middle clause of no frame. I'd figured "A frameless document should never be executing script, right?" But I was totally wrong. So now I have to find a (good) way to propagate the policy forward to frameless documents from whoever creates them.
Brady Eidson
Comment 17
2020-02-13 22:50:59 PST
Created
attachment 390731
[details]
Patch Trying this approach on the bots (fixed at least some tests locally)
Brady Eidson
Comment 18
2020-02-14 07:53:33 PST
Created
attachment 390768
[details]
Patch Trying this approach on the bots (fixed more tests locally)
Brady Eidson
Comment 19
2020-02-14 10:23:15 PST
Created
attachment 390784
[details]
Patch
Darin Adler
Comment 20
2020-02-14 15:16:04 PST
Comment on
attachment 390784
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=390784&action=review
I like the public allowsContentJavaScript name so much better than the internal scriptMarkupPolicy name.
> Source/WebCore/dom/Document.cpp:6817 > + if (!settings().scriptMarkupEnabled())
Seems slightly dangerous to still have this Settings::scriptMarkupEnabled function. If anyone calls it and it returns true, they will likely do the wrong thing. Maybe at some point we can rename it?
> Source/WebCore/dom/Document.cpp:6826 > + if (m_contextDocument) > + return m_contextDocument->scriptMarkupEnabled(); > + > + // If this Document is frameless or in the wrong frame, *and* it has no context document, > + // then it has no business running markup script. > + return false;
I’d find this slightly easier to read as an && expression: return m_contextDocument && m_contextDocument->scriptMarkupEnabled(); Also slightly annoying that there’s recursion here, but I suppose it’s unlikely to recurse deeply.
> Source/WebCore/xml/XMLHttpRequest.cpp:194 > m_responseDocument->setContextDocument(context); > + m_responseDocument->setContent(m_responseBuilder.toStringPreserveCapacity()); > m_responseDocument->setSecurityOriginPolicy(context.securityOriginPolicy()); > m_responseDocument->overrideMIMEType(mimeType);
Maybe we should also move up the setSecurityOriginPolicy and overrideMIMEType calls up before we call setContent too? Seems like we’d want all those things set before we do any parsing.
> Source/WebKit/WebProcess/WebPage/WebFrame.cpp:269 > + ASSERT(page());
What guarantees page() is not null?
Brady Eidson
Comment 21
2020-02-14 18:27:44 PST
(In reply to Darin Adler from
comment #20
)
> Comment on
attachment 390784
[details]
> Patch > > View in context: >
https://bugs.webkit.org/attachment.cgi?id=390784&action=review
> > I like the public allowsContentJavaScript name so much better than the > internal scriptMarkupPolicy name.
Me too. It was originally the tri-state enum Sam requested and this "FooPolicy" name was matching other tri-state style. I'll rename.
> > > Source/WebCore/dom/Document.cpp:6817 > > + if (!settings().scriptMarkupEnabled()) > > Seems slightly dangerous to still have this Settings::scriptMarkupEnabled > function. If anyone calls it and it returns true, they will likely do the > wrong thing. Maybe at some point we can rename it?
I agree! Unfortunately it is exposed as (multiple) SPIs that are still used. Renaming it to something that discourages its use seems great.
> > Source/WebCore/dom/Document.cpp:6826 > > + if (m_contextDocument) > > + return m_contextDocument->scriptMarkupEnabled(); > > + > > + // If this Document is frameless or in the wrong frame, *and* it has no context document, > > + // then it has no business running markup script. > > + return false; > > I’d find this slightly easier to read as an && expression: > > return m_contextDocument && m_contextDocument->scriptMarkupEnabled(); > > Also slightly annoying that there’s recursion here, but I suppose it’s > unlikely to recurse deeply. > > > Source/WebCore/xml/XMLHttpRequest.cpp:194 > > m_responseDocument->setContextDocument(context); > > + m_responseDocument->setContent(m_responseBuilder.toStringPreserveCapacity()); > > m_responseDocument->setSecurityOriginPolicy(context.securityOriginPolicy()); > > m_responseDocument->overrideMIMEType(mimeType); > > Maybe we should also move up the setSecurityOriginPolicy and > overrideMIMEType calls up before we call setContent too? Seems like we’d > want all those things set before we do any parsing.
Sounds right!
> > > Source/WebKit/WebProcess/WebPage/WebFrame.cpp:269 > > + ASSERT(page()); > > What guarantees page() is not null?
The coreFrame null check earlier almost always guarantees this. It's not a 100% guarantee, I'll clean it up.
Brady Eidson
Comment 22
2020-02-14 22:37:48 PST
Created
attachment 390855
[details]
Patch
Brady Eidson
Comment 23
2020-02-15 08:08:37 PST
(In reply to Brady Eidson from
comment #22
)
> Created
attachment 390855
[details]
> Patch
This will be for landing later: Some clients need to handle the deprecation first
WebKit Commit Bot
Comment 24
2020-02-16 17:35:23 PST
Comment on
attachment 390855
[details]
Patch Clearing flags on attachment: 390855 Committed
r256715
: <
https://trac.webkit.org/changeset/256715
>
WebKit Commit Bot
Comment 25
2020-02-16 17:35:25 PST
All reviewed patches have been landed. Closing bug.
Radar WebKit Bug Importer
Comment 26
2020-02-16 17:36:19 PST
<
rdar://problem/59498009
>
Alex Christensen
Comment 27
2020-02-17 11:39:17 PST
Comment on
attachment 390855
[details]
Patch View in context:
https://bugs.webkit.org/attachment.cgi?id=390855&action=review
> Tools/TestWebKitAPI/Tests/WebKitCocoa/WKWebViewEvaluateJavaScript.mm:261 > +TEST(WebKit, AllowsContentJavaScript)
This needs #if HAVE(NETWORK_FRAMEWORK)
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug