<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://bugs.webkit.org/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4.1"
          urlbase="https://bugs.webkit.org/"
          
          maintainer="admin@webkit.org"
>

    <bug>
          <bug_id>219632</bug_id>
          
          <creation_ts>2020-12-08 01:52:29 -0800</creation_ts>
          <short_desc>REGRESSION(r261238): WKWebView crashes on launch inside a quicklook preview</short_desc>
          <delta_ts>2021-01-27 11:33:48 -0800</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WebKit</product>
          <component>WebKit2</component>
          <version>Safari 14</version>
          <rep_platform>Mac</rep_platform>
          <op_sys>Other</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords>InRadar</keywords>
          <priority>P2</priority>
          <bug_severity>Critical</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter>sbarex</reporter>
          <assigned_to name="Brent Fulgham">bfulgham</assigned_to>
          <cc>ap</cc>
    
    <cc>bfulgham</cc>
    
    <cc>ggaren</cc>
    
    <cc>pvollan</cc>
    
    <cc>webkit-bug-importer</cc>
    
    <cc>webKit.bugzilla</cc>
          

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>1712713</commentid>
    <comment_count>0</comment_count>
    <who name="">sbarex</who>
    <bug_when>2020-12-08 01:52:29 -0800</bug_when>
    <thetext>I have a Quicklook appex that show the file contents by a WKWebView. The application and the extension are sandboxed. When try to use the quickllok preview I see only the spinning icon.
On XCode this is the log:

[Process] 0x7f8cbc029620 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::processDidTerminate: (pid 0), reason 3
[Loading] 0x7f8cbc029620 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::dispatchProcessDidTerminate: reason = 3
[Process] 0x7f8cbc029620 - [pageProxyID=5, webPageID=6, PID=0] WebPageProxy::tryReloadAfterProcessTermination: process crashed and the client did not handle it, not reloading the page because we reached the maximum number of attempts

Using the webkit source code I see this other output log:
com.apple.WebKit.Networking.Development[96084:1414561] Application does not have permission to communicate with network resources. rc=1 : errno=22

Che entitlements check fail on `XPCServiceInitializerDelegate::checkEntitlements` in XPCServiceEntryPoint.mm. If I hack this function returning true the preview works well.
I see that the function was changed on revision 261238 of the 2020-05-06 19:32. From this revision the `checkEntitlements` uses the SandboxSPI to check the entitlements with `sandbox_check_by_audit_token`. Before it uses `hasEntitlement` (that uses `SecTaskCopyValueForEntitlement` to perform the check).

Both the application and the extension contain the entitlement `com.apple.security.network.client`.

Please note that the application works on Catalina. 
If I use the deprecated WebView insted of WKWebView the preview works also on Big Sur.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713317</commentid>
    <comment_count>1</comment_count>
    <who name="Radar WebKit Bug Importer">webkit-bug-importer</who>
    <bug_when>2020-12-09 14:59:15 -0800</bug_when>
    <thetext>&lt;rdar://problem/72154830&gt;</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713338</commentid>
    <comment_count>2</comment_count>
    <who name="Geoffrey Garen">ggaren</who>
    <bug_when>2020-12-09 15:41:34 -0800</bug_when>
    <thetext>Seems like something about the quicklook preview setup does not carry the entitlement through the audit token.

I wonder if you can hack most of the code out of your project and turn it into a test app demonstrating this problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713352</commentid>
    <comment_count>3</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2020-12-09 16:17:38 -0800</bug_when>
    <thetext>&gt; Both the application and the extension contain the entitlement `com.apple.security.network.client`.

I don&apos;t think that it does anything for QuickLook extensions.

Can you try using a com.apple.security.temporary-exception.mach-lookup.global-name exception entitlement for com.apple.nsurlsessiond instead? That would be for diagnosis only, I&apos;m not suggesting to do this in production at this point.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713650</commentid>
    <comment_count>4</comment_count>
    <who name="">sbarex</who>
    <bug_when>2020-12-10 12:05:28 -0800</bug_when>
    <thetext>(In reply to Geoffrey Garen from comment #2)
&gt; Seems like something about the quicklook preview setup does not carry the
&gt; entitlement through the audit token.
&gt; 
&gt; I wonder if you can hack most of the code out of your project and turn it
&gt; into a test app demonstrating this problem.

Hi,
I have created a demo code here:
https://github.com/sbarex/QLTest

The quicklook appex handle files with extension .sbarex_test 
The PreviewController create a WKWebView and show a &quot;hello world&quot; message with loadHTMLString (so for this example do not shows the file contents).

The completion handler to show the ql preview is called when the html rendering is complete.

On Big Sur webkit fail immediately and the handle in never called (So the spinning icon rest visibile).

Inside the PreviewController.swift I have inserted but commented the code that use the old WebView. Using this code instead of the wkwebview the preview works.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713655</commentid>
    <comment_count>5</comment_count>
    <who name="">sbarex</who>
    <bug_when>2020-12-10 12:11:57 -0800</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #3)
&gt; &gt; Both the application and the extension contain the entitlement `com.apple.security.network.client`.
&gt; 
&gt; I don&apos;t think that it does anything for QuickLook extensions.
&gt; 
&gt; Can you try using a
&gt; com.apple.security.temporary-exception.mach-lookup.global-name exception
&gt; entitlement for com.apple.nsurlsessiond instead? That would be for diagnosis
&gt; only, I&apos;m not suggesting to do this in production at this point.

I do not understand which entitlement I must try to add...
com.apple.security.temporary-exception.mach-lookup.global-name does nothing for the bug.

If I add com.apple.nsurlsessiond I need to sign the app with a certificate. Then the appex fail to load and Xcode cannot bind to the process to debug (failure Reason: “org.sbarex.QLTest.QLExt” failed to launch or exited before the debugger could attach to it. Please verify that “org.sbarex.QLTest.QLExt” has a valid code signature that permits it to be launched on “My Mac”.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713686</commentid>
    <comment_count>6</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2020-12-10 13:02:31 -0800</bug_when>
    <thetext>Please see documentation for com.apple.security.temporary-exception.mach-lookup.global-name at https://developer.apple.com/library/archive/documentation/Miscellaneous/Reference/EntitlementKeyReference/Chapters/AppSandboxTemporaryExceptionEntitlements.html.

The idea is that WebContent process confirms that the UI process can look up the com.apple.nsurlsessiond name. For applications, com.apple.security.network.client includes that, but as far as I know, QuickLook extensions don&apos;t honor com.apple.security.network.client.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713723</commentid>
    <comment_count>7</comment_count>
    <who name="">sbarex</who>
    <bug_when>2020-12-10 14:34:41 -0800</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #6)
&gt; Please see documentation for
&gt; com.apple.security.temporary-exception.mach-lookup.global-name at
&gt; https://developer.apple.com/library/archive/documentation/Miscellaneous/
&gt; Reference/EntitlementKeyReference/Chapters/
&gt; AppSandboxTemporaryExceptionEntitlements.html.
&gt; 
&gt; The idea is that WebContent process confirms that the UI process can look up
&gt; the com.apple.nsurlsessiond name. For applications,
&gt; com.apple.security.network.client includes that, but as far as I know,
&gt; QuickLook extensions don&apos;t honor com.apple.security.network.client.

Thanks, now I understand.
By setting the entitlement com.apple.security.temporary-exception.mach-lookup.global-name as an array and inserting the value com.apple.nsurlsessiond  finally the extension works! Many thanks!

However with Catalina it was not necessary to insert an exception in the entitlements. I don&apos;t know if for a different management of the quicklook framework or for the different version of webkit.

From what I understand most of the formats supported by the system are rendered in quicklook via a webkit view (although apple still uses the deperecated qlgenerator api), so it seems strange to me that it does not allow its use in the new framework.

There is still one last bug but I&apos;m afraid it doesn&apos;t depend on webkit. When scroll bars appear, it is not possible to drag the scroller with the mouse because the action causes the entire window to be dragged (but you can scroll with trackpad gesture).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713741</commentid>
    <comment_count>8</comment_count>
    <who name="Alexey Proskuryakov">ap</who>
    <bug_when>2020-12-10 15:22:23 -0800</bug_when>
    <thetext>This was a WebKit change, you correctly identified it to be http://trac.webkit.org/r261238.

Thank you for testing! Just to reiterate, I&apos;m not saying that adding a temporary entitlement is a permanent or even recommended solution. We&apos;ll need to look into this more.

&gt; There is still one last bug but I&apos;m afraid it doesn&apos;t depend on webkit.

https://feedbackassistant.apple.com is always a good place to report bugs that may or may not be in WebKit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1713743</commentid>
    <comment_count>9</comment_count>
    <who name="">sbarex</who>
    <bug_when>2020-12-10 15:31:30 -0800</bug_when>
    <thetext>(In reply to Alexey Proskuryakov from comment #8)
&gt; This was a WebKit change, you correctly identified it to be
&gt; http://trac.webkit.org/r261238.
&gt; 
&gt; Thank you for testing! Just to reiterate, I&apos;m not saying that adding a
&gt; temporary entitlement is a permanent or even recommended solution. We&apos;ll
&gt; need to look into this more.
&gt; 
&gt; &gt; There is still one last bug but I&apos;m afraid it doesn&apos;t depend on webkit.
&gt; 
&gt; https://feedbackassistant.apple.com is always a good place to report bugs
&gt; that may or may not be in WebKit.

Thanks. Yes I know it&apos;s not a permanent solution but at least it makes the code usable. In the absence of a temporary solution I was thinking of suspending some my quicklook extension projects while now I can take them back in hand.

For the feedback to Apple I have already sent it (both for this bug, for the scroll bar bug and also for other things in the past) but unfortunately I have never received feedback until now.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1722378</commentid>
    <comment_count>10</comment_count>
      <attachid>418364</attachid>
    <who name="Brent Fulgham">bfulgham</who>
    <bug_when>2021-01-25 19:06:19 -0800</bug_when>
    <thetext>Created attachment 418364
Patch</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1722666</commentid>
    <comment_count>11</comment_count>
    <who name="EWS">ews-feeder</who>
    <bug_when>2021-01-26 12:40:24 -0800</bug_when>
    <thetext>Committed r271895: &lt;https://trac.webkit.org/changeset/271895&gt;

All reviewed patches have been landed. Closing bug and clearing flags on attachment 418364.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>1723086</commentid>
    <comment_count>12</comment_count>
    <who name="">sbarex</who>
    <bug_when>2021-01-27 11:33:48 -0800</bug_when>
    <thetext>(In reply to Brent Fulgham from comment #10)
&gt; Created attachment 418364 [details]
&gt; Patch

Thank you very much</thetext>
  </long_desc>
      
          <attachment
              isobsolete="0"
              ispatch="1"
              isprivate="0"
          >
            <attachid>418364</attachid>
            <date>2021-01-25 19:06:19 -0800</date>
            <delta_ts>2021-01-26 12:40:25 -0800</delta_ts>
            <desc>Patch</desc>
            <filename>bug-219632-20210125190618.patch</filename>
            <type>text/plain</type>
            <size>2285</size>
            <attacher name="Brent Fulgham">bfulgham</attacher>
            
              <data encoding="base64">U3VidmVyc2lvbiBSZXZpc2lvbjogMjcwODczCmRpZmYgLS1naXQgYS9Tb3VyY2UvV2ViS2l0L0No
YW5nZUxvZyBiL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nCmluZGV4IDI5ZDEzNzQ2NDM3NDMyM2Qw
M2QzNDRhODIwZTM0NWE1MGRlMmI0YzAuLmNiZTc2M2M2MDZhNDZjNDYzMDE1ZDZhZGJhNzQ5YmRj
NWVlMGIxMDkgMTAwNjQ0Ci0tLSBhL1NvdXJjZS9XZWJLaXQvQ2hhbmdlTG9nCisrKyBiL1NvdXJj
ZS9XZWJLaXQvQ2hhbmdlTG9nCkBAIC0xLDMgKzEsMTkgQEAKKzIwMjEtMDEtMjUgIEJyZW50IEZ1
bGdoYW0gIDxiZnVsZ2hhbUBhcHBsZS5jb20+CisKKyAgICAgICAgUkVHUkVTU0lPTihyMjYxMjM4
KTogV0tXZWJWaWV3IGNyYXNoZXMgb24gbGF1bmNoIGluc2lkZSBhIHF1aWNrbG9vayBwcmV2aWV3
CisgICAgICAgIGh0dHBzOi8vYnVncy53ZWJraXQub3JnL3Nob3dfYnVnLmNnaT9pZD0yMTk2MzIK
KyAgICAgICAgPHJkYXI6Ly9wcm9ibGVtLzcyMTU0ODMwPgorCisgICAgICAgIFJldmlld2VkIGJ5
IE5PQk9EWSAoT09QU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hdWRpdF90b2tlbihhdWRpdFRva2VuLCAibWFjaC1sb29rdXAiLCBzdGF0
aWNfY2FzdDxlbnVtIHNhbmRib3hfZmlsdGVyX3R5cGU+KFNBTkRCT1hfRklMVEVSX0dMT0JBTF9O
QU1FIHwgU0FOREJPWF9DSEVDS19OT19SRVBPUlQpLCAiY29tLmFwcGxlLm5zdXJsc2Vzc2lvbmQi
KSkgewo=
</data>

          </attachment>
      

    </bug>

</bugzilla>