Commit fcc6a2d5 authored by Vignesh Mohankumar's avatar Vignesh Mohankumar Committed by GitHub

fix: filter out all `unsafe-eval` csp errors (#6409)

* update match

* Update src/tracing/errors.ts
Co-authored-by: default avatarZach Pomerantz <zzmp@uniswap.org>

* lint

* add test

---------
parent 98841c78
...@@ -8,6 +8,11 @@ describe('filterKnownErrors', () => { ...@@ -8,6 +8,11 @@ describe('filterKnownErrors', () => {
expect(filterKnownErrors(ERROR, {})).toBe(ERROR) expect(filterKnownErrors(ERROR, {})).toBe(ERROR)
}) })
it('propagates an error with generic text', () => {
const originalException = new Error('generic error copy')
expect(filterKnownErrors(ERROR, { originalException })).toBe(ERROR)
})
it('filters block number polling errors', () => { it('filters block number polling errors', () => {
const originalException = new (class extends Error { const originalException = new (class extends Error {
requestBody = JSON.stringify({ method: 'eth_blockNumber' }) requestBody = JSON.stringify({ method: 'eth_blockNumber' })
...@@ -30,10 +35,19 @@ describe('filterKnownErrors', () => { ...@@ -30,10 +35,19 @@ describe('filterKnownErrors', () => {
expect(filterKnownErrors(ERROR, { originalException })).toBe(null) expect(filterKnownErrors(ERROR, { originalException })).toBe(null)
}) })
it('filters CSP unsafe-eval errors', () => { describe('Content Security Policy', () => {
const originalException = new Error( it('filters unsafe-eval evaluate errors', () => {
"Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' https://www.google-analytics.com https://www.googletagmanager.com 'unsafe-inlin..." const originalException = new Error(
) "Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' https://www.google-analytics.com https://www.googletagmanager.com 'unsafe-inlin..."
expect(filterKnownErrors(ERROR, { originalException })).toBe(null) )
expect(filterKnownErrors(ERROR, { originalException })).toBe(null)
})
it('filters CSP unsafe-eval compile/instatiate errors', () => {
const originalException = new Error(
"Refused to compile or instantiate WebAssembly module because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive: \"script-src 'self' https://www.google-a..."
)
expect(filterKnownErrors(ERROR, { originalException })).toBe(null)
})
}) })
}) })
...@@ -52,11 +52,7 @@ export const filterKnownErrors: Required<ClientOptions>['beforeSend'] = (event: ...@@ -52,11 +52,7 @@ export const filterKnownErrors: Required<ClientOptions>['beforeSend'] = (event:
* For example, if a user runs an eval statement in console this error would still get thrown. * For example, if a user runs an eval statement in console this error would still get thrown.
* TODO(INFRA-176): We should extend this to filter out any type of CSP error. * TODO(INFRA-176): We should extend this to filter out any type of CSP error.
*/ */
if ( if (error.message.match(/'unsafe-eval'.*content security policy/i)) {
error.message.match(
/Refused to evaluate a string as JavaScript because 'unsafe-eval' is not an allowed source of script in the following Content Security Policy directive/
)
) {
return null return null
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment