Skip to content

Commit 5615e50

Browse files
POR-22460: Filter cross-origin history SecurityError noise from Sentry
Add shared browser Sentry ignore patterns for history API instrumentation noise, including NS Pushstate prevention and cross-origin replaceState SecurityErrors seen during portal OAuth/login redirects. Co-authored-by: Neil Raina <makeitraina@users.noreply.github.com>
1 parent 8f63a1b commit 5615e50

3 files changed

Lines changed: 43 additions & 1 deletion

File tree

src/instrumentation-client.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import * as Sentry from '@sentry/nextjs'
66

7+
import { browserSentryIgnoredErrors } from '@/utils/sentryIgnoredErrors'
8+
79
const dsn = process.env.NEXT_PUBLIC_SENTRY_DSN || process.env.SENTRY_DSN
810
const vercelEnv = process.env.NEXT_PUBLIC_VERCEL_ENV
911
const isProd = process.env.NEXT_PUBLIC_VERCEL_ENV === 'production'
@@ -33,7 +35,7 @@ if (dsn) {
3335
// }),
3436
],
3537

36-
ignoreErrors: [/fetch failed/i, /failed to fetch/i],
38+
ignoreErrors: browserSentryIgnoredErrors,
3739

3840
beforeSend(event) {
3941
if (!isProd && event.type === undefined) {
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { isIgnoredBrowserSentryError } from './sentryIgnoredErrors'
2+
3+
describe('isIgnoredBrowserSentryError', () => {
4+
it('ignores browser history pushState instrumentation noise', () => {
5+
expect(isIgnoredBrowserSentryError('Error: NS Pushstate prevention')).toBe(true)
6+
expect(isIgnoredBrowserSentryError('ns pushstate prevention')).toBe(true)
7+
})
8+
9+
it('ignores cross-origin history replaceState security errors', () => {
10+
expect(
11+
isIgnoredBrowserSentryError(
12+
'SecurityError: Blocked attempt to use history.replaceState() to change session history URL from https://help.kudzu.digital/login?step=signIn to https://auth.copilot.app/auth/google/callback.',
13+
),
14+
).toBe(true)
15+
expect(
16+
isIgnoredBrowserSentryError(
17+
'SecurityError: Blocked attempt to use history.pushState() to change session history URL from https://portal.example.com/login to https://auth.copilot.app/auth/google/callback.',
18+
),
19+
).toBe(true)
20+
})
21+
22+
it('keeps ignoring generic browser fetch failures', () => {
23+
expect(isIgnoredBrowserSentryError('TypeError: Failed to fetch')).toBe(true)
24+
expect(isIgnoredBrowserSentryError('Error: fetch failed')).toBe(true)
25+
})
26+
27+
it('does not ignore unrelated application errors', () => {
28+
expect(isIgnoredBrowserSentryError('Error: Unable to create task')).toBe(false)
29+
})
30+
})

src/utils/sentryIgnoredErrors.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
export const browserSentryIgnoredErrors = [
2+
/fetch failed/i,
3+
/failed to fetch/i,
4+
/NS Pushstate prevention/i,
5+
/Blocked attempt to use history\.(replace|push)State\(\)/i,
6+
]
7+
8+
export function isIgnoredBrowserSentryError(errorMessage: string) {
9+
return browserSentryIgnoredErrors.some((ignoredError) => ignoredError.test(errorMessage))
10+
}

0 commit comments

Comments
 (0)