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

prevent tracking localhost #57

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

kandros
Copy link
Contributor

@kandros kandros commented Apr 3, 2024

fixes #50

I opted for skipping sending the request instead of rejecting it in collectRequestHandler Does it cover your usecase @benvinegar?

@benvinegar
Copy link
Owner

benvinegar commented Apr 4, 2024

First off, thank you for picking up an issue and contributing. 🙏

Does it cover your usecase @benvinegar?

Some thoughts that come to mind:

  • It should probably account for 127.0.0.1 too.
  • The behavior probably shouldn't be hard-coded – as in, it should be possible to disable the behavior and allow localhost traffic through some kind of configuration variable specified on the client.

You're welcome to try adding that; if you do, I'd look at prior art from other analytics tracking scripts and see what other folks do. For example, Plausible had a ticket around this and has since made it possible to track local scripts.

All of this makes the issue more complicated than at first blush (my fault for not clarifying more).

@xuelink
Copy link
Contributor

xuelink commented Apr 14, 2024

@kandros I think updating it with this condition, gonna fix all possible localhost scenarios

if (/^localhost$|^127(?:\.[0-9]+){0,2}\.[0-9]+$|^(?:0*\:)*?:?0*1$/.test(window.location.hostname)) {
    console.warn("[counterscale] localhost detected, datapoints will not be collected");
    return;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Reject stats from localhost by default
3 participants