From fb94bdf905275c14e32e1b367c4567769c40400d Mon Sep 17 00:00:00 2001 From: Sam Mason de Caires Date: Tue, 17 Nov 2026 11:54:06 +0000 Subject: [PATCH 1/2] feat: harden Amplitude config and add CSP report-only header Disable Amplitude remote config, custom enrichment and unused autocapture features so SDK upgrades or dashboard changes can't enable code loading. Serve a Content-Security-Policy-Report-Only header (non-static builds) with an explicit allowlist for RPCs, wallet providers and app services. Reports go to CSP_REPORT_URI when set. Co-Authored-By: Claude Opus 5.5 --- .env.example | 2 + csp.config.js | 133 ++++++++++++++++++++++++++++++++++++ next.config.js | 11 +++ src/store/analyticsSlice.ts | 22 +++++- 4 files changed, 167 insertions(+), 1 deletion(-) create mode 100644 csp.config.js diff --git a/.env.example b/.env.example index 5f0dcb804a..760ca35ff0 100644 --- a/.env.example +++ b/.env.example @@ -56,6 +56,8 @@ PLAIN_API_KEY= COMPLIANCE_API_URL= COMPLIANCE_SECRET= SENTRY_AUTH_TOKEN= +# Where browsers send CSP report-only violations (e.g. Sentry security endpoint), read at build time +CSP_REPORT_URI= # Gas-sponsored voting relay (server-side only, never exposed to the client) VOTE_RELAY_URL=https://governance-cache-api.aave.com/relay VOTE_RELAY_API_KEY= diff --git a/csp.config.js b/csp.config.js new file mode 100644 index 0000000000..5fca8d356a --- /dev/null +++ b/csp.config.js @@ -0,0 +1,133 @@ +// Content Security Policy, served as `Content-Security-Policy-Report-Only`. +// +// Report-only: browsers never block anything, they only report requests that fall outside this +// allowlist. The reports tell us what still needs adding and when enforcement would be safe. +// Connections are listed explicitly (rather than `https:`) so unknown origins show up in reports. +// +// Reports go to CSP_REPORT_URI (e.g. Sentry's security endpoint for the aave-v3 project). Without +// it the header is still sent, so violations show in the browser console during development. + +const isDev = process.env.NODE_ENV === 'development'; + +const rpcs = [ + '*.publicnode.com', + '*.drpc.org', + '*.tenderly.co', + '*.blockpi.network', + '*.quiknode.pro', + 'rpc.ankr.com', + 'rpc.flashbots.net', + 'public-op-mainnet.fastnode.io', + 'arb1.arbitrum.io', + 'sepolia-rollup.arbitrum.io', + 'api.avax.network', + 'api.avax-test.network', + 'mainnet.base.org', + 'sepolia.base.org', + 'sepolia.optimism.io', + 'rpc.gnosischain.com', + 'andromeda.metis.io', + 'mainnet.era.zksync.io', + 'rpc.scroll.io', + 'sepolia-rpc.scroll.io', + 'rpc.mantle.xyz', + 'rpc.soniclabs.com', + 'rpc.soneium.org', + 'rpc.xlayer.tech', + 'rpc.plasma.to', + 'rpc.monad.xyz', + 'rpc1.monad.xyz', + 'mainnet.megaeth.com', +]; + +const wallets = [ + // WalletConnect / Reown relay, verify and explorer + '*.walletconnect.com', + 'wss://*.walletconnect.com', + '*.walletconnect.org', + 'wss://*.walletconnect.org', + '*.reown.com', + 'wss://*.reown.com', + // Coinbase Wallet SDK + '*.coinbase.com', + 'wss://*.coinbase.com', + // Family (ConnectKit) and Fun (@funkit/connect, which uses Relay and reports to Datadog) + '*.family.co', + '*.fun.xyz', + '*.relay.link', + 'browser-intake-datadoghq.com', + // Safe{Wallet} when running as a Safe App + '*.safe.global', +]; + +const services = [ + '*.aave.com', + 'wss://*.aave.com', + // Analytics and error reporting + '*.amplitude.com', + '*.sentry.io', + // Market data, rewards, swaps, bridging, on-ramp, identity + '*.coingecko.com', + '*.merkl.xyz', + '*.cow.fi', + '*.paraswap.io', + '*.velora.xyz', + 'ccip.chain.link', + 'apps.aavechan.com', + '*.transak.com', + 'wss://*.transak.com', + '*.self.xyz', + '*.thegraph.com', + 'tokenlogic-data.ddn.hasura.app', + 'metisapi.0xgraph.xyz', + 'metadata.ens.domains', + 'raw.githubusercontent.com', +]; + +const withScheme = (source) => (source.includes('://') ? source : `https://${source}`); + +const directives = { + 'default-src': ["'self'"], + 'script-src': ["'self'", "'wasm-unsafe-eval'", ...(isDev ? ["'unsafe-eval'"] : [])], + // Emotion/MUI inject styles at runtime + 'style-src': ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'], + 'font-src': ["'self'", 'data:', 'https://fonts.gstatic.com'], + // Token, reward and wallet icons come from many hosts; tighten once reports show the set. + 'img-src': ["'self'", 'data:', 'blob:', 'https:'], + 'connect-src': [ + "'self'", + ...[...rpcs, ...wallets, ...services].map(withScheme), + ...(isDev ? ['ws://localhost:*', 'http://localhost:*', 'http://127.0.0.1:*'] : []), + ], + 'frame-src': [ + "'self'", + 'https://verify.walletconnect.com', + 'https://verify.walletconnect.org', + 'https://*.transak.com', + 'https://*.family.co', + 'https://*.fun.xyz', + ], + 'worker-src': ["'self'", 'blob:'], + 'object-src': ["'none'"], + 'base-uri': ["'self'"], + 'form-action': ["'self'"], + // No frame-ancestors: the app is embedded by Safe{Wallet} and other wallet hosts. +}; + +function getCspHeaders() { + const reportUri = process.env.CSP_REPORT_URI; + const policy = Object.entries(directives).map( + ([name, sources]) => `${name} ${sources.join(' ')}` + ); + const headers = []; + + if (reportUri) { + policy.push(`report-uri ${reportUri}`, 'report-to csp-endpoint'); + headers.push({ key: 'Reporting-Endpoints', value: `csp-endpoint="${reportUri}"` }); + } + + headers.push({ key: 'Content-Security-Policy-Report-Only', value: policy.join('; ') }); + return headers; +} + +module.exports = { getCspHeaders }; diff --git a/next.config.js b/next.config.js index 5ed951774f..79fccbd548 100644 --- a/next.config.js +++ b/next.config.js @@ -1,5 +1,8 @@ const { withSentryConfig } = require('@sentry/nextjs'); +// eslint-disable-next-line +const { getCspHeaders } = require('./csp.config'); + // eslint-disable-next-line const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', @@ -52,6 +55,14 @@ module.exports = withSentryConfig( ...(process.env.STATIC_EXPORT === 'true' ? { output: 'export' } : {}), trailingSlash: true, pageExtensions, + // Custom headers aren't applied to a static export, so the IPFS build ships without CSP. + ...(process.env.STATIC_EXPORT === 'true' + ? {} + : { + async headers() { + return [{ source: '/:path*', headers: getCspHeaders() }]; + }, + }), // NOTE: Needed for SAFE testing locally // async headers() { // return [ diff --git a/src/store/analyticsSlice.ts b/src/store/analyticsSlice.ts index b95d2d69ed..9ba6a3a744 100644 --- a/src/store/analyticsSlice.ts +++ b/src/store/analyticsSlice.ts @@ -21,6 +21,13 @@ const createAppContextPlugin = (context: string) => ({ const AMPLITUDE_API_KEY = process.env.NEXT_PUBLIC_AMPLITUDE_API_KEY || ''; +// Remote config can be downloaded and partly executed as code, and custom enrichment loads +// scripts from Amplitude's CDN. Neither is used, so keep them off regardless of SDK defaults. +const AMPLITUDE_HARDENED_OPTIONS = { + fetchRemoteConfig: false, + customEnrichment: false, +} as const; + // Consent version - increment this to force all users to re-consent const CONSENT_VERSION = 'v1'; export const CONSENT_KEY = `userAcceptedAnalytics_${CONSENT_VERSION}`; @@ -92,7 +99,18 @@ export const createAnalyticsSlice: StateCreator< if (!isInitialized) { init(AMPLITUDE_API_KEY, { // serverZone: 'EU', - autocapture: true, // disable if we don't want to capture every click and page view on the site + autocapture: { + attribution: true, + pageViews: true, + sessions: true, + elementInteractions: false, + formInteractions: false, + fileDownloads: false, + frustrationInteractions: false, + networkTracking: false, + webVitals: false, + }, + ...AMPLITUDE_HARDENED_OPTIONS, trackingOptions: { ipAddress: true, language: true, @@ -110,6 +128,7 @@ export const createAnalyticsSlice: StateCreator< init(AMPLITUDE_API_KEY, { // serverZone: 'EU', autocapture: false, + ...AMPLITUDE_HARDENED_OPTIONS, trackingOptions: { ipAddress: false, language: false, @@ -150,6 +169,7 @@ export const createAnalyticsSlice: StateCreator< // Initialize minimal tracking just for this one event init(AMPLITUDE_API_KEY, { autocapture: false, + ...AMPLITUDE_HARDENED_OPTIONS, trackingOptions: { ipAddress: false, language: false, From 4ed45eee60a9d8e3080d1302d49c9103822e9d24 Mon Sep 17 00:00:00 2001 From: Sam Mason de Caires Date: Tue, 17 Nov 2026 12:04:44 +0000 Subject: [PATCH 2/2] chore: drop CSP header, managed in Cloudflare instead Co-Authored-By: Claude Opus 5.5 --- .env.example | 2 - csp.config.js | 133 ------------------------------------------------- next.config.js | 11 ---- 3 files changed, 146 deletions(-) delete mode 100644 csp.config.js diff --git a/.env.example b/.env.example index 760ca35ff0..5f0dcb804a 100644 --- a/.env.example +++ b/.env.example @@ -56,8 +56,6 @@ PLAIN_API_KEY= COMPLIANCE_API_URL= COMPLIANCE_SECRET= SENTRY_AUTH_TOKEN= -# Where browsers send CSP report-only violations (e.g. Sentry security endpoint), read at build time -CSP_REPORT_URI= # Gas-sponsored voting relay (server-side only, never exposed to the client) VOTE_RELAY_URL=https://governance-cache-api.aave.com/relay VOTE_RELAY_API_KEY= diff --git a/csp.config.js b/csp.config.js deleted file mode 100644 index 5fca8d356a..0000000000 --- a/csp.config.js +++ /dev/null @@ -1,133 +0,0 @@ -// Content Security Policy, served as `Content-Security-Policy-Report-Only`. -// -// Report-only: browsers never block anything, they only report requests that fall outside this -// allowlist. The reports tell us what still needs adding and when enforcement would be safe. -// Connections are listed explicitly (rather than `https:`) so unknown origins show up in reports. -// -// Reports go to CSP_REPORT_URI (e.g. Sentry's security endpoint for the aave-v3 project). Without -// it the header is still sent, so violations show in the browser console during development. - -const isDev = process.env.NODE_ENV === 'development'; - -const rpcs = [ - '*.publicnode.com', - '*.drpc.org', - '*.tenderly.co', - '*.blockpi.network', - '*.quiknode.pro', - 'rpc.ankr.com', - 'rpc.flashbots.net', - 'public-op-mainnet.fastnode.io', - 'arb1.arbitrum.io', - 'sepolia-rollup.arbitrum.io', - 'api.avax.network', - 'api.avax-test.network', - 'mainnet.base.org', - 'sepolia.base.org', - 'sepolia.optimism.io', - 'rpc.gnosischain.com', - 'andromeda.metis.io', - 'mainnet.era.zksync.io', - 'rpc.scroll.io', - 'sepolia-rpc.scroll.io', - 'rpc.mantle.xyz', - 'rpc.soniclabs.com', - 'rpc.soneium.org', - 'rpc.xlayer.tech', - 'rpc.plasma.to', - 'rpc.monad.xyz', - 'rpc1.monad.xyz', - 'mainnet.megaeth.com', -]; - -const wallets = [ - // WalletConnect / Reown relay, verify and explorer - '*.walletconnect.com', - 'wss://*.walletconnect.com', - '*.walletconnect.org', - 'wss://*.walletconnect.org', - '*.reown.com', - 'wss://*.reown.com', - // Coinbase Wallet SDK - '*.coinbase.com', - 'wss://*.coinbase.com', - // Family (ConnectKit) and Fun (@funkit/connect, which uses Relay and reports to Datadog) - '*.family.co', - '*.fun.xyz', - '*.relay.link', - 'browser-intake-datadoghq.com', - // Safe{Wallet} when running as a Safe App - '*.safe.global', -]; - -const services = [ - '*.aave.com', - 'wss://*.aave.com', - // Analytics and error reporting - '*.amplitude.com', - '*.sentry.io', - // Market data, rewards, swaps, bridging, on-ramp, identity - '*.coingecko.com', - '*.merkl.xyz', - '*.cow.fi', - '*.paraswap.io', - '*.velora.xyz', - 'ccip.chain.link', - 'apps.aavechan.com', - '*.transak.com', - 'wss://*.transak.com', - '*.self.xyz', - '*.thegraph.com', - 'tokenlogic-data.ddn.hasura.app', - 'metisapi.0xgraph.xyz', - 'metadata.ens.domains', - 'raw.githubusercontent.com', -]; - -const withScheme = (source) => (source.includes('://') ? source : `https://${source}`); - -const directives = { - 'default-src': ["'self'"], - 'script-src': ["'self'", "'wasm-unsafe-eval'", ...(isDev ? ["'unsafe-eval'"] : [])], - // Emotion/MUI inject styles at runtime - 'style-src': ["'self'", "'unsafe-inline'", 'https://fonts.googleapis.com'], - 'font-src': ["'self'", 'data:', 'https://fonts.gstatic.com'], - // Token, reward and wallet icons come from many hosts; tighten once reports show the set. - 'img-src': ["'self'", 'data:', 'blob:', 'https:'], - 'connect-src': [ - "'self'", - ...[...rpcs, ...wallets, ...services].map(withScheme), - ...(isDev ? ['ws://localhost:*', 'http://localhost:*', 'http://127.0.0.1:*'] : []), - ], - 'frame-src': [ - "'self'", - 'https://verify.walletconnect.com', - 'https://verify.walletconnect.org', - 'https://*.transak.com', - 'https://*.family.co', - 'https://*.fun.xyz', - ], - 'worker-src': ["'self'", 'blob:'], - 'object-src': ["'none'"], - 'base-uri': ["'self'"], - 'form-action': ["'self'"], - // No frame-ancestors: the app is embedded by Safe{Wallet} and other wallet hosts. -}; - -function getCspHeaders() { - const reportUri = process.env.CSP_REPORT_URI; - const policy = Object.entries(directives).map( - ([name, sources]) => `${name} ${sources.join(' ')}` - ); - const headers = []; - - if (reportUri) { - policy.push(`report-uri ${reportUri}`, 'report-to csp-endpoint'); - headers.push({ key: 'Reporting-Endpoints', value: `csp-endpoint="${reportUri}"` }); - } - - headers.push({ key: 'Content-Security-Policy-Report-Only', value: policy.join('; ') }); - return headers; -} - -module.exports = { getCspHeaders }; diff --git a/next.config.js b/next.config.js index 79fccbd548..5ed951774f 100644 --- a/next.config.js +++ b/next.config.js @@ -1,8 +1,5 @@ const { withSentryConfig } = require('@sentry/nextjs'); -// eslint-disable-next-line -const { getCspHeaders } = require('./csp.config'); - // eslint-disable-next-line const withBundleAnalyzer = require('@next/bundle-analyzer')({ enabled: process.env.ANALYZE === 'true', @@ -55,14 +52,6 @@ module.exports = withSentryConfig( ...(process.env.STATIC_EXPORT === 'true' ? { output: 'export' } : {}), trailingSlash: true, pageExtensions, - // Custom headers aren't applied to a static export, so the IPFS build ships without CSP. - ...(process.env.STATIC_EXPORT === 'true' - ? {} - : { - async headers() { - return [{ source: '/:path*', headers: getCspHeaders() }]; - }, - }), // NOTE: Needed for SAFE testing locally // async headers() { // return [