RESOLVED FIXED 203214
Mach lookup to com.apple.webinspector should not be allowed in WebKit's WebContent process
https://bugs.webkit.org/show_bug.cgi?id=203214
Summary Mach lookup to com.apple.webinspector should not be allowed in WebKit's WebCo...
Per Arne Vollan
Reported 2019-10-21 14:55:49 PDT
Currently, mach lookup to com.apple.webinspector is allowed in the WebContent process, but instead of always allowing this, we should issue a mach sandbox extension in the UI process when the user is enabling the Web inspector.
Attachments
Patch (15.43 KB, patch)
2019-10-21 15:57 PDT, Per Arne Vollan
no flags
Patch (15.47 KB, patch)
2019-10-21 16:33 PDT, Per Arne Vollan
no flags
Patch (15.52 KB, patch)
2019-10-22 14:39 PDT, Per Arne Vollan
no flags
Patch (16.80 KB, patch)
2019-10-23 10:45 PDT, Per Arne Vollan
no flags
Patch (16.80 KB, patch)
2019-10-23 11:12 PDT, Per Arne Vollan
no flags
Patch (16.71 KB, patch)
2019-10-23 11:20 PDT, Per Arne Vollan
no flags
Patch (15.96 KB, patch)
2019-10-23 17:11 PDT, Per Arne Vollan
no flags
Patch (15.92 KB, patch)
2019-10-24 10:06 PDT, Per Arne Vollan
no flags
Patch (15.92 KB, patch)
2019-10-24 10:38 PDT, Per Arne Vollan
no flags
Patch (16.04 KB, patch)
2019-11-05 17:15 PST, Per Arne Vollan
no flags
Patch (16.88 KB, patch)
2020-02-06 10:59 PST, Per Arne Vollan
no flags
Patch (17.11 KB, patch)
2020-02-06 15:09 PST, Per Arne Vollan
no flags
Patch (17.32 KB, patch)
2020-02-12 17:22 PST, Per Arne Vollan
no flags
Patch (17.37 KB, patch)
2020-02-13 08:54 PST, Per Arne Vollan
no flags
Patch (17.16 KB, patch)
2020-02-13 09:18 PST, Per Arne Vollan
bfulgham: review+
Per Arne Vollan
Comment 1 2019-10-21 15:57:34 PDT
Per Arne Vollan
Comment 2 2019-10-21 16:33:52 PDT
Joseph Pecoraro
Comment 3 2019-10-21 16:59:51 PDT
Comment on attachment 381472 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381472&action=review > Source/JavaScriptCore/inspector/remote/RemoteInspector.cpp:43 > +#if PLATFORM(COCOA) > +std::atomic<bool> RemoteInspector::needMachSandboxExtension = true; > +#endif Hmm. Since the default is false, this looks like like it could break remote debugging of a JSContext: (1) Applications/Daemons should already have access to the port in the default sandbox rules (2) Disabling RemoteInspector by default means JSContext only applications would not be debuggable I see that you relax the restriction for +[WebView initialization] (WebView / UIWebView), but it seems we would also need to do the same for JSContext / JSContextRef. However maybe the default should be that the sandbox requirement is not necessary, and it is only turned on in WebContentProcess? That seems less likely to be problematic for Remote Inspection in the future. > Source/JavaScriptCore/inspector/remote/RemoteInspector.h:111 > +#if PLATFORM(COCOA) > + static void setNeedMachSandboxExtension(bool needExtension) { needMachSandboxExtension = needExtension; } > +#endif This is only ever called with `false`. How about renaming it to describe what it is effectively doing? static void relaxSandboxExtensionRequirement() { needMachSandboxExtension = false; } > Source/WebKit/ChangeLog:12 > + If the Web inspector is enabled when the WebContent process is started, a sandbox extension is created > + for 'com.apple.webinspectord' and a message is sent to the WebContent process, where the extension will > + be consumed, and the remote Web inspector will be started. The same happens if Web inspector is enabled > + by the user while Safari is running. When RemoteInspector::singleton() is called in the UI process there > + is no need for an extension, since access to the Web inspector daemon is already allowed. Given we now go through the UIProcess... does the WebContent process ever need access to this mach port now? Hmm, it probably needs it for direct Service-Worker debugging. > Source/WebKit/UIProcess/WebProcessProxy.cpp:869 > + if (CFPreferencesGetAppIntegerValue(CFSTR("RemoteInspectorEnabled"), CFSTR("com.apple.webinspectord"), &keyExistsAndHasValidFormat) && keyExistsAndHasValidFormat) { Is it normal to have access to this? I would not expect this.
Alex Christensen
Comment 4 2019-10-22 07:12:38 PDT
Comment on attachment 381481 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381481&action=review > Source/WebKit/UIProcess/WebProcessPool.cpp:1041 > + Inspector::RemoteInspector::setNeedMachSandboxExtension(false); This doesn't look right. Shouldn't we be consuming a sandbox extension before calling this? > Source/WebKit/WebProcess/WebProcess.messages.in:135 > + RemoteWebInspectorEnabled(WebKit::SandboxExtension::Handle handle); This sounds like it should return a bool. EnableRemoteWebInspector?
Per Arne Vollan
Comment 5 2019-10-22 11:23:56 PDT
(In reply to Joseph Pecoraro from comment #3) > Comment on attachment 381472 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=381472&action=review > > > Source/JavaScriptCore/inspector/remote/RemoteInspector.cpp:43 > > +#if PLATFORM(COCOA) > > +std::atomic<bool> RemoteInspector::needMachSandboxExtension = true; > > +#endif > > Hmm. Since the default is false, this looks like like it could break remote > debugging of a JSContext: > > (1) Applications/Daemons should already have access to the port in the > default sandbox rules > (2) Disabling RemoteInspector by default means JSContext only > applications would not be debuggable > > I see that you relax the restriction for +[WebView initialization] (WebView > / UIWebView), but it seems we would also need to do the same for JSContext / > JSContextRef. > > However maybe the default should be that the sandbox requirement is not > necessary, and it is only turned on in WebContentProcess? That seems less > likely to be problematic for Remote Inspection in the future. > Good point, I'll change the default to not require a sandbox extension. > > Source/JavaScriptCore/inspector/remote/RemoteInspector.h:111 > > +#if PLATFORM(COCOA) > > + static void setNeedMachSandboxExtension(bool needExtension) { needMachSandboxExtension = needExtension; } > > +#endif > > This is only ever called with `false`. How about renaming it to describe > what it is effectively doing? > > static void relaxSandboxExtensionRequirement() { > needMachSandboxExtension = false; } > By changing the default of the flag to not needing a sandbox extension, I think the WebContent process will need to pass both true and false to this method. > > Source/WebKit/ChangeLog:12 > > + If the Web inspector is enabled when the WebContent process is started, a sandbox extension is created > > + for 'com.apple.webinspectord' and a message is sent to the WebContent process, where the extension will > > + be consumed, and the remote Web inspector will be started. The same happens if Web inspector is enabled > > + by the user while Safari is running. When RemoteInspector::singleton() is called in the UI process there > > + is no need for an extension, since access to the Web inspector daemon is already allowed. > > Given we now go through the UIProcess... does the WebContent process ever > need access to this mach port now? Hmm, it probably needs it for direct > Service-Worker debugging. > Oh, that is interesting! How can I test if it's needed for Service-Worker debugging? > > Source/WebKit/UIProcess/WebProcessProxy.cpp:869 > > + if (CFPreferencesGetAppIntegerValue(CFSTR("RemoteInspectorEnabled"), CFSTR("com.apple.webinspectord"), &keyExistsAndHasValidFormat) && keyExistsAndHasValidFormat) { > > Is it normal to have access to this? I would not expect this. You're right. This requires a new sandbox rule for the UI process (Safari), which will be added in separate patch. Thanks for reviewing!
Joseph Pecoraro
Comment 6 2019-10-22 11:40:28 PDT
> > > Source/WebKit/ChangeLog:12 > > > + If the Web inspector is enabled when the WebContent process is started, a sandbox extension is created > > > + for 'com.apple.webinspectord' and a message is sent to the WebContent process, where the extension will > > > + be consumed, and the remote Web inspector will be started. The same happens if Web inspector is enabled > > > + by the user while Safari is running. When RemoteInspector::singleton() is called in the UI process there > > > + is no need for an extension, since access to the Web inspector daemon is already allowed. > > > > Given we now go through the UIProcess... does the WebContent process ever > > need access to this mach port now? Hmm, it probably needs it for direct > > Service-Worker debugging. > > > > Oh, that is interesting! How can I test if it's needed for Service-Worker > debugging? You can visit a page like `https://airhorner.com` and you should continue to see the airhorner.com Service Worker in the Develop menu: macOS: Develop > Service Worker > airhorner iOS: Develop > (Device Name) > airhorner > > > Source/WebKit/UIProcess/WebProcessProxy.cpp:869 > > > + if (CFPreferencesGetAppIntegerValue(CFSTR("RemoteInspectorEnabled"), CFSTR("com.apple.webinspectord"), &keyExistsAndHasValidFormat) && keyExistsAndHasValidFormat) { > > > > Is it normal to have access to this? I would not expect this. > > You're right. This requires a new sandbox rule for the UI process (Safari), > which will be added in separate patch. I'm not exactly a fan of this approach. If this `RemoteInspectorEnabled` setting changes, then someone will have to remember to change WebKit. Currently that setting (on COCOA) is only set in one place and checked in one place.
Per Arne Vollan
Comment 7 2019-10-22 13:46:36 PDT
(In reply to Alex Christensen from comment #4) > Comment on attachment 381481 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=381481&action=review > > > Source/WebKit/UIProcess/WebProcessPool.cpp:1041 > > + Inspector::RemoteInspector::setNeedMachSandboxExtension(false); > > This doesn't look right. Shouldn't we be consuming a sandbox extension > before calling this? > Not in this case, since the UI process does not need to consume a web inspector extension. However, this line will not be needed when the default flag for needing a sandbox extension is being changed to false. > > Source/WebKit/WebProcess/WebProcess.messages.in:135 > > + RemoteWebInspectorEnabled(WebKit::SandboxExtension::Handle handle); > > This sounds like it should return a bool. EnableRemoteWebInspector? Yes, that is much better. Thanks for reviewing!
Per Arne Vollan
Comment 8 2019-10-22 14:39:38 PDT
Per Arne Vollan
Comment 9 2019-10-22 15:46:11 PDT
(In reply to Joseph Pecoraro from comment #6) > > > > Source/WebKit/ChangeLog:12 > > > > + If the Web inspector is enabled when the WebContent process is started, a sandbox extension is created > > > > + for 'com.apple.webinspectord' and a message is sent to the WebContent process, where the extension will > > > > + be consumed, and the remote Web inspector will be started. The same happens if Web inspector is enabled > > > > + by the user while Safari is running. When RemoteInspector::singleton() is called in the UI process there > > > > + is no need for an extension, since access to the Web inspector daemon is already allowed. > > > > > > Given we now go through the UIProcess... does the WebContent process ever > > > need access to this mach port now? Hmm, it probably needs it for direct > > > Service-Worker debugging. > > > > > > > Oh, that is interesting! How can I test if it's needed for Service-Worker > > debugging? > > You can visit a page like `https://airhorner.com` and you should continue to > see the airhorner.com Service Worker in the Develop menu: > > macOS: Develop > Service Worker > airhorner > iOS: Develop > (Device Name) > airhorner > > > > > Source/WebKit/UIProcess/WebProcessProxy.cpp:869 > > > > + if (CFPreferencesGetAppIntegerValue(CFSTR("RemoteInspectorEnabled"), CFSTR("com.apple.webinspectord"), &keyExistsAndHasValidFormat) && keyExistsAndHasValidFormat) { > > > > > > Is it normal to have access to this? I would not expect this. > > > > You're right. This requires a new sandbox rule for the UI process (Safari), > > which will be added in separate patch. > > I'm not exactly a fan of this approach. If this `RemoteInspectorEnabled` > setting changes, then someone will have to remember to change WebKit. > Currently that setting (on COCOA) is only set in one place and checked in > one place. Yes, that is a good point. Perhaps these strings could be added to a header file?
Brent Fulgham
Comment 10 2019-10-22 21:25:26 PDT
Comment on attachment 381609 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381609&action=review Looks good. I think we should get an okay from a WebInsoector person like Joe before landing. > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:502 > + CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, static_cast<CFStringRef>(CFSTR(WIRServiceEnabledNotification)) , nullptr); Extra white space around the commas.
Per Arne Vollan
Comment 11 2019-10-23 10:45:11 PDT
Per Arne Vollan
Comment 12 2019-10-23 10:45:51 PDT
(In reply to Brent Fulgham from comment #10) > Comment on attachment 381609 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=381609&action=review > > Looks good. I think we should get an okay from a WebInsoector person like > Joe before landing. > > > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:502 > > + CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, static_cast<CFStringRef>(CFSTR(WIRServiceEnabledNotification)) , nullptr); > > Extra white space around the commas. Good catch, I have uploaded a new patch. Thanks for reviewing!
Per Arne Vollan
Comment 13 2019-10-23 11:12:25 PDT
Per Arne Vollan
Comment 14 2019-10-23 11:20:52 PDT
Per Arne Vollan
Comment 15 2019-10-23 17:11:17 PDT
Joseph Pecoraro
Comment 16 2019-10-23 17:32:37 PDT
Comment on attachment 381756 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381756&action=review > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:501 > + CFNotificationCenterRemoveObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, static_cast<CFStringRef>(CFSTR(WIRServiceEnabledNotification)), nullptr); Would you have to static_cast a string that is already a CFSTR? Seems like you should be able to drop the `static_cast<CFStringRef>` cast. > Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm:219 > + if (!CFPreferencesGetAppIntegerValue(CFSTR(WIRRemoteInspectorEnabledKey), CFSTR(WIRRemoteInspectorDomainName), nullptr)) > + return; How will we guarantee that all UIProcesses have access to this setting? Do we want to expose all of their sandboxes to this?
Per Arne Vollan
Comment 17 2019-10-24 10:06:20 PDT
Brent Fulgham
Comment 18 2019-10-24 10:10:29 PDT
Comment on attachment 381756 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381756&action=review >> Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm:219 >> + return; > > How will we guarantee that all UIProcesses have access to this setting? Do we want to expose all of their sandboxes to this? I'm not sure I understand the question here. It seems like this setting would be available to any WebKit client that links to a new build of WebKit.
Brent Fulgham
Comment 19 2019-10-24 10:25:56 PDT
Comment on attachment 381821 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=381821&action=review > Source/JavaScriptCore/inspector/remote/RemoteInspectorConstants.h:123 > +#define WIRRemoteInspectorDomainName "com.apple.webinspectord" You always cast this as CFSTR; should these be defined as @"Remote.." and @"com.apple.webinspectord"? > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:420 > + process->enableRemoteInspectorIfNeeded(); Is the remote inspector needed for every web process? Should it be tied to a specific active tab when the user chose to enable (or show) the WebInspector?
Per Arne Vollan
Comment 20 2019-10-24 10:30:33 PDT
(In reply to Brent Fulgham from comment #18) > Comment on attachment 381756 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=381756&action=review > > >> Source/WebKit/UIProcess/Cocoa/WebProcessProxyCocoa.mm:219 > >> + return; > > > > How will we guarantee that all UIProcesses have access to this setting? Do we want to expose all of their sandboxes to this? > > I'm not sure I understand the question here. It seems like this setting > would be available to any WebKit client that links to a new build of WebKit. I believe we need to extend the sandbox in the UI process with the right to read this preference. Additionally, the UI process' sandbox needs a new rule to allow creating the mach sandbox extension to 'com.apple.webinspector'. All apps that wants to be inspectable will have to add these two rules to their sandbox. I will make sure these two rules are added to the sandbox profile which most apps are using. Thanks for reviewing, all!
Per Arne Vollan
Comment 21 2019-10-24 10:38:08 PDT
Per Arne Vollan
Comment 22 2019-10-24 11:00:49 PDT
(In reply to Brent Fulgham from comment #19) > Comment on attachment 381821 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=381821&action=review > > > Source/JavaScriptCore/inspector/remote/RemoteInspectorConstants.h:123 > > +#define WIRRemoteInspectorDomainName "com.apple.webinspectord" > > You always cast this as CFSTR; should these be defined as @"Remote.." and > @"com.apple.webinspectord"? > Done. Declared as CFSTR in the latest patch. > > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:420 > > + process->enableRemoteInspectorIfNeeded(); > > Is the remote inspector needed for every web process? Should it be tied to a > specific active tab when the user chose to enable (or show) the WebInspector? I believe it needs to be enabled for every web process, since I believe it is possible to inspect many Service workers at the same time.
Per Arne Vollan
Comment 23 2019-11-05 17:15:52 PST
Per Arne Vollan
Comment 24 2019-11-13 15:35:49 PST
Per Arne Vollan
Comment 25 2020-02-06 10:59:39 PST
Per Arne Vollan
Comment 26 2020-02-06 15:09:49 PST
Brent Fulgham
Comment 27 2020-02-11 15:09:27 PST
Comment on attachment 390010 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=390010&action=review > Source/JavaScriptCore/inspector/remote/RemoteInspector.cpp:41 > +#if PLATFORM(IOS) What about macOS? What about macCatalyst? > Source/JavaScriptCore/inspector/remote/RemoteInspector.h:118 > + static void setNeedMachSandboxExtension(bool needExtension) { needMachSandboxExtension = needExtension; } Do we need to do a std::swap() here to benefit from the atomic type? I can't remember. > Source/JavaScriptCore/inspector/remote/RemoteInspector.h:242 > +#if PLATFORM(IOS) Why can't we do this on macOS, too?
Per Arne Vollan
Comment 28 2020-02-12 07:37:10 PST
(In reply to Brent Fulgham from comment #27) > Comment on attachment 390010 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=390010&action=review > > > Source/JavaScriptCore/inspector/remote/RemoteInspector.cpp:41 > > +#if PLATFORM(IOS) > > What about macOS? What about macCatalyst? > Good point! I will change the code to include maOS as well. Some parts are iOS specific, like the setting to enable remote inspection and the notification name. Are you OK with fixing the remaining macOS specific things in a separate patch? > > Source/JavaScriptCore/inspector/remote/RemoteInspector.h:118 > > + static void setNeedMachSandboxExtension(bool needExtension) { needMachSandboxExtension = needExtension; } > > Do we need to do a std::swap() here to benefit from the atomic type? I can't > remember. > I am not 100% sure, but I think it should be safe to to an assignment here. > > Source/JavaScriptCore/inspector/remote/RemoteInspector.h:242 > > +#if PLATFORM(IOS) > > Why can't we do this on macOS, too? I will enable this for macOS as well. Thanks for reviewing!
Per Arne Vollan
Comment 29 2020-02-12 17:22:35 PST
Per Arne Vollan
Comment 30 2020-02-13 08:54:53 PST
Per Arne Vollan
Comment 31 2020-02-13 09:18:09 PST
Brent Fulgham
Comment 32 2020-02-16 20:50:26 PST
Comment on attachment 390657 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=390657&action=review > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:513 > + for (size_t i = 0; i < pool->m_processes.size(); ++i) { Can we use a modern C++ loop here? > Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:574 > + CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, remoteWebInspectorEnabledCallback, static_cast<CFStringRef>(CFSTR(WIRServiceEnabledNotification)), nullptr, CFNotificationSuspensionBehaviorCoalesce); Do we not need this for macOS? > Source/WebKit/WebProcess/WebProcess.cpp:436 > + Inspector::RemoteInspector::setNeedMachSandboxExtension(true); Why isn't this needed on macOS, too? And what about MacCatalyst?
Brent Fulgham
Comment 33 2020-02-16 20:52:15 PST
Comment on attachment 390657 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=390657&action=review Thank you for reviewing it again. r=me >> Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:574 >> + CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, remoteWebInspectorEnabledCallback, static_cast<CFStringRef>(CFSTR(WIRServiceEnabledNotification)), nullptr, CFNotificationSuspensionBehaviorCoalesce); > > Do we not need this for macOS? Oh -- I see, you already answered this. Never mind. >> Source/WebKit/WebProcess/WebProcess.cpp:436 >> + Inspector::RemoteInspector::setNeedMachSandboxExtension(true); > > Why isn't this needed on macOS, too? And what about MacCatalyst? Never mind!
Per Arne Vollan
Comment 34 2020-02-17 10:23:05 PST
(In reply to Brent Fulgham from comment #33) > Comment on attachment 390657 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=390657&action=review > > Thank you for reviewing it again. r=me > > >> Source/WebKit/UIProcess/Cocoa/WebProcessPoolCocoa.mm:574 > >> + CFNotificationCenterAddObserver(CFNotificationCenterGetDarwinNotifyCenter(), this, remoteWebInspectorEnabledCallback, static_cast<CFStringRef>(CFSTR(WIRServiceEnabledNotification)), nullptr, CFNotificationSuspensionBehaviorCoalesce); > > > > Do we not need this for macOS? > > Oh -- I see, you already answered this. Never mind. > > >> Source/WebKit/WebProcess/WebProcess.cpp:436 > >> + Inspector::RemoteInspector::setNeedMachSandboxExtension(true); > > > > Why isn't this needed on macOS, too? And what about MacCatalyst? > > Never mind! Thanks for reviewing!
Per Arne Vollan
Comment 35 2020-02-17 10:31:36 PST
Note You need to log in before you can comment on or make changes to this bug.