Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Track actual window location origin and hash #1853

Merged
merged 9 commits into from
Apr 26, 2018
19 changes: 15 additions & 4 deletions src/Analytics.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,24 @@ import SdkConfig, { DEFAULTS } from './SdkConfig';
import Modal from './Modal';
import sdk from './index';

function getRedactedHash() {
return window.location.hash.replace(/#\/(group|room|user)\/(.+)/, "#/$1/<redacted>");
const hashRegex = /#\/(groups?|room|user|settings|register|login|forgot_password|home|directory)/;

// Remove all but the first item in the hash path. Redact unexpected hashes.
function getRedactedHash(hash) {
// Don't leak URLs we aren't expecting - they could contain tokens/PPI
const match = hashRegex.exec(hash);
if (!match) {
console.warn(`Unexpected hash location "${hash}"`);
return '#/<unexpected hash location>';
}

return hash.replace(hashRegex, "#/$1");
}

// Return the current origin and hash separated with a `/`. This does not include query parameters.
function getRedactedUrl() {
// hardcoded url to make piwik happy
return 'https://riot.im/app/' + getRedactedHash();
const { origin, hash } = window.location;
return origin + '/' + getRedactedHash(hash);
}

const customVariables = {
Expand Down