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

bug: default value of user-agent flagged as bot by is-bot #1

Open
manuel-rw opened this issue May 20, 2024 · 0 comments
Open

bug: default value of user-agent flagged as bot by is-bot #1

manuel-rw opened this issue May 20, 2024 · 0 comments

Comments

@manuel-rw
Copy link

manuel-rw commented May 20, 2024

Hello,
I am using Umami to send some data from a server side Node.js application.
This applications uses @umami/node to send track data to the Umami instance.
Some example code for this:

const umamiInstance = new Umami();

umamiInstance.init({
  hostURL: UMAMI_HOST_URL,
  websiteId: UMAMI_WEBSITE_ID
});

await umamiInstance.track('my-event', {
  "exampleKey": "exampleValue"
});

The track() function returns a Response from the fetch:

node/index.ts

Lines 41 to 48 in 9331047

return fetch(`${hostUrl}/api/send`, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'User-Agent': `Mozilla/5.0 Node/${process.version}`,
},
body: JSON.stringify({ type, payload }),
});

I noticed that no matter what I configured, my Umami track events were not showing up in Umami.
So I decided to dig a bit in the code and found a potentially unwanted behaviour / default value.

In the Umami server, there are multiple paths for the runtime to go:

https://github.com/umami-software/umami/blob/7a75639dd3d7aeff46104b71ebfb3853fc0eee09/src/pages/api/send.ts#L85-L100

One of them is the bot check that will fail silently if the request is being detected as a bot by the is-bot package.
The default value of your library here is Mozilla/5.0 Node/${process.version} -> the variable interpolation doesn't matter in this case:

node/index.ts

Line 45 in 9331047

'User-Agent': `Mozilla/5.0 Node/${process.version}`,

is-bot detects this as a bot and will therefore return true on the check:
image

Therefore, Umami will silently drop this track event without log message or any indications why it failed. Additionally, the 200 status code indicates that the request was successful (which it wasn't).

A possible workaround is to set the undocumented variable DISABLE_BOT_CHECK to true - but this disables the check entirely.
It would be favorable if this library has a different user agent as the default value or supports setting a custom agent.

If Umami thinks that this is intended behavior, please add a log warning to Umami server.

The commit 9331047 has not changed this problem, because the regex from is-bot will match either user agent.

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

No branches or pull requests

1 participant