-
Notifications
You must be signed in to change notification settings - Fork 27
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
Request Bodies with "o" Object Should be Encoded #93
Comments
|
actually i think f = {
o: encodeURI(d),
sv: "0.1.2",
sdkn: null != (r = null == t ? void 0 : t.getAttribute("data-sdkn")) ? r : void 0,
sdkv: null != (l = null == t ? void 0 : t.getAttribute("data-sdkv")) ? l : void 0,
ts: Date.now(),
...null != a && a.withReferrer && !s ? {
r: u
} : {},
..."event" === i && o && {
en: o.name,
ed: o.data
}
}; would be best |
Hey @danielcliu-ifixit! I don't think that we should use My question is: why do you have the unencoded character in the URL in the first place? One possible solution would be to use <Analytics beforeSend={(event) => {
if(event.url.includes("exampleVercelError") {
return {
...event,
url: encodeURI(event.url)
}
}
return event;
}
} /> Let me know what you think! |
The curly brace is being added by another analytics package (matomo). Maybe it could be encoded, but as far as I can tell, urls with curly braces in the query strings are still valid. The page doesn't seem to have a problem loading, so it seems odd that vercel analytics would decide that our url is invalid. I agree double-encoding the url isn't the right answer, but the real problem is that the analytics api gives a 400 on a valid url because the uri validator is not conforming to the url spec. https://url.spec.whatwg.org/#query-percent-encode-set A fix to that validator should resolve this issue. |
Thanks for bringing that up. |
@tobiaslins thanks for the fix! My issue seems to be resolved. |
Overview
I'm assuming this is the correct repo to write an issue found within
/_vercel/insights/script.js
. If not please let me know or point me in the right direction.in
script.js
we make a fetch call to/_vercel/insights/
endpoints like sohowever the body
f
is defined byand
d = location.href
. The reason this is an issue is the/_vercel/insights/
endpoints seem to anticipate thato
is already encoded, and if its not returns an error that looks like{"statusCode":400,"error":"Bad Request","message":"body/href must match format \"uri\""}
.If you want to see evidence of this error you can search "vercel" requests in dev tools -> network when visiting a page like
https://www.ifixit.com/products/galaxy-note10-plus-replacement-battery?exampleVercelError={hello}
whereas
https://www.ifixit.com/products/galaxy-note10-plus-replacement-battery?exampleVercelError=hello has those vercel calls work fine.
Proposed Solution
I think that
body: JSON.stringify(encodeURI(f))
should solve this issue, or maybe getting the uri and then runningencodeURIComponent
on the params etc. Or if you have access to the vitals API endpoints code you can make it encode expected URIs on the server side, because I notice the same error occurring for thebody
key-valuehref
for calls tohttps://vitals.vercel-insights.com/v1/vitals
The text was updated successfully, but these errors were encountered: