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!

feat: IP whitelist to bypass bot protection

Blue Mouse8ec229e9d910
diff --git a/backend/.env.example b/backend/.env.example
index a50c10c95..3219f6e5f 100644
--- a/backend/.env.example
+++ b/backend/.env.example
@@ -100,6 +100,12 @@ SENTRY_DSN=''
# Default: x-forwarded-for
CLIENT_IP_HEADER=cf-connecting-ip
+# (Cloud) Comma-separated egress IPs of our own relays (web app server-side
+# fetches, managed proxy edge). Requests whose X-Real-IP matches one of these
+# have their visitor IP recovered from X-Forwarded-For (rightmost untrusted
+# hop); all other connections resolve to X-Real-IP itself.
+TRUSTED_PROXY_IPS=
+
# Load balancing
IS_PRIMARY_NODE=true
diff --git a/backend/apps/cloud/src/analytics/bot-detection.service.ts b/backend/apps/cloud/src/analytics/bot-detection.service.ts
index 2485bb6c8..c05da8e4f 100644
--- a/backend/apps/cloud/src/analytics/bot-detection.service.ts
+++ b/backend/apps/cloud/src/analytics/bot-detection.service.ts
@@ -7,6 +7,7 @@ import { parse as parseDomain } from 'tldts'
import { BotsProtectionLevel, Project } from '../project/entity/project.entity'
import { ProjectService } from '../project/project.service'
import { getIPDetails } from '../common/utils'
+import { isIpInRange } from '../common/ip-range'
type BotReason =
| 'user_agent'
@@ -233,6 +234,18 @@ export class BotDetectionService {
if (level === BotsProtectionLevel.OFF) return NEGATIVE
+ // Whitelisted IPs (e.g. customer backends doing server-side tracking)
+ // bypass the entire detection chain.
+ const ipWhitelist = (project.ipWhitelist || []).filter(Boolean)
+
+ if (
+ input.ip &&
+ ipWhitelist.length > 0 &&
+ isIpInRange(input.ip, ipWhitelist)
+ ) {
+ return NEGATIVE
+ }
+
const ua = (input.userAgent || '').trim()
if (ua && isbot(ua)) {
diff --git a/backend/apps/cloud/src/analytics/protection/analytics-read.util.ts b/backend/apps/cloud/src/analytics/protection/analytics-read.util.ts
index 2b3fe7f0d..85899c088 100644
--- a/backend/apps/cloud/src/analytics/protection/analytics-read.util.ts
+++ b/backend/apps/cloud/src/analytics/protection/analytics-read.util.ts
@@ -1,13 +1,6 @@
import _isString from 'lodash/isString'
-import { getIPFromHeaders } from '../../common/utils'
-
-const TRUSTED_PROXY_IPS = new Set(
- (process.env.TRUSTED_PROXY_IPS || '')
- .split(',')
- .map((entry) => entry.trim())
- .filter(Boolean),
-)
+import { getIPFromHeaders, TRUSTED_PROXY_IPS } from '../../common/utils'
const firstHeaderValue = (value: unknown): string => {
if (_isString(value) && value) {
diff --git a/backend/apps/cloud/src/common/utils.ts b/backend/apps/cloud/src/common/utils.ts
index c5bfc89b5..63dc16723 100644
--- a/backend/apps/cloud/src/common/utils.ts
+++ b/backend/apps/cloud/src/common/utils.ts
@@ -413,6 +413,17 @@ const getHeader = (headers: any, name: string): string | null | undefined => {
return headers?.[name] ?? headers?.[name.toLowerCase()]
}
+// Egress IPs of our own relays (the web app's server-side fetches, the
+// managed proxy edge). Requests arriving from these carry the real visitor
+// IP in X-Forwarded-For; for every other connection the only trustworthy
+// source is X-Real-IP, which nginx derives from the TCP connection itself.
+export const TRUSTED_PROXY_IPS: ReadonlySet<string> = new Set(
+ (process.env.TRUSTED_PROXY_IPS || '')
+ .split(',')
+ .map((entry) => entry.trim())
+ .filter(Boolean),
+)
+
export const getIPFromHeaders = (headers: unknown) => {
const customHeader = process.env.CLIENT_IP_HEADER
@@ -423,7 +434,26 @@ export const getIPFromHeaders = (headers: unknown) => {
}
}
- return normalise(getHeader(headers, 'x-forwarded-for'))
+ const realIp = normalise(getHeader(headers, 'x-real-ip'))
+
+ if (realIp && !TRUSTED_PROXY_IPS.has(realIp)) {
+ return realIp
+ }
+
+ // The connection is one of our own relays (or X-Real-IP is absent, e.g.
+ // local development). Recover the visitor from X-Forwarded-For, walking
+ // from the right past our own hops so a client-supplied prefix never wins.
+ const forwardedFor = String(getHeader(headers, 'x-forwarded-for') ?? '')
+ const hops = forwardedFor.split(',')
+
+ for (let i = hops.length - 1; i >= 0; --i) {
+ const candidate = normalise(hops[i])
+ if (candidate && !TRUSTED_PROXY_IPS.has(candidate)) {
+ return candidate
+ }
+ }
+
+ return realIp
}
export const sumArrays = (source: number[], target: number[]) => {
diff --git a/backend/apps/cloud/src/project/dto/create-project.dto.ts b/backend/apps/cloud/src/project/dto/create-project.dto.ts
index 2df7e2b81..21bfe2da5 100644
--- a/backend/apps/cloud/src/project/dto/create-project.dto.ts
+++ b/backend/apps/cloud/src/project/dto/create-project.dto.ts
@@ -49,6 +49,11 @@ export class CreateProjectDTO extends ProjectOrganisationDto {
})
ipBlacklist?: string[]
+ @ApiProperty({
+ required: false,
+ })
+ ipWhitelist?: string[]
+
@ApiProperty({
required: false,
})
diff --git a/backend/apps/cloud/src/project/dto/project.dto.ts b/backend/apps/cloud/src/project/dto/project.dto.ts
index 9d67252f9..163fb214d 100644
--- a/backend/apps/cloud/src/project/dto/project.dto.ts
+++ b/backend/apps/cloud/src/project/dto/project.dto.ts
@@ -53,6 +53,14 @@ export class ProjectDTO {
})
ipBlacklist: string[] | null
+ @ApiProperty({
+ example: '::1,127.0.0.1,192.168.0.1/32',
+ required: false,
+ description:
+ 'Array of IP addresses (or CIDR ranges) that are never flagged by bot protection. Useful for server-side event tracking.',
+ })
+ ipWhitelist: string[] | null
+
@ApiProperty({
example: ['RU', 'BY', 'KP'],
required: false,
diff --git a/backend/apps/cloud/src/project/entity/project.entity.ts b/backend/apps/cloud/src/project/entity/project.entity.ts
index 3f8d92803..665aaf43b 100644
--- a/backend/apps/cloud/src/project/entity/project.entity.ts
+++ b/backend/apps/cloud/src/project/entity/project.entity.ts
@@ -47,6 +47,11 @@ export class Project {
@Column('simple-array', { nullable: true, default: null })
ipBlacklist: string[]
+ // IPs (or CIDR ranges) that bot detection (Shields) never flags
+ @ApiProperty()
+ @Column('simple-array', { nullable: true, default: null })
+ ipWhitelist: string[]
+
@ApiProperty()
@Column('simple-array', { nullable: true, default: null })
countryBlacklist: string[]
diff --git a/backend/apps/cloud/src/project/project.controller.ts b/backend/apps/cloud/src/project/project.controller.ts
index cbfa92feb..2c18e3130 100644
--- a/backend/apps/cloud/src/project/project.controller.ts
+++ b/backend/apps/cloud/src/project/project.controller.ts
@@ -1808,6 +1808,17 @@ export class ProjectController {
: null
}
+ if (projectDTO.ipWhitelist !== undefined) {
+ project.ipWhitelist =
+ Array.isArray(projectDTO.ipWhitelist) &&
+ projectDTO.ipWhitelist.length > 0
+ ? (_map(
+ projectDTO.ipWhitelist.slice(0, BLACKLIST_ITEMS_MAXIMUM),
+ _trim,
+ ) as string[])
+ : null
+ }
+
if (projectDTO.countryBlacklist !== undefined) {
project.countryBlacklist =
projectDTO.countryBlacklist &&
diff --git a/backend/apps/cloud/src/project/project.service.ts b/backend/apps/cloud/src/project/project.service.ts
index 9e2c0106e..691049211 100644
--- a/backend/apps/cloud/src/project/project.service.ts
+++ b/backend/apps/cloud/src/project/project.service.ts
@@ -196,6 +196,7 @@ export class ProjectService {
'project.active',
'project.public',
'project.ipBlacklist',
+ 'project.ipWhitelist',
'project.countryBlacklist',
'project.botsProtectionLevel',
'project.captchaSecretKey',
@@ -790,6 +791,20 @@ export class ProjectService {
})
}
+ validateIPWhitelist(
+ projectDTO: ProjectDTO | UpdateProjectDto | CreateProjectDTO,
+ ) {
+ if (_size(_join(projectDTO.ipWhitelist, ',')) > 300)
+ throw new UnprocessableEntityException(
+ 'The list of whitelisted IP addresses must be less than 300 characters.',
+ )
+ _map(projectDTO.ipWhitelist, (ip) => {
+ if (!net.isIP(_trim(ip)) && !IP_REGEX.test(_trim(ip))) {
+ throw new ConflictException(`IP address ${ip} is not correct`)
+ }
+ })
+ }
+
validateCountryBlacklist(
projectDTO: ProjectDTO | UpdateProjectDto | CreateProjectDTO,
) {
@@ -832,6 +847,7 @@ export class ProjectService {
this.validateOrigins(projectDTO)
this.validateIPBlacklist(projectDTO)
+ this.validateIPWhitelist(projectDTO)
this.validateCountryBlacklist(projectDTO)
}
diff --git a/backend/apps/community/src/analytics/bot-detection.service.ts b/backend/apps/community/src/analytics/bot-detection.service.ts
index b5f43a9ba..4af374566 100644
--- a/backend/apps/community/src/analytics/bot-detection.service.ts
+++ b/backend/apps/community/src/analytics/bot-detection.service.ts
@@ -7,6 +7,7 @@ import { parse as parseDomain } from 'tldts'
import { BotsProtectionLevel, Project } from '../project/entity/project.entity'
import { ProjectService } from '../project/project.service'
import { getIPDetails } from '../common/utils'
+import { isIpInRange } from '../common/ip-range'
type BotReason =
| 'user_agent'
@@ -216,6 +217,18 @@ export class BotDetectionService {
if (level === BotsProtectionLevel.OFF) return NEGATIVE
+ // Whitelisted IPs (e.g. customer backends doing server-side tracking)
+ // bypass the entire detection chain.
+ const ipWhitelist = (project.ipWhitelist || []).filter(Boolean)
+
+ if (
+ input.ip &&
+ ipWhitelist.length > 0 &&
+ isIpInRange(input.ip, ipWhitelist)
+ ) {
+ return NEGATIVE
+ }
+
const ua = (input.userAgent || '').trim()
if (ua && isbot(ua)) {
diff --git a/backend/apps/community/src/common/utils.ts b/backend/apps/community/src/common/utils.ts
index 1cac71d46..301075931 100644
--- a/backend/apps/community/src/common/utils.ts
+++ b/backend/apps/community/src/common/utils.ts
@@ -123,6 +123,7 @@ const ALLOWED_KEYS = [
'name',
'origins',
'ipBlacklist',
+ 'ipWhitelist',
'countryBlacklist',
'active',
'public',
@@ -498,6 +499,7 @@ const createProjectClickhouse = async (project: Partial<Project>) => {
name,
origins: '',
ipBlacklist: '',
+ ipWhitelist: '',
countryBlacklist: '',
active: 1,
public: 0,
diff --git a/backend/apps/community/src/project/dto/project.dto.ts b/backend/apps/community/src/project/dto/project.dto.ts
index 3f4dec05f..b55f95296 100644
--- a/backend/apps/community/src/project/dto/project.dto.ts
+++ b/backend/apps/community/src/project/dto/project.dto.ts
@@ -53,6 +53,14 @@ export class ProjectDTO {
})
ipBlacklist: string[] | null
+ @ApiProperty({
+ example: '::1,127.0.0.1,192.168.0.1/32',
+ required: false,
+ description:
+ 'Array of IP addresses (or CIDR ranges) that are never flagged by bot protection. Useful for server-side event tracking.',
+ })
+ ipWhitelist: string[] | null
+
@ApiProperty({
example: ['RU', 'BY', 'KP'],
required: false,
diff --git a/backend/apps/community/src/project/entity/project.entity.ts b/backend/apps/community/src/project/entity/project.entity.ts
index 077458f86..68b4ef241 100644
--- a/backend/apps/community/src/project/entity/project.entity.ts
+++ b/backend/apps/community/src/project/entity/project.entity.ts
@@ -11,6 +11,8 @@ export class Project {
name: string
origins: string[]
ipBlacklist: string[]
+ // IPs (or CIDR ranges) that bot detection (Shields) never flags
+ ipWhitelist: string[]
countryBlacklist: string[]
active: boolean
public: boolean
diff --git a/backend/apps/community/src/project/project.controller.ts b/backend/apps/community/src/project/project.controller.ts
index d088cd974..1930a37df 100644
--- a/backend/apps/community/src/project/project.controller.ts
+++ b/backend/apps/community/src/project/project.controller.ts
@@ -1097,6 +1097,23 @@ export class ProjectController {
}
}
+ if (projectDTO.ipWhitelist !== undefined) {
+ if (!projectDTO.ipWhitelist) {
+ project.ipWhitelist = []
+ } else {
+ if (!Array.isArray(projectDTO.ipWhitelist)) {
+ throw new BadRequestException('ipWhitelist must be an array')
+ }
+
+ const MAX_IP_WHITELIST_ITEMS = 1000
+ if (projectDTO.ipWhitelist.length > MAX_IP_WHITELIST_ITEMS) {
+ throw new BadRequestException('ipWhitelist is too large')
+ }
+
+ project.ipWhitelist = _map(projectDTO.ipWhitelist, _trim) as string[]
+ }
+ }
+
if (projectDTO.countryBlacklist !== undefined) {
if (projectDTO.countryBlacklist) {
if (!Array.isArray(projectDTO.countryBlacklist)) {
diff --git a/backend/apps/community/src/project/project.service.ts b/backend/apps/community/src/project/project.service.ts
index 35994c47d..cfa5dec90 100644
--- a/backend/apps/community/src/project/project.service.ts
+++ b/backend/apps/community/src/project/project.service.ts
@@ -386,6 +386,12 @@ export class ProjectService {
: _join(updProject.ipBlacklist, ',')
}
+ if (!_isNull(updProject.ipWhitelist)) {
+ updProject.ipWhitelist = _isString(updProject.ipWhitelist)
+ ? updProject.ipWhitelist
+ : _join(updProject.ipWhitelist, ',')
+ }
+
if (!_isNull(updProject.countryBlacklist)) {
updProject.countryBlacklist = _isString(updProject.countryBlacklist)
? updProject.countryBlacklist
@@ -422,6 +428,10 @@ export class ProjectService {
? []
: _split(updProject.ipBlacklist, ',')
+ updProject.ipWhitelist = _isEmpty(updProject.ipWhitelist)
+ ? []
+ : _split(updProject.ipWhitelist, ',')
+
updProject.countryBlacklist = _isEmpty(updProject.countryBlacklist)
? []
: _split(updProject.countryBlacklist, ',')
diff --git a/backend/migrations/clickhouse/initialise_selfhosted.js b/backend/migrations/clickhouse/initialise_selfhosted.js
index be488a023..253c2bd2c 100644
--- a/backend/migrations/clickhouse/initialise_selfhosted.js
+++ b/backend/migrations/clickhouse/initialise_selfhosted.js
@@ -27,6 +27,7 @@ const CLICKHOUSE_INIT_QUERIES = [
name String CODEC(ZSTD(3)),
origins Nullable(String) CODEC(ZSTD(3)),
ipBlacklist Nullable(String) CODEC(ZSTD(3)),
+ ipWhitelist Nullable(String) CODEC(ZSTD(3)),
countryBlacklist Nullable(String) CODEC(ZSTD(3)),
active Int8,
public Int8,
diff --git a/backend/migrations/clickhouse/selfhosted_2026_07_12_ip_whitelist.js b/backend/migrations/clickhouse/selfhosted_2026_07_12_ip_whitelist.js
new file mode 100644
index 000000000..6fc1ab213
--- /dev/null
+++ b/backend/migrations/clickhouse/selfhosted_2026_07_12_ip_whitelist.js
@@ -0,0 +1,9 @@
+// This migration adds the ipWhitelist column (IPs excluded from bot
+// protection) to the project table
+const { queriesRunner, dbName } = require('./setup')
+
+const queries = [
+ `ALTER TABLE ${dbName}.project ADD COLUMN ipWhitelist Nullable(String) DEFAULT NULL AFTER ipBlacklist;`,
+]
+
+queriesRunner(queries)
diff --git a/backend/migrations/mysql/2026_07_12_ip_whitelist.sql b/backend/migrations/mysql/2026_07_12_ip_whitelist.sql
new file mode 100644
index 000000000..26eaf8322
--- /dev/null
+++ b/backend/migrations/mysql/2026_07_12_ip_whitelist.sql
@@ -0,0 +1 @@
+ALTER TABLE `project` ADD COLUMN `ipWhitelist` text DEFAULT NULL AFTER `ipBlacklist`;
diff --git a/docs/content/docs/api/admin.mdx b/docs/content/docs/api/admin.mdx
index 33a79b339..df1dab663 100644
--- a/docs/content/docs/api/admin.mdx
+++ b/docs/content/docs/api/admin.mdx
@@ -42,6 +42,7 @@ If you have special needs for more requests, please [contact us](https://swetrix
| `password` | `string` | Required only if `isPasswordProtected` is set to `true`. That is the password unauthorised people will have to enter to access your project's dashboard. |
| `origins` | `Array<string>` | Domains allowed to send analytics using this Project ID. Traffic from all other domains is blocked. Supports wildcards, for example: `['cornell.edu', 'app.example.com', '*.gov.uk']`. An empty array allows all domains. |
| `ipBlacklist` | `Array<string>` | IP addresses or CIDR ranges whose traffic should be ignored for this project. Useful for excluding your own visits. For example: `['172.126.10.16', '192.168.0.1/32', '::1']`. |
+| `ipWhitelist` | `Array<string>` | IP addresses or CIDR ranges that are never flagged by [bot protection](/bot-protection#trusted-ip-addresses). Useful for server-side event tracking. For example: `['172.126.10.16', '192.168.0.1/32', '::1']`. |
| `botsProtectionLevel` | `off`, `basic`, or `strict` | Choose how aggressively bot and automated traffic should be filtered. `off` tracks all traffic, `basic` filters common bots, and `strict` adds stronger automated-traffic checks. `basic` by default. |
| `organisationId` | `string` | Organisation you want to add this project to. You must be an owner or admin of the organisation to add a project to it. |
@@ -199,6 +200,7 @@ curl -i -X POST https://api.swetrix.com/v1/project \
"origins": [],
"isPasswordProtected": true,
"ipBlacklist": null,
+ "ipWhitelist": null,
"captchaSecretKey": null,
"active": true,
"public": false,
@@ -231,6 +233,7 @@ curl -i -X PUT https://api.swetrix.com/v1/project/WvZCYTrOPzSK \
"name": "PASSWORD PROTECTED",
"origins": ["example.com", "example.co.uk"],
"ipBlacklist": null,
+ "ipWhitelist": null,
"active": true,
"public": true,
"isTransferring": false,
diff --git a/docs/content/docs/sitesettings/bot-protection.mdx b/docs/content/docs/sitesettings/bot-protection.mdx
index 4795c0c0b..0f09bafd1 100644
--- a/docs/content/docs/sitesettings/bot-protection.mdx
+++ b/docs/content/docs/sitesettings/bot-protection.mdx
@@ -139,7 +139,18 @@ Every detection method has trade-offs:
- **`referrer_spam`** β€” the matomo list is community-curated and very strict; false positives are rare but possible if someone legitimately migrates onto a domain that used to be a spam farm.
- **`datacenter_ip`** β€” the highest false-positive rate of the bunch. VPN users, server-side rendering hits, and cloud-based RSS readers can all be caught. Only enable Strict if datacenter traffic is materially polluting your dashboard.
-If you suspect a false positive, switch to **Basic** to isolate the cause: the only checks that run there are user-agent and headless-browser, and both are deterministic.
+If you suspect a false positive, switch to **Basic** to isolate the cause: the only checks that run there are user-agent and headless-browser, and both are deterministic. If the false positives come from a fixed set of IP addresses β€” your own backend, an office network, a monitoring service you want counted β€” add them to the [Trusted IP addresses](#trusted-ip-addresses) list instead of lowering the protection level.
+
+## Trusted IP addresses
+
+The **Trusted IP addresses** field on the Shields tab lets you exempt specific IPs (or CIDR ranges) from bot detection entirely. Requests from a trusted IP skip the whole detection chain β€” none of the six checks run, no block is recorded, and the event is processed as regular traffic.
+
+The most common reason to use it is **server-side event tracking on Strict mode**: events sent from your own backend (via `@swetrix/node` or the [Events API](/events-api)) originate from a hosting provider's network, so the `datacenter_ip` check would classify them as bot traffic and silently drop them. Add your servers' egress IPs to the trusted list and they'll pass.
+
+- Separate multiple values with commas.
+- IPv4, IPv6, and CIDR ranges are supported, for example `172.126.10.16`, `192.168.0.1/32`, or `::1`.
+- Trusted IPs bypass bot detection only. The **Blocked IP addresses** list, origin checks, and country blocks still apply.
+- Available on both cloud and self-hosted (community) editions.
## When bots are detected
@@ -165,11 +176,15 @@ No. Bot detection runs **before** the event is recorded, so you only pay for rea
### Can I add my own UA rules or IP ranges?
-Not yet. The current detection logic is fixed. The existing **Blocked IP addresses** and **Blocked countries** settings in the Shields tab let you block specific IPs and countries, which works for most allowlist/denylist use cases.
+Custom user-agent rules aren't supported, but IP-based rules are: use **Blocked IP addresses** to deny specific IPs or ranges, and [Trusted IP addresses](#trusted-ip-addresses) to exempt IPs or ranges from bot detection entirely.
### My GoogleBot / SEO crawler stats disappeared after I enabled Basic. Is that a bug?
-That's by design β€” search-engine crawlers are detected by their user agent and excluded. If you specifically want to count crawler hits, switch to **Off**. We're considering a per-project allowlist for legitimate crawlers in a future release.
+That's by design β€” search-engine crawlers are detected by their user agent and excluded. If you specifically want to count crawler hits, switch to **Off**, or add the crawler's published IP ranges to [Trusted IP addresses](#trusted-ip-addresses) to exempt just that crawler.
+
+### My server-side events stopped showing up after I enabled Strict. Why?
+
+Events sent from a backend originate from a datacenter IP, so Strict mode's `datacenter_ip` check drops them. Add your servers' egress IPs to [Trusted IP addresses](#trusted-ip-addresses) and they'll be tracked again.
### Why does my report only show one or two reasons?
diff --git a/docs/content/docs/sitesettings/project-configuration.mdx b/docs/content/docs/sitesettings/project-configuration.mdx
index 5d9e5efc9..0dae846fc 100644
--- a/docs/content/docs/sitesettings/project-configuration.mdx
+++ b/docs/content/docs/sitesettings/project-configuration.mdx
@@ -51,6 +51,16 @@ Swetrix has built-in bot detection. You can choose how aggressively bot and auto
Below the dropdown you'll find a per-project **Blocked traffic** report showing how many requests were filtered out, broken down by classification and country. See the dedicated [Bot Protection](/bot-protection) page for the full list of detection methods, privacy notes, and FAQ.
+### Trusted IP addresses
+
+Traffic from these IP addresses is never flagged by bot protection, regardless of the protection level. This is the recommended way to make **server-side event tracking** work with Strict protection: requests sent from your backend (for example via `@swetrix/node` or the [Events API](/events-api)) would otherwise be classified as datacenter traffic and dropped.
+
+- Add the egress IP addresses of the servers that send events to Swetrix.
+- Separate multiple values with commas.
+- Supports IPv4, IPv6, and CIDR ranges, for example `172.126.10.16`, `192.168.0.1/32`, or `::1`.
+
+Note that trusted IPs only bypass bot detection β€” the [Blocked IP addresses](#blocked-ip-addresses) list and other Shields settings still apply.
+
## Session Replays
The **Session replays** tab controls how long newly recorded replay chunks are retained for the project.
diff --git a/web/app/api/api.server.ts b/web/app/api/api.server.ts
index e05458f62..8ba6d583f 100644
--- a/web/app/api/api.server.ts
+++ b/web/app/api/api.server.ts
@@ -2277,6 +2277,7 @@ export interface Project {
name: string
origins: string[] | null
ipBlacklist: string[] | null
+ ipWhitelist: string[] | null
active: boolean
public: boolean
isPasswordProtected: boolean
diff --git a/web/app/lib/models/Project.ts b/web/app/lib/models/Project.ts
index c2e2acf2d..2d2c768a8 100644
--- a/web/app/lib/models/Project.ts
+++ b/web/app/lib/models/Project.ts
@@ -246,6 +246,7 @@ export interface Project {
name: string
origins: string[] | string | null
ipBlacklist: string[] | null | string
+ ipWhitelist: string[] | null | string
countryBlacklist: string[] | null
active: boolean
public: boolean
diff --git a/web/app/pages/Project/Settings/ProjectSettings.tsx b/web/app/pages/Project/Settings/ProjectSettings.tsx
index 25e478891..e41f60764 100644
--- a/web/app/pages/Project/Settings/ProjectSettings.tsx
+++ b/web/app/pages/Project/Settings/ProjectSettings.tsx
@@ -79,6 +79,7 @@ const CAPTCHA_CLIENT_DOCS_URL =
interface Form extends Partial<Omit<Project, 'brandKeywords'>> {
origins: string | null
ipBlacklist: string | null
+ ipWhitelist: string | null
countryBlacklist: string[]
websiteUrl?: string | null
brandKeywords?: string
@@ -90,6 +91,7 @@ const PROJECT_TEXT_AUTOSAVE_TOASTS = {
name: 'project.settings.autosave.name',
origins: 'project.settings.autosave.origins',
ipBlacklist: 'project.settings.autosave.ipBlacklist',
+ ipWhitelist: 'project.settings.autosave.ipWhitelist',
websiteUrl: 'project.settings.autosave.websiteUrl',
brandKeywords: 'project.settings.autosave.brandKeywords',
} as const
@@ -112,6 +114,9 @@ const getFormFromProject = (project: Project): Form => ({
ipBlacklist: _isString(project.ipBlacklist)
? project.ipBlacklist
: _join(project.ipBlacklist, ', '),
+ ipWhitelist: _isString(project.ipWhitelist)
+ ? project.ipWhitelist
+ : _join(project.ipWhitelist, ', '),
countryBlacklist: project.countryBlacklist || [],
active: project.active !== false,
botsProtectionLevel:
@@ -190,6 +195,7 @@ const ProjectSettings = () => {
name?: string
origins?: string
ipBlacklist?: string
+ ipWhitelist?: string
password?: string
websiteUrl?: string
transferEmail?: string
@@ -701,6 +707,7 @@ const ProjectSettings = () => {
name?: string
origins?: string
ipBlacklist?: string
+ ipWhitelist?: string
password?: string
websiteUrl?: string
} = {}
@@ -727,6 +734,12 @@ const ProjectSettings = () => {
})
}
+ if (_size(data.ipWhitelist) > MAX_IPBLACKLIST_LENGTH) {
+ allErrors.ipWhitelist = t('project.settings.oxCharsError', {
+ amount: MAX_IPBLACKLIST_LENGTH,
+ })
+ }
+
if (data.websiteUrl?.trim() && !isValidHttpUrl(data.websiteUrl)) {
allErrors.websiteUrl = t('project.settings.invalidUrl')
}
diff --git a/web/app/pages/Project/Settings/tabs/Shields.tsx b/web/app/pages/Project/Settings/tabs/Shields.tsx
index f5b79fc8c..68c0cba61 100644
--- a/web/app/pages/Project/Settings/tabs/Shields.tsx
+++ b/web/app/pages/Project/Settings/tabs/Shields.tsx
@@ -21,12 +21,14 @@ interface ShieldsProps {
form: {
origins: string | null
ipBlacklist: string | null
+ ipWhitelist: string | null
botsProtectionLevel?: string
countryBlacklist?: string[]
}
errors: {
origins?: string
ipBlacklist?: string
+ ipWhitelist?: string
}
beenSubmitted: boolean
handleInput: (e: React.ChangeEvent<HTMLInputElement>) => void
@@ -185,6 +187,17 @@ const Shields = ({
)}
/>
</div>
+ <Input
+ name='ipWhitelist'
+ label={t('project.settings.ipWhitelist')}
+ hint={t('project.settings.ipWhitelistHint')}
+ placeholder={t('project.settings.ipWhitelistPlaceholder')}
+ value={form.ipWhitelist || ''}
+ className='mt-4'
+ onChange={handleInput}
+ onBlur={handleBlur}
+ error={beenSubmitted ? errors.ipWhitelist : null}
+ />
</>
)
}
diff --git a/web/app/routes/projects.settings.$id.tsx b/web/app/routes/projects.settings.$id.tsx
index 67f4f3757..362ab51c6 100644
--- a/web/app/routes/projects.settings.$id.tsx
+++ b/web/app/routes/projects.settings.$id.tsx
@@ -124,6 +124,7 @@ export async function action({ request, params }: ActionFunctionArgs) {
const password = formData.get('password')?.toString()
const origins = formData.get('origins')?.toString()
const ipBlacklist = formData.get('ipBlacklist')?.toString()
+ const ipWhitelist = formData.get('ipWhitelist')?.toString()
const botsProtectionLevel = formData
.get('botsProtectionLevel')
?.toString()
@@ -178,6 +179,10 @@ export async function action({ request, params }: ActionFunctionArgs) {
updateData.ipBlacklist = ipBlacklist
? ipBlacklist.split(',').map((ip) => ip.trim())
: null
+ if (ipWhitelist !== undefined)
+ updateData.ipWhitelist = ipWhitelist
+ ? ipWhitelist.split(',').map((ip) => ip.trim())
+ : null
if (botsProtectionLevel !== undefined)
updateData.botsProtectionLevel = botsProtectionLevel
if (countryBlacklist !== undefined)
diff --git a/web/public/locales/en.json b/web/public/locales/en.json
index e48311dba..1e15202e6 100644
--- a/web/public/locales/en.json
+++ b/web/public/locales/en.json
@@ -2535,6 +2535,7 @@
"brandKeywords": "Brand keywords updated",
"origins": "Allowed origins updated",
"ipBlacklist": "IP blacklist updated",
+ "ipWhitelist": "Trusted IP addresses updated",
"countryBlacklist": "Country blacklist updated",
"botsProtectionLevel": "Bot traffic filtering updated",
"public": "Public dashboard setting updated",
@@ -2610,6 +2611,9 @@
"ipBlacklist": "Blocked IP addresses",
"ipBlacklistHint": "Traffic from these IP addresses will be ignored for this project. Separate multiple IP addresses or CIDR ranges with commas. Useful for excluding your own visits from analytics. Example: 172.126.10.16, 192.168.0.1/32, ::1.",
"ipBlacklistPlaceholder": "Not blocking any IP addresses by default",
+ "ipWhitelist": "Trusted IP addresses",
+ "ipWhitelistHint": "Traffic from these IP addresses will never be flagged by bot protection. Separate multiple IP addresses or CIDR ranges with commas. Useful for server-side event tracking, as requests from your backend may otherwise be dropped as datacenter traffic. Example: 172.126.10.16, 192.168.0.1/32, ::1.",
+ "ipWhitelistPlaceholder": "No trusted IP addresses by default",
"countryBlacklist": "Blocked countries",
"countryBlacklistHint": "Choose the countries you don't want to track. Traffic from these countries will be ignored in your analytics.",
"countryBlacklistPlaceholder": "Not blocking any countries by default",