fix: sanitizePageViewRoute to remove instead of replace

This commit is contained in:
phamhieu authored and Joshen Lim committed 2023-04-20 18:51:52 +07:00
1 parent b08447b424
commit 6c1675129d
1 file changed
+14 -8
+14 -8
View File
@@ -6,15 +6,21 @@ import { useRouter } from 'next/router'
import { FC, useEffect } from 'react'
function sanitizePageViewRoute(_route?: string) {
const hashSplits = _route?.split('#')
if (hashSplits && hashSplits?.length > 1) {
const urlParams = new URLSearchParams(hashSplits[1])
if (urlParams?.get('access_token')) urlParams.set('access_token', 'xxxxx')
if (urlParams?.get('refresh_token')) urlParams.set('refresh_token', 'xxxxx')
if (urlParams?.get('token')) urlParams.set('token', 'xxxxx')
return urlParams?.toString() ?? _route
// remove all fragments
const noFragments = _route?.split('#')[0]
// remove sensitive params
const paramsSplits = noFragments?.split('?')
const hasParams = paramsSplits && paramsSplits?.length > 1
if (hasParams) {
const urlParams = new URLSearchParams(paramsSplits[1])
const sensitiveKeys = [...urlParams.keys()].filter((x) => x.includes('token'))
const sensitiveParams = ['code', ...sensitiveKeys]
sensitiveParams.forEach((name) => urlParams.delete(name))
return `${paramsSplits[0]}?${urlParams?.toString()}`
}
return _route
return noFragments
}
const PageTelemetry: FC = ({ children }) => {