From 3205765083d2fe291f7bd72a1c0872615dbd791c Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Fri, 27 Jul 2018 13:41:41 +0300 Subject: [PATCH 1/2] Seeded random used on obfuscatedCoordinatesImpl --- package.json | 1 + src/util/maps.js | 23 ++++++++++++++++++++--- yarn.lock | 4 ++++ 3 files changed, 25 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index f55215ab..d2af03fc 100644 --- a/package.json +++ b/package.json @@ -47,6 +47,7 @@ "redux": "^4.0.0", "redux-thunk": "^2.2.0", "sanitize.css": "^5.0.0", + "seedrandom": "^2.4.3", "sharetribe-scripts": "1.1.2", "sharetribe-sdk": "https://github.com/sharetribe/sharetribe-sdk-js.git#b7ffe0fe0a5bdb0a1471e2ff36cdd25b997fb39b", "smoothscroll-polyfill": "^0.4.0", diff --git a/src/util/maps.js b/src/util/maps.js index 271fd795..94d95ea3 100644 --- a/src/util/maps.js +++ b/src/util/maps.js @@ -1,10 +1,16 @@ import memoize from 'lodash/memoize'; +import seedrandom from 'seedrandom'; import { types as sdkTypes } from './sdkLoader'; import config from '../config'; const { LatLng } = sdkTypes; -const obfuscatedCoordinatesImpl = latlng => { +/** + * This obfuscatedCoordinatesImpl function is a temporary solution for the coordinate obfuscation. + * In the future, improved version needs to have protectedData working and + * available in accepted transaction. + */ +const obfuscatedCoordinatesImpl = (latlng, cacheKey) => { const { lat, lng } = latlng; const offset = config.coordinates.coordinateOffset; @@ -12,8 +18,19 @@ const obfuscatedCoordinatesImpl = latlng => { const r = offset / 111300; const y0 = lat; const x0 = lng; - const u = Math.random(); - const v = Math.random(); + + // Two seeded random numbers to be used to calculate new location + // We need seeded so that the static map URL doesn't change between requests + // (i.e. URL is cacheable) + const u = cacheKey ? seedrandom(cacheKey)() : Math.random(); + const v = cacheKey + ? seedrandom( + cacheKey + .split('') + .reverse() + .join('') + )() + : Math.random(); const w = r * Math.sqrt(u); const t = 2 * Math.PI * v; const x = w * Math.cos(t); diff --git a/yarn.lock b/yarn.lock index 7009b79a..70ed68cb 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7406,6 +7406,10 @@ scriptjs@^2.5.8: version "2.5.8" resolved "https://registry.yarnpkg.com/scriptjs/-/scriptjs-2.5.8.tgz#d0c43955c2e6bad33b6e4edf7b53b8965aa7ca5f" +seedrandom@^2.4.3: + version "2.4.3" + resolved "https://registry.yarnpkg.com/seedrandom/-/seedrandom-2.4.3.tgz#2438504dad33917314bff18ac4d794f16d6aaecc" + select-hose@^2.0.0: version "2.0.0" resolved "https://registry.yarnpkg.com/select-hose/-/select-hose-2.0.0.tgz#625d8658f865af43ec962bfc376a37359a4994ca" From ff7a2f064051d08a3fb2f22131d6718b6dda1847 Mon Sep 17 00:00:00 2001 From: Vesa Luusua Date: Fri, 27 Jul 2018 13:45:10 +0300 Subject: [PATCH 2/2] Udapte Changelog --- CHANGELOG.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a591e83..20d8a8dd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,10 @@ way to update this template, but currently, we follow a pattern: --- +## Upcoming version +* [change] Use seeded random for client side coordinate obfuscation + [#874](https://github.com/sharetribe/flex-template-web/pull/874) + ## v1.2.2 * [change] Change static map to dynamic map when clicked. [#871](https://github.com/sharetribe/flex-template-web/pull/871)