RESOLVED FIXED 218097
[macOS] Set preference for overridden languages in the WebContent process after entering the sandbox.
https://bugs.webkit.org/show_bug.cgi?id=218097
Summary [macOS] Set preference for overridden languages in the WebContent process aft...
Per Arne Vollan
Reported 2020-10-22 13:19:26 PDT
Currently, the preference for overridden languages in the WebContent process is set before entering the sandbox, which leaves behind an open connection to opendirectoryd. This preference should be set after entering the sandbox to avoid this.
Attachments
Patch (8.28 KB, patch)
2020-10-22 13:42 PDT, Per Arne Vollan
no flags
Patch (12.72 KB, patch)
2020-10-27 07:47 PDT, Per Arne Vollan
no flags
Patch (13.36 KB, patch)
2020-10-27 09:06 PDT, Per Arne Vollan
ews-feeder: commit-queue-
Patch (15.23 KB, patch)
2020-10-27 10:16 PDT, Per Arne Vollan
no flags
Patch (16.25 KB, patch)
2020-10-29 07:28 PDT, Per Arne Vollan
no flags
Patch (17.05 KB, patch)
2020-10-29 08:15 PDT, Per Arne Vollan
no flags
Patch (16.18 KB, patch)
2020-10-29 09:09 PDT, Per Arne Vollan
no flags
Patch (16.42 KB, patch)
2020-10-29 11:37 PDT, Per Arne Vollan
no flags
Patch (21.18 KB, patch)
2020-10-29 13:13 PDT, Per Arne Vollan
no flags
Patch (21.21 KB, patch)
2020-10-29 14:17 PDT, Per Arne Vollan
ap: review+
Patch (21.16 KB, patch)
2020-10-30 10:10 PDT, Per Arne Vollan
ews-feeder: commit-queue-
Patch (23.12 KB, patch)
2020-11-02 09:59 PST, Per Arne Vollan
no flags
Radar WebKit Bug Importer
Comment 1 2020-10-22 13:19:48 PDT
Per Arne Vollan
Comment 2 2020-10-22 13:42:10 PDT
Alexey Proskuryakov
Comment 3 2020-10-23 10:35:26 PDT
Comment on attachment 412126 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=412126&action=review > Source/WebKit/ChangeLog:9 > + Currently, the preference for overridden languages in the WebContent process is set before entering the sandbox, How did you test that the functionality still works? This is not really covered by regression tests.
Per Arne Vollan
Comment 4 2020-10-23 13:41:18 PDT
(In reply to Alexey Proskuryakov from comment #3) > Comment on attachment 412126 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=412126&action=review > > > Source/WebKit/ChangeLog:9 > > + Currently, the preference for overridden languages in the WebContent process is set before entering the sandbox, > > How did you test that the functionality still works? This is not really > covered by regression tests. That is a good point. This was tested manually, but I can look into creating an API test for this.
Alexey Proskuryakov
Comment 5 2020-10-23 13:44:40 PDT
How did you test this manually?
Per Arne Vollan
Comment 6 2020-10-23 14:19:27 PDT
(In reply to Alexey Proskuryakov from comment #5) > How did you test this manually? I verified in the debugger that the languages read from the preference 'AppleLanguages' in the UI process was written to preferences in the WebContent process. I aim to create an API test for this next, where the language preference will be overridden in memory in the UI process. Thanks for reviewing!
Alexey Proskuryakov
Comment 7 2020-10-23 15:33:31 PDT
This amount of manual testing is not sufficient, please test end to end that the language is set and honored. It was very intentional that variables were set form bootstrap message, as letting any CFBundle code run permanently fixes it on the value that is in effect at the time.
Per Arne Vollan
Comment 8 2020-10-27 07:47:54 PDT
Per Arne Vollan
Comment 9 2020-10-27 07:50:54 PDT
(In reply to Alexey Proskuryakov from comment #7) > This amount of manual testing is not sufficient, please test end to end that > the language is set and honored. > I have added a regression test in the latest patch. > It was very intentional that variables were set form bootstrap message, as > letting any CFBundle code run permanently fixes it on the value that is in > effect at the time. Thanks, that is very helpful information. I believe the latest patch does not alter the previous behavior in that regard. Thanks for reviewing!
Per Arne Vollan
Comment 10 2020-10-27 09:06:25 PDT
Per Arne Vollan
Comment 11 2020-10-27 10:16:21 PDT
Alexey Proskuryakov
Comment 12 2020-10-27 10:50:01 PDT
Comment on attachment 412438 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=412438&action=review > Tools/TestWebKitAPI/Tests/WebKit/OverrideAppleLanguagesPreference.mm:39 > + [[NSUserDefaults standardUserDefaults] setVolatileDomain:dict forName:NSArgumentDomain]; This part is good I think. > Tools/TestWebKitAPI/Tests/WebKit/OverrideAppleLanguagesPreference.mm:47 > + return [webView stringByEvaluatingJavaScript:@"window.internals.userPreferredLanguages()[0]"]; This test does not verify the challenging side of the proposed change, which is using correct localization resources. While I'm not 100% certain that it's wrong, I recall that CFBundle was initialized right after calling XPCServiceMain, so event handler is too late. Please at least verify manually that the right localization is picked when setting AppleLanguages in UI process.
Per Arne Vollan
Comment 13 2020-10-27 14:19:22 PDT
(In reply to Alexey Proskuryakov from comment #12) > Comment on attachment 412438 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=412438&action=review > > > Tools/TestWebKitAPI/Tests/WebKit/OverrideAppleLanguagesPreference.mm:39 > > + [[NSUserDefaults standardUserDefaults] setVolatileDomain:dict forName:NSArgumentDomain]; > > This part is good I think. > > > Tools/TestWebKitAPI/Tests/WebKit/OverrideAppleLanguagesPreference.mm:47 > > + return [webView stringByEvaluatingJavaScript:@"window.internals.userPreferredLanguages()[0]"]; > > This test does not verify the challenging side of the proposed change, which > is using correct localization resources. While I'm not 100% certain that > it's wrong, I recall that CFBundle was initialized right after calling > XPCServiceMain, so event handler is too late. > I was able to verify in the debugger that the CFBundle localization code related to the XPC bootstrap message was run after the initialization function, so I think we should be ok. > Please at least verify manually that the right localization is picked when > setting AppleLanguages in UI process. What is the best way to verify this? It seems the WebContent process has only one localization (en.lproj). Thanks for reviewing!
Alexey Proskuryakov
Comment 14 2020-10-27 17:08:29 PDT
I usually copy localization directories from shipping Safari.
Per Arne Vollan
Comment 15 2020-10-29 07:28:51 PDT
Per Arne Vollan
Comment 16 2020-10-29 07:34:57 PDT
(In reply to Alexey Proskuryakov from comment #14) > I usually copy localization directories from shipping Safari. I have confirmed locally that the correct localization is picked up with this patch. This was tested by manually adding localized strings in Spanish and Norwegian in the Xcode IDE to WebCore.framework. I then set the system language to Spanish, and launched Safari in the debugger with the command line option '-AppleLanguages (nb)'. Safari was then started with Norwegian localization, and I confirmed in the debugger that the function CFBundleCopyLocalizedString returned Norwegian strings in the WebContent process.
Per Arne Vollan
Comment 17 2020-10-29 08:15:18 PDT
Per Arne Vollan
Comment 18 2020-10-29 09:09:01 PDT
Per Arne Vollan
Comment 19 2020-10-29 11:37:50 PDT
Per Arne Vollan
Comment 20 2020-10-29 13:13:17 PDT
Per Arne Vollan
Comment 21 2020-10-29 14:17:33 PDT
Alexey Proskuryakov
Comment 22 2020-10-29 14:45:07 PDT
Comment on attachment 412684 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=412684&action=review Thank you for testing! It would be useful to check the full scenario with localizations in the API test. But it doesn't have to be part of this patch to test something that's preexisting behavior. > LayoutTests/ChangeLog:8 > + Add test for sandbox access to cfprefsd.daemon, and mark cfprefsd tests as failing for Mojave, since CFPrefs This is surprising. CFPREFS_DIRECT_MODE is not enabled on Catalina either, so doesn't the failing result need to be in platform/mac-catalina?
Per Arne Vollan
Comment 23 2020-10-29 15:01:39 PDT
(In reply to Alexey Proskuryakov from comment #22) > Comment on attachment 412684 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=412684&action=review > > Thank you for testing! It would be useful to check the full scenario with > localizations in the API test. But it doesn't have to be part of this patch > to test something that's preexisting behavior. > > > LayoutTests/ChangeLog:8 > > + Add test for sandbox access to cfprefsd.daemon, and mark cfprefsd tests as failing for Mojave, since CFPrefs > > This is surprising. CFPREFS_DIRECT_MODE is not enabled on Catalina either, > so doesn't the failing result need to be in platform/mac-catalina? Ah, yes! I will move the expectation file to the Catalina folder. Thanks for reviewing!
Per Arne Vollan
Comment 24 2020-10-30 10:10:41 PDT
Per Arne Vollan
Comment 25 2020-11-02 09:59:14 PST
EWS
Comment 26 2020-11-09 10:00:45 PST
Committed r269584: <https://trac.webkit.org/changeset/269584> All reviewed patches have been landed. Closing bug and clearing flags on attachment 412934 [details].
Note You need to log in before you can comment on or make changes to this bug.