Skip to content

Commit bdbfb92

Browse files
authored
Verify hostname for identities (keybase#10358)
* Verify hostname for identities * Bump version * Cleanup keybase regex * Drop keybase.pub * Remove keybase.pub from manifest * Comments
1 parent 02aaf2c commit bdbfb92

6 files changed

Lines changed: 54 additions & 22 deletions

File tree

‎browser/README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Once you have development versions of the extension in your browsers, run
5656
through the following to quickly QA any changes you have made. Check that the
5757
button appears and you can chat `joshblum` on :
5858

59-
* [keybase](https://keybase.io/joshblum)
59+
* [keybase.io](https://keybase.io/joshblum)
6060
* [reddit](https://www.reddit.com/user/joshblum)
6161
* [HN](https://news.ycombinator.com/user?id=josh_blum)
6262
* [GitHub](https://github.com/joshblum)

‎browser/css/style.css‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,7 @@ a.keybase-chat {
234234
border-radius: 28px;
235235
}
236236
a.keybase-chat img {
237+
vertical-align: unset;
237238
height: 16px;
238239
width: 16px;
239240
margin-bottom: -2px;

‎browser/js/background.js‎

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,13 +79,15 @@ function generateConditions(matchers) {
7979
// Generate pageMatchRules conditions
8080
const conditions = [];
8181
for (const m of matchers) {
82-
const cond = {
83-
pageUrl: { originAndPathMatches: m.originAndPathMatches },
84-
};
85-
if (m.css !== undefined) {
86-
cond.css = m.css;
82+
for (const hostName of m.hostEquals) {
83+
const cond = {
84+
pageUrl: { originAndPathMatches: m.originAndPathMatches, hostEquals: hostName},
85+
};
86+
if (m.css !== undefined) {
87+
cond.css = m.css;
88+
}
89+
conditions.push(new chrome.declarativeContent.PageStateMatcher(cond));
8790
}
88-
conditions.push(new chrome.declarativeContent.PageStateMatcher(cond));
8991
}
9092
return conditions;
9193
}

‎browser/js/identities.js‎

Lines changed: 42 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,50 +22,79 @@ function parseLocationQuery(s) {
2222
return params;
2323
}
2424

25-
// identityMatchers is used to generate our declarative page match rules, but also
26-
// used to check for matches at runtime. Unfortunately, these mechanisms use different
27-
// implementations of regular expressions (re2 vs javascript's regexp) so there's
28-
// some redundancy but at least it's all in one place? :D
25+
// identityMatchers is used to generate our declarative page match rules, but
26+
// also used to check for matches at runtime for each `service` that we
27+
// support. They have the following schema:
28+
// {
29+
// "service": Service name, if you add one here update `profileInject` in
30+
// `identities.js` and `User.prototype.href to fully register it.
31+
//
32+
// "getUsername": Function to parse the username from the browser
33+
// `location` object.
34+
//
35+
// "locationMatches": A regular expression used to match a page within the
36+
// service (i.e. news.ycombinator.com/user?id=username matches but not
37+
// news.ycombinator.com/newest).
38+
//
39+
// "originAndPathMatches": A re2 style regex used to match a page within
40+
// the service for declarativeContent matching
41+
// (https://developer.chrome.com/extensions/declarativeContent).
42+
//
43+
// "hostEquals": Used to match that the host is the host we want to run on
44+
// (preventing any regex trickery for `locationMatches` or
45+
// `originAndPathMatches`).
46+
//
47+
// "css": (optional) CSS selector which must be present for declarativeContent
48+
// or the chat button to be injected.
49+
//
50+
// }
51+
//
2952
const identityMatchers = [
3053
{
3154
service: "keybase",
3255
getUsername: function(loc) { return loc.pathname.split('/')[1]; },
33-
locationMatches: new RegExp('\\.keybase\\.(?:io|pub)/([\\w]+)[/]?'),
34-
originAndPathMatches: '\\.keybase\\.(io|pub)/[\\w]+[/]?',
56+
locationMatches: new RegExp('\\.keybase\\.io/([\\w]+)[/]?'),
57+
originAndPathMatches: 'keybase\\.io/[\\w]+[/]?',
58+
hostEquals: ['keybase.io'],
3559
css: ['.profile-heading']
3660
},
3761
{
3862
service: "reddit",
3963
getUsername: function(loc) { return loc.pathname.split('/')[2]; },
40-
locationMatches: new RegExp('\\.reddit.com/user/([\\w-]+)[/]?$'),
41-
originAndPathMatches: '\\.reddit.com/user/[\\w-]+[/]?$',
64+
locationMatches: new RegExp('\\.reddit\\.com/user/([\\w-]+)[/]?$'),
65+
originAndPathMatches: '\\.reddit\\.com/user/[\\w-]+[/]?$',
66+
hostEquals: ['www.reddit.com', 'reddit.com']
4267
},
4368
{
4469
service: "twitter",
4570
getUsername: function(loc) { return loc.pathname.split('/')[1]; },
4671
locationMatches: new RegExp('\\.twitter\\.com/([\\w]+)[/]?$'),
47-
originAndPathMatches: '\\.twitter\\.com/[\\w]+[/]?$',
72+
originAndPathMatches: 'twitter\\.com/[\\w]+[/]?$',
73+
hostEquals: ['twitter.com'],
4874
css: ['body.ProfilePage']
4975
},
5076
{
5177
service: "github",
5278
getUsername: function(loc) { return loc.pathname.split('/')[1]; },
5379
locationMatches: new RegExp('\\.github\\.com/([\\w\-]+)[/]?$'),
54-
originAndPathMatches: '\\.github\\.com/[\\w\-]+[/]?$',
80+
originAndPathMatches: 'github\\.com/[\\w\-]+[/]?$',
81+
hostEquals: ['github.com'],
5582
css: ['body.page-profile']
5683
},
5784
{
5885
service: "facebook",
5986
getUsername: function(loc) { return loc.pathname.split('/')[1]; },
6087
locationMatches: new RegExp('\\.facebook\\.com/([\\w\\.]+)[/]?$'),
6188
originAndPathMatches: '\\.facebook\\.com/[\\w\\.]+[/]?$',
89+
hostEquals: ['facebook.com', 'www.facebook.com'],
6290
css: ['body.timelineLayout']
6391
},
6492
{
6593
service: "hackernews",
6694
getUsername: function(loc) { return parseLocationQuery(loc.search)["id"]; },
6795
locationMatches: new RegExp('news\\.ycombinator\\.com/user'),
6896
originAndPathMatches: 'news\\.ycombinator\\.com/user',
97+
hostEquals: ['news.ycombinator.com'],
6998
css: ['html[op="user"]']
7099
}
71100
];
@@ -80,7 +109,9 @@ function matchService(loc, doc, forceService) {
80109
for (const m of identityMatchers) {
81110
if (forceService !== undefined && forceService !== m.service) continue;
82111

83-
const matched = url.match(m.locationMatches);
112+
const matched = m.hostEquals.some(function(hostName) {
113+
return hostName === loc.hostname
114+
}) && url.match(m.locationMatches);
84115
if (!matched) continue;
85116

86117
const username = safeHTML(m.getUsername(loc));

‎browser/js/inject.js‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@ const profileInject = {
4242
wrapper.insertBefore(button, lastButton);
4343
}
4444
},
45-
4645
"facebook": function facebookInjectProfile(user) {
4746
const container = document.querySelector("#fbProfileCover .actions");
4847
if (!container) return;

‎browser/manifest.json‎

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"key": "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAsc0yU3MTDhx+JC23YHwvWo/TD1Pynkdc9QekQ7S3jpl0isgro3I5K0ywANwBsZicIYhVq3OQTzV4jq53YoJSP9OFApMb3yzqzJ/QmcwpGvHjztD6I2zPoglMLnWj12VNqFqJtqVj5tT+/TQJ2MdY4eCQpuPweEwDLsR9mP2mxlpV1iCNzF2T61DAqnLmV8zeyjrwJ1QRZq/qd0lJR5JRI8+xBTTStOy2eQvnf8ngEXq2R+NXNq10MELtTpfAT0NPPS1lUbJwR9AYbm9f4wQWLxpeyl63WlmbBUsInM9jsfccDo0hULa59IWpgTdFVQFMBFlIEIN7St8QpF09OygMNQIDAQAB",
33
"name": "Keybase",
44
"short_name": "Keybase",
5-
"version": "1.10.8",
5+
"version": "1.10.9",
66
"description": "A secure chat button for every profile.",
77
"icons": {
88
"48": "images/icon-keybase-logo-48.png",
@@ -33,8 +33,7 @@
3333
"https://www.facebook.com/*",
3434
"https://github.com/*",
3535
"https://news.ycombinator.com/user*",
36-
"https://keybase.io/*",
37-
"https://keybase.pub/*"
36+
"https://keybase.io/*"
3837
],
3938
"js": [
4039
"js/bundle.js",

0 commit comments

Comments
 (0)