Skip to content
This repository has been archived by the owner on Jan 17, 2023. It is now read-only.

Commit

Permalink
Fix #2167, don't login until absolutely necessary, and allow submissi…
Browse files Browse the repository at this point in the history
…on POST /event with a non-signed non-cookie deviceId
  • Loading branch information
ianb committed Feb 24, 2017
1 parent 7add195 commit 6adbfea
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 4 deletions.
5 changes: 4 additions & 1 deletion server/src/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -426,7 +426,10 @@ app.post("/event", function (req, res) {
if (typeof bodyObj !== "object") {
throw new Error(`Got unexpected req.body type: ${typeof bodyObj}`);
}
hashUserId(req.deviceId).then((userUuid) => {
// We allow clients to signal events with a deviceId even if they haven't logged in yet,
// by putting deviceId into the request body:
let deviceId = req.deviceId || bodyObj.deviceId;
hashUserId(deviceId).then((userUuid) => {
let userAnalytics = ua(config.gaId, userUuid.toString(), {strictCidFormat: false});
if (config.debugGoogleAnalytics) {
userAnalytics = userAnalytics.debug();
Expand Down
3 changes: 2 additions & 1 deletion webextension/background/analytics.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* globals main */
/* globals main, auth */

window.analytics = (function () {
let exports = {};
Expand All @@ -16,6 +16,7 @@ window.analytics = (function () {
};
// FIXME: add cdX and other details from req.js
req.send(JSON.stringify({
deviceId: auth.getDeviceId(),
event: eventCategory,
action,
label
Expand Down
6 changes: 4 additions & 2 deletions webextension/background/auth.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ window.auth = (function () {
chrome.storage.local.get(["registrationInfo"], (result) => {
if (result.registrationInfo) {
registrationInfo = result.registrationInfo;
login();
} else {
registrationInfo = generateRegistrationInfo();
chrome.storage.local.set({
Expand All @@ -21,10 +20,13 @@ window.auth = (function () {
console.info("Device authentication saved");
});
console.info("Generating new device authentication ID", registrationInfo);
register();
}
});

exports.getDeviceId = function () {
return registrationInfo && registrationInfo.deviceId;
};

function generateRegistrationInfo() {
let info = {
deviceId: "anon" + makeUuid() + "",
Expand Down

0 comments on commit 6adbfea

Please sign in to comment.