Bug 230778 - PCM: Take app bundle ID into consideration when matching triggering events with pending clicks
Summary: PCM: Take app bundle ID into consideration when matching triggering events wi...
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: WebKit Misc. (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: John Wilander
URL:
Keywords: InRadar
Depends on:
Blocks:
 
Reported: 2021-09-24 16:29 PDT by John Wilander
Modified: 2021-09-30 09:22 PDT (History)
5 users (show)

See Also:


Attachments
Patch (68.97 KB, patch)
2021-09-28 16:49 PDT, John Wilander
achristensen: review-
Details | Formatted Diff | Diff
Patch (73.35 KB, patch)
2021-09-28 21:17 PDT, John Wilander
ews-feeder: commit-queue-
Details | Formatted Diff | Diff
Patch (73.58 KB, patch)
2021-09-28 22:01 PDT, John Wilander
no flags Details | Formatted Diff | Diff
Patch (78.21 KB, patch)
2021-09-29 14:12 PDT, John Wilander
no flags Details | Formatted Diff | Diff
Patch (63.24 KB, patch)
2021-09-29 18:23 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (59.91 KB, patch)
2021-09-29 20:38 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (73.07 KB, patch)
2021-09-29 20:43 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description John Wilander 2021-09-24 16:29:38 PDT
https://commits.webkit.org/r282884 added app bundle IDs to unattributed and attributed clicks in PCM. We need to take those IDs into consideration in PCM::Database::attributePrivateClickMeasurement().
Comment 1 Radar WebKit Bug Importer 2021-09-24 16:30:04 PDT
<rdar://problem/83516528>
Comment 2 John Wilander 2021-09-28 16:49:03 PDT
Created attachment 439544 [details]
Patch
Comment 3 Alex Christensen 2021-09-28 17:02:45 PDT
Comment on attachment 439544 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439544&action=review

> Source/WebCore/loader/PrivateClickMeasurement.cpp:152
> +    RELEASE_ASSERT(WebCore::applicationBundleIdentifier() == "com.apple.WebKit.WebKitTestRunner"_s);

iOS has a different bundle ID, "org.webkit.WebKitTestRunnerApp"

> Source/WebCore/loader/PrivateClickMeasurement.h:424
> +    std::optional<String> m_sourceApplicationBundleIDForTesting;

I don't think this needs to be stored separately on the PCM.  setSourceApplicationBundleIDForTesting could just set m_sourceApplicationBundleID.

> Source/WebKit/NetworkProcess/NetworkSession.h:217
> +    std::optional<String> m_privateClickMeasurementAppBundleIDForTesting;

This should probably be stored on the PrivateClickMeasurementManager along with all the other testing state.
Comment 4 John Wilander 2021-09-28 17:07:25 PDT
(In reply to Alex Christensen from comment #3)
> Comment on attachment 439544 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=439544&action=review
> 
> > Source/WebCore/loader/PrivateClickMeasurement.cpp:152
> > +    RELEASE_ASSERT(WebCore::applicationBundleIdentifier() == "com.apple.WebKit.WebKitTestRunner"_s);
> 
> iOS has a different bundle ID, "org.webkit.WebKitTestRunnerApp"

Will fix.

> > Source/WebCore/loader/PrivateClickMeasurement.h:424
> > +    std::optional<String> m_sourceApplicationBundleIDForTesting;
> 
> I don't think this needs to be stored separately on the PCM. 
> setSourceApplicationBundleIDForTesting could just set
> m_sourceApplicationBundleID.

I remember thinking about that and opted for what's in the patch but I can't recall what it was. Will change and hopefully that just works.

> > Source/WebKit/NetworkProcess/NetworkSession.h:217
> > +    std::optional<String> m_privateClickMeasurementAppBundleIDForTesting;
> 
> This should probably be stored on the PrivateClickMeasurementManager along
> with all the other testing state.

I discussed with Kate and she said PrivateClickMeasurementManager will be part of the daemon and not part of the app that's using WebKit which would break this functionality. That's why I moved it back to NetworkSession. Are you saying PrivateClickMeasurementManager is guaranteed to always be part of the app?

Thanks for the review!
Comment 5 John Wilander 2021-09-28 17:12:30 PDT
(In reply to John Wilander from comment #4)
> (In reply to Alex Christensen from comment #3)
> > Comment on attachment 439544 [details]
> > Patch
> > 
> > View in context:
> > https://bugs.webkit.org/attachment.cgi?id=439544&action=review
> > 
> > > Source/WebCore/loader/PrivateClickMeasurement.cpp:152
> > > +    RELEASE_ASSERT(WebCore::applicationBundleIdentifier() == "com.apple.WebKit.WebKitTestRunner"_s);
> > 
> > iOS has a different bundle ID, "org.webkit.WebKitTestRunnerApp"
> 
> Will fix.
> 
> > > Source/WebCore/loader/PrivateClickMeasurement.h:424
> > > +    std::optional<String> m_sourceApplicationBundleIDForTesting;
> > 
> > I don't think this needs to be stored separately on the PCM. 
> > setSourceApplicationBundleIDForTesting could just set
> > m_sourceApplicationBundleID.
> 
> I remember thinking about that and opted for what's in the patch but I can't
> recall what it was. Will change and hopefully that just works.

Aaand now I remember why. It's to be able to reset it back to its original app bundle ID. Otherwise I'd have to have a variable to store the old one instead.

But I guess I could just set it to WebCore::applicationBundleIdentifier().

> > > Source/WebKit/NetworkProcess/NetworkSession.h:217
> > > +    std::optional<String> m_privateClickMeasurementAppBundleIDForTesting;
> > 
> > This should probably be stored on the PrivateClickMeasurementManager along
> > with all the other testing state.
> 
> I discussed with Kate and she said PrivateClickMeasurementManager will be
> part of the daemon and not part of the app that's using WebKit which would
> break this functionality. That's why I moved it back to NetworkSession. Are
> you saying PrivateClickMeasurementManager is guaranteed to always be part of
> the app?
> 
> Thanks for the review!
Comment 6 Alex Christensen 2021-09-28 19:31:50 PDT
PrivateClickMeasurementManager is in the daemon, but the ability to set an override bundle ID for testing is one of many test-only functions that will only be available when running tests.  I think it will be fine.

Yeah, reset it to WebCore::applicationBundleIdentifier()
Comment 7 John Wilander 2021-09-28 21:17:15 PDT
Created attachment 439563 [details]
Patch
Comment 8 John Wilander 2021-09-28 22:01:45 PDT
Created attachment 439564 [details]
Patch
Comment 9 Alex Christensen 2021-09-29 09:50:27 PDT
Comment on attachment 439564 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439564&action=review

Seems good.  API test needs fixing.

> Source/WebCore/loader/PrivateClickMeasurement.cpp:152
> +    RELEASE_ASSERT(WebCore::applicationBundleIdentifier() == "com.apple.WebKit.WebKitTestRunner"_s || WebCore::applicationBundleIdentifier() == "org.webkit.WebKitTestRunnerApp"_s);

nit: we could only check the first one if PLATFORM(MAC) and the second one elif PLATFORM(COCOA)
Also, I think we should move this check to NetworkSession, which is the place that won't move to the daemon.

> Source/WebKit/NetworkProcess/NetworkSession.cpp:328
> +    privateClickMeasurement().handleAttribution(WTFMove(attributionTriggerData), requestURL, RegistrableDomain(redirectRequest.url()), redirectRequest.firstPartyForCookies(), WebCore::applicationBundleIdentifier());

nit: we could reduce some redundancy by doing something like this:

#if PLATFORM(COCOA)
auto bundleID = WebCore::applicationBundleIdentifier();
#else
auto bundleID = emptyString();
#endif

> Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp:265
> +    RELEASE_ASSERT(WebCore::applicationBundleIdentifier() == "com.apple.WebKit.WebKitTestRunner"_s || WebCore::applicationBundleIdentifier() == "org.webkit.WebKitTestRunnerApp"_s);

This is currently redundant.  One check in NetworkSession ought to do.
Comment 10 John Wilander 2021-09-29 14:12:42 PDT
Created attachment 439655 [details]
Patch
Comment 11 John Wilander 2021-09-29 14:14:46 PDT
(In reply to Alex Christensen from comment #9)
> Comment on attachment 439564 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=439564&action=review
> 
> Seems good.  API test needs fixing.
> 
> > Source/WebCore/loader/PrivateClickMeasurement.cpp:152
> > +    RELEASE_ASSERT(WebCore::applicationBundleIdentifier() == "com.apple.WebKit.WebKitTestRunner"_s || WebCore::applicationBundleIdentifier() == "org.webkit.WebKitTestRunnerApp"_s);
> 
> nit: we could only check the first one if PLATFORM(MAC) and the second one
> elif PLATFORM(COCOA)
> Also, I think we should move this check to NetworkSession, which is the
> place that won't move to the daemon.
> 
> > Source/WebKit/NetworkProcess/NetworkSession.cpp:328
> > +    privateClickMeasurement().handleAttribution(WTFMove(attributionTriggerData), requestURL, RegistrableDomain(redirectRequest.url()), redirectRequest.firstPartyForCookies(), WebCore::applicationBundleIdentifier());
> 
> nit: we could reduce some redundancy by doing something like this:
> 
> #if PLATFORM(COCOA)
> auto bundleID = WebCore::applicationBundleIdentifier();
> #else
> auto bundleID = emptyString();
> #endif
> 
> > Source/WebKit/NetworkProcess/PrivateClickMeasurement/PrivateClickMeasurementManager.cpp:265
> > +    RELEASE_ASSERT(WebCore::applicationBundleIdentifier() == "com.apple.WebKit.WebKitTestRunner"_s || WebCore::applicationBundleIdentifier() == "org.webkit.WebKitTestRunnerApp"_s);
> 
> This is currently redundant.  One check in NetworkSession ought to do.

I changed the release asserts to the Mac vs Cocoa thing you wanted. However, I kept the check in WebCore::PrivateClickMeasurement since the two places protect against two different kinds of abuse. One is about making a *click* count for another application. The other is for a *conversion* to count for another application. You could of course have cases where both are done at the same time but they matter isolated too.
Comment 12 John Wilander 2021-09-29 15:22:08 PDT
The WPE build failure looks unrelated and was caused by https://commits.webkit.org/r283029. Sihui is fixing it in https://bugs.webkit.org/show_bug.cgi?id=230989.

The Win layout test failures are unrelated.
Comment 13 Chris Dumez 2021-09-29 15:24:00 PDT
(In reply to John Wilander from comment #12)
> The WPE build failure looks unrelated and was caused by
> https://commits.webkit.org/r283029. Sihui is fixing it in
> https://bugs.webkit.org/show_bug.cgi?id=230989.
> 
> The Win layout test failures are unrelated.

Looks related to me:
Source/WebKit/CMakeFiles/WebKit.dir/__/__/DerivedSources/WebKit/unified-sources/UnifiedSource-72468c22-2.cpp.o:UnifiedSource-72468c22-2.cpp:function WebKit::NetworkProcess::setPrivateClickMeasurementAppBundleIDForTesting(PAL::SessionID, WTF::String&&, WTF::CompletionHandler<void ()>&&): error: undefined reference to 'WebKit::NetworkSession::setPrivateClickMeasurementAppBundleIDForTesting(WTF::String&&)'
collect2: error: ld returned 1 exit status

The other one is just a warning.
Comment 14 Chris Dumez 2021-09-29 15:25:12 PDT
(In reply to Chris Dumez from comment #13)
> (In reply to John Wilander from comment #12)
> > The WPE build failure looks unrelated and was caused by
> > https://commits.webkit.org/r283029. Sihui is fixing it in
> > https://bugs.webkit.org/show_bug.cgi?id=230989.
> > 
> > The Win layout test failures are unrelated.
> 
> Looks related to me:
> Source/WebKit/CMakeFiles/WebKit.dir/__/__/DerivedSources/WebKit/unified-
> sources/UnifiedSource-72468c22-2.cpp.o:UnifiedSource-72468c22-2.cpp:function
> WebKit::NetworkProcess::setPrivateClickMeasurementAppBundleIDForTesting(PAL::
> SessionID, WTF::String&&, WTF::CompletionHandler<void ()>&&): error:
> undefined reference to
> 'WebKit::NetworkSession::setPrivateClickMeasurementAppBundleIDForTesting(WTF:
> :String&&)'
> collect2: error: ld returned 1 exit status
> 
> The other one is just a warning.

That said, given that this is the only bot, maybe it is just an incremental build issue?
Comment 15 John Wilander 2021-09-29 15:27:53 PDT
(In reply to Chris Dumez from comment #14)
> (In reply to Chris Dumez from comment #13)
> > (In reply to John Wilander from comment #12)
> > > The WPE build failure looks unrelated and was caused by
> > > https://commits.webkit.org/r283029. Sihui is fixing it in
> > > https://bugs.webkit.org/show_bug.cgi?id=230989.
> > > 
> > > The Win layout test failures are unrelated.
> > 
> > Looks related to me:
> > Source/WebKit/CMakeFiles/WebKit.dir/__/__/DerivedSources/WebKit/unified-
> > sources/UnifiedSource-72468c22-2.cpp.o:UnifiedSource-72468c22-2.cpp:function
> > WebKit::NetworkProcess::setPrivateClickMeasurementAppBundleIDForTesting(PAL::
> > SessionID, WTF::String&&, WTF::CompletionHandler<void ()>&&): error:
> > undefined reference to
> > 'WebKit::NetworkSession::setPrivateClickMeasurementAppBundleIDForTesting(WTF:
> > :String&&)'
> > collect2: error: ld returned 1 exit status
> > 
> > The other one is just a warning.

Oh.

> That said, given that this is the only bot, maybe it is just an incremental
> build issue?

I did look at that part too and couldn't figure out why it was complaining. Can such a thing happen due to incremental build?
Comment 16 Alex Christensen 2021-09-29 18:23:32 PDT
Created attachment 439688 [details]
Patch
Comment 17 John Wilander 2021-09-29 19:34:32 PDT
Comment on attachment 439688 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439688&action=review

> Source/WebCore/loader/PrivateClickMeasurement.cpp:149
> +    m_sourceApplicationBundleID = appBundleIDForTesting;

It needs to check that it's running a test here too. Otherwise it's possible to store a click for arbitrary bundle IDs.
Comment 18 Alex Christensen 2021-09-29 19:54:46 PDT
Comment on attachment 439688 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=439688&action=review

>> Source/WebCore/loader/PrivateClickMeasurement.cpp:149
>> +    m_sourceApplicationBundleID = appBundleIDForTesting;
> 
> It needs to check that it's running a test here too. Otherwise it's possible to store a click for arbitrary bundle IDs.

This is only called if the manager's m_privateClickMeasurementAppBundleIDForTesting has been set, which can only be set through NetworkSession::setPrivateClickMeasurementAppBundleIDForTesting.
Comment 19 John Wilander 2021-09-29 20:25:57 PDT
(In reply to Alex Christensen from comment #18)
> Comment on attachment 439688 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=439688&action=review
> 
> >> Source/WebCore/loader/PrivateClickMeasurement.cpp:149
> >> +    m_sourceApplicationBundleID = appBundleIDForTesting;
> > 
> > It needs to check that it's running a test here too. Otherwise it's possible to store a click for arbitrary bundle IDs.
> 
> This is only called if the manager's
> m_privateClickMeasurementAppBundleIDForTesting has been set, which can only
> be set through
> NetworkSession::setPrivateClickMeasurementAppBundleIDForTesting.

In our current benign, mistake-free code, yes. I want to make sure no code, good or bad, can call that setter unless it's a test client.
Comment 20 Alex Christensen 2021-09-29 20:38:38 PDT
Created attachment 439695 [details]
Patch
Comment 21 Alex Christensen 2021-09-29 20:43:24 PDT
Created attachment 439696 [details]
Patch
Comment 22 EWS 2021-09-30 09:22:11 PDT
Committed r283316 (242341@main): <https://commits.webkit.org/242341@main>

All reviewed patches have been landed. Closing bug and clearing flags on attachment 439696 [details].