Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Don't track hash params by default #1391

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

benjackwhite
Copy link
Collaborator

@benjackwhite benjackwhite commented Aug 29, 2024

Changes

Hash params are typically not necessary to be tracked and often even undeseriable as they can be used for storing tokens etc. that never leave the browser.

I don't think we should track these by default. This is technically a breaking change so a little hard to guage but I strongly feel like the default should be not to track

We probably want to offer a config option to allow this...

Checklist

  • Tests for new code (see advice on the tests we use)
  • Accounted for the impact of any changes across different browsers
  • Accounted for backwards compatibility of any changes (no breaking changes in posthog-js!)

Copy link

vercel bot commented Aug 29, 2024

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated (UTC)
posthog-js ✅ Ready (Inspect) Visit Preview Aug 29, 2024 7:50am

Copy link

github-actions bot commented Aug 29, 2024

Size Change: +770 B (+0.07%)

Total Size: 1.17 MB

Filename Size Change
dist/array.full.js 335 kB +188 B (+0.06%)
dist/array.js 155 kB +194 B (+0.13%)
dist/main.js 156 kB +194 B (+0.12%)
dist/module.js 155 kB +194 B (+0.13%)
ℹ️ View Unchanged
Filename Size
dist/exception-autocapture.js 10.4 kB
dist/recorder-v2.js 110 kB
dist/recorder.js 110 kB
dist/surveys-preview.js 59.8 kB
dist/surveys.js 66 kB
dist/tracing-headers.js 8.26 kB
dist/web-vitals.js 5.79 kB

compressed-size-action

@marandaneto
Copy link
Member

I recall people complaining (in the past) about query params as well, so masking query param values would be also good, eg:

function maskUrl(url: string): string {
    try {
        const parsedUrl = new URL(url);

        parsedUrl.searchParams.forEach((_, key) => {
            parsedUrl.searchParams.set(key, 'masked');
        });

        if (parsedUrl.hash) {
            parsedUrl.hash = 'masked';
        }

        return parsedUrl.toString();
    } catch (e) {
        console.error("Invalid URL provided:", e);
        return url;
    }
}

const originalUrl = "https://www.google.com?query=123&login=true#456";
const maskedUrl = maskUrl(originalUrl);
console.log(maskedUrl); // "https://www.google.com/?query=masked&login=masked#masked"

Not a blocker for this PR, just remembering that I had to do something like this in the past.

@@ -32,6 +32,16 @@ export const CAMPAIGN_PARAMS = [
]

export const Info = {
Copy link
Member

Choose a reason for hiding this comment

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

I know it's not this PR but "info" makes me sad 🤣
we should rename it "misc" :p

return {
// NOTE: Hash params are typically sensitive and not designed to be sent to servers so we exclude them here by default
href: location?.href?.split('#')[0],
hrefIncludingHash: location?.href,
Copy link
Member

Choose a reason for hiding this comment

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

almost feels like we should capture the hash params separately so that if folk really want them they can capture them

instead of having href and hash

I don't think that massively affects queries so no strong opinion but would sit nicely to have query_params, pathname, and hash_params as separate things

(no need to take that as blocking here i think generally we could do with better url handling)

Copy link
Member

@pauldambra pauldambra left a comment

Choose a reason for hiding this comment

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

agree it would be nice for this to be configurable...
arguably if we allow the config we should add a scrub function so folk can capture via allowlist or denylist so they don't capture sensitive info unless they really want to

since it looks like hash params are not being queried for by many folk we can probably not take on the complexity now and ask them if they need it and add it on demand

@benjackwhite
Copy link
Collaborator Author

agree it would be nice for this to be configurable... arguably if we allow the config we should add a scrub function so folk can capture via allowlist or denylist so they don't capture sensitive info unless they really want to

since it looks like hash params are not being queried for by many folk we can probably not take on the complexity now and ask them if they need it and add it on demand

I feel like this isn't specific to URLs. We should just have a hook for people to hook into and modify the final captured event payload. That way they can do whatever level of modifications they want and avoids the need for more and more complex config options tbh...

@pauldambra
Copy link
Member

We should just have a hook for people to hook into and modify the final captured event payload. That way they can do whatever level of modifications they want and avoids the need for more and more complex config options tbh...

+100 🧠

@robbie-c
Copy link
Contributor

We should just have a hook for people to hook into and modify the final captured event payload. That way they can do whatever level of modifications they want and avoids the need for more and more complex config options tbh...

I'm in favour of this too. This would be cool:

import {stripQueryParams, stripProperties} from "@posthog/js-transforms"

posthog.init("my-token", {
  transforms: [
    stripQueryParams(["some-oauth-token", "some-ad-id"]),
    stripProperties(["$browser"])
  ]
}

@posthog-bot
Copy link
Collaborator

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@posthog-bot
Copy link
Collaborator

This PR hasn't seen activity in a week! Should it be merged, closed, or further worked on? If you want to keep it open, post a comment or remove the stale label – otherwise this will be closed in another week.

@benjackwhite benjackwhite added bump minor Bump minor version when this PR gets merged and removed stale labels Sep 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bump minor Bump minor version when this PR gets merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants