Skip to content

Track the origin of webRequest events - #10429

Merged
zcbenz merged 7 commits into
electron:masterfrom
qazbnm456:web-request-origin
Sep 13, 2017
Merged

zcbenz merged 7 commits into
electron:masterfrom
qazbnm456:web-request-origin

Conversation

@qazbnm456

Copy link
Copy Markdown
Contributor

This PR is a mitigation to #10061, and therefore ppl can use the webContentsGetId to track the origin requester. The variable name webContentsGetId is taken from a64978b.

In addition, it would be convenient if we can have a webContents.fromGetId api to get the corresponding WebContents, just like what webContents.fromId does. How do you think?

@MarshallOfSound MarshallOfSound left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please remove package-lock.json 👍

@qazbnm456

Copy link
Copy Markdown
Contributor Author

@MarshallOfSound Done 😃

if (info) {
int64_t process_id = info->GetChildID();
int64_t routing_id = info->GetRouteID();
details->SetDouble("webContentsGetId", (process_id << 32) + routing_id);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be just webContentsId

And assuming my understanding of this bit shifting is correct that ID should just work with https://electron.atom.io/docs/api/web-contents/#webcontentsfromidid 👍

@qazbnm456 qazbnm456 Sep 3, 2017 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • webContentsId is actually the ID in a weak map, as shown here.
  • webContentsGetId is, in the other hand, a 64-bit integer composed of both the process id(high 32) and the RenderViewHost routing id(low 32), as shown here.

Thus, the argument passed to webContents.fromId(id) should be webContentsId, not webContentsGetId, as shown here. Besides, there's no api to get back the corresponding webContents from webContentsGetId afaik 😭 .

@zcbenz zcbenz Sep 12, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use the process ID and routing ID to get the WebContents with:

content::WebContents* webContents = content::WebContents::FromRenderFrameHost(RenderFrameHost::FromID(process_id, routing_id));

And then get the webContentsId by calling api::WebContents::GetIDFromWrappedClass(webContents).

(We would need to make that method public though).

if (info) {
int64_t process_id = info->GetChildID();
int64_t routing_id = info->GetRouteID();
details->SetDouble("webContentsGetId", (process_id << 32) + routing_id);

@zcbenz zcbenz Sep 12, 2017 •

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you can use the process ID and routing ID to get the WebContents with:

content::WebContents* webContents = content::WebContents::FromRenderFrameHost(RenderFrameHost::FromID(process_id, routing_id));

And then get the webContentsId by calling api::WebContents::GetIDFromWrappedClass(webContents).

(We would need to make that method public though).

@qazbnm456

qazbnm456 commented Sep 12, 2017 •

Copy link
Copy Markdown
Contributor Author

@zcbenz
Thanks for your suggestions. I've used process_id and render_id, which is fetched from info-> GetRenderFrameID(), to get the corresponding webContents through content::WebContents::FromRenderFrameHost(content::RenderFrameHost::FromID(process_id, render_id)), and then get the webContentsId by atom::api::WebContents::GetIDFromWrappedClass(webContents). 😄

By the way, I just changed atom::api::WebContents::GetIDFromWrappedClass(webContents) from protected to public method.

@zcbenz
zcbenz merged commit 2048a1a into electron:master Sep 13, 2017
@qazbnm456
qazbnm456 deleted the web-request-origin branch September 13, 2017 13:26
qazbnm456 added a commit to LulumiProject/lulumi-browser that referenced this pull request Sep 29, 2017
2. remove mappings member in vuex
3. we now track each webRequest events by electron/electron#10429
4. store the corresponding tabId as an attribute into its webContents object
qazbnm456 added a commit to LulumiProject/lulumi-browser that referenced this pull request Sep 30, 2017
2. remove mappings member in vuex
3. we now track each webRequest events by electron/electron#10429
4. store the corresponding webContentsId as an attribute into extension API's TabObject
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants