Skip to content

📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!

fix: Escape query names before returning tooltip HTML to prevent XSS

Blue Mouse978b65832949
diff --git a/web/app/pages/Project/tabs/SEO/SEOView.tsx b/web/app/pages/Project/tabs/SEO/SEOView.tsx
index bef52806c..4ba73e84a 100644
--- a/web/app/pages/Project/tabs/SEO/SEOView.tsx
+++ b/web/app/pages/Project/tabs/SEO/SEOView.tsx
@@ -59,7 +59,7 @@ import Dropdown from '~/ui/Dropdown'
import Loader from '~/ui/Loader'
import { Text } from '~/ui/Text'
import Tooltip from '~/ui/Tooltip'
-import { nFormatter } from '~/utils/generic'
+import { escapeHtml, nFormatter } from '~/utils/generic'
import countries from '~/utils/isoCountries'
import { getSearchEngineReferrals, getAIReferrals } from '~/utils/referrers'
import routes from '~/utils/routes'
@@ -725,7 +725,7 @@ const SEOViewInner = ({ projectId, tnMapping }: SEOViewProps) => {
const imp = impressions[d.index]
return `<ul class='bg-gray-50 dark:text-gray-50 dark:bg-slate-900 rounded-md ring-1 ring-black/10 px-2 py-1 text-xs md:text-sm shadow-md z-50'>
- <li class='font-semibold pb-1 mb-1 border-b border-gray-200 dark:border-slate-800 break-all'>${name}</li>
+ <li class='font-semibold pb-1 mb-1 border-b border-gray-200 dark:border-slate-800 break-all'>${escapeHtml(name ?? '')}</li>
<li class='flex justify-between items-center py-px leading-snug'>
<span class='mr-4'>${t('project.seo.position')}:</span>
<span class='font-mono whitespace-nowrap'>${d.x.toFixed(1)}</span>
diff --git a/web/app/utils/generic.ts b/web/app/utils/generic.ts
index 84ebe93c5..e5a82cbb8 100644
--- a/web/app/utils/generic.ts
+++ b/web/app/utils/generic.ts
@@ -158,3 +158,12 @@ export const delay = (ms: number) =>
export const cn = (...args: ClassValue[]) => {
return twMerge(clsx(args))
}
+
+export const escapeHtml = (unsafe: string): string => {
+ return unsafe
+ .replace(/&/g, '&amp;')
+ .replace(/</g, '&lt;')
+ .replace(/>/g, '&gt;')
+ .replace(/"/g, '&quot;')
+ .replace(/'/g, '&#39;')
+}
diff --git a/web/app/utils/toc.ts b/web/app/utils/toc.ts
index 595a98cdc..c25cb6dbf 100644
--- a/web/app/utils/toc.ts
+++ b/web/app/utils/toc.ts
@@ -5,14 +5,7 @@ interface TocItem {
children: TocItem[]
}
-function escapeHtml(unsafe: string): string {
- return unsafe
- .replace(/&/g, '&amp;')
- .replace(/</g, '&lt;')
- .replace(/>/g, '&gt;')
- .replace(/"/g, '&quot;')
- .replace(/'/g, '&#39;')
-}
+import { escapeHtml } from './generic'
function stripHtmlTags(input: string): string {
const tagRegex = /<[^>]*>/g