📈 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!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
Proper auto difficulty detection
Blue Mouseb7fbc9c3c75c
diff --git a/backend/apps/cloud/src/captcha/captcha.service.ts b/backend/apps/cloud/src/captcha/captcha.service.tsindex 52442a777..a726f5eb9 100644--- a/backend/apps/cloud/src/captcha/captcha.service.ts+++ b/backend/apps/cloud/src/captcha/captcha.service.ts@@ -576,11 +576,10 @@ export class CaptchaService {: await this.projectService.getRedisProject(pid)const mode = (project?.captchaDifficultyMode ||'manual') as CaptchaDifficultyMode- const baseDifficulty = clampDifficulty(project?.captchaDifficulty)if (mode !== 'auto' || isDummyPID(pid)) {return {- difficulty: baseDifficulty,+ difficulty: clampDifficulty(project?.captchaDifficulty),mode: 'manual',reasons: ['manual'],score: 0,@@ -639,23 +638,24 @@ export class CaptchaService {}addRisk(isHosting, 'hosting_ip')- addRisk(hasHeadlessUserAgent(headers), 'headless_browser')+ addRisk(hasHeadlessUserAgent(headers), 'headless_browser', 2)addRisk(hasSuspiciousHeaders(headers), 'suspicious_headers')- addRisk(projectGenerate1m >= 50, 'project_spike')+ addRisk(projectGenerate1m >= 50, 'project_spike', 2)addRisk(countryGenerate5m >= 50, 'country_spike')- addRisk(ipGenerate1m >= 8, 'ip_pressure')- addRisk(projectGenerate5m >= 30 && passRatio < 0.25, 'low_pass_ratio')- addRisk(verifyAttempts >= 20 && failRatio > 0.35, 'verify_failures')- addRisk(projectValidationFail5m >= 5, 'validation_failures')- addRisk(projectReplay5m >= 2 || ipReplay5m >= 1, 'replay_attempts')- addRisk(ipFail5m >= 3, 'ip_verify_failures')+ addRisk(ipGenerate1m >= 8, 'ip_pressure', 2)+ addRisk(projectGenerate5m >= 30 && passRatio < 0.25, 'low_pass_ratio', 2)+ addRisk(verifyAttempts >= 20 && failRatio > 0.35, 'verify_failures', 2)+ addRisk(projectValidationFail5m >= 5, 'validation_failures', 2)+ addRisk(projectReplay5m >= 2 || ipReplay5m >= 1, 'replay_attempts', 2)+ addRisk(ipFail5m >= 3, 'ip_verify_failures', 2)- const adjustment = score >= 5 ? 2 : score >= 2 ? 1 : 0+ const difficulty =+ score >= 8 ? 6 : score >= 5 ? 5 : score >= 2 ? 4 : score >= 1 ? 3 : 2return {- difficulty: clampDifficulty(baseDifficulty + adjustment),+ difficulty,mode: 'auto',- reasons: adjustment > 0 ? reasons.slice(0, 4) : ['baseline'],+ reasons: difficulty > 2 ? reasons.slice(0, 4) : ['baseline'],score,}}diff --git a/backend/apps/cloud/src/project/dto/update-project.dto.ts b/backend/apps/cloud/src/project/dto/update-project.dto.tsindex 68a517fee..b3789b222 100644--- a/backend/apps/cloud/src/project/dto/update-project.dto.ts+++ b/backend/apps/cloud/src/project/dto/update-project.dto.ts@@ -49,7 +49,7 @@ export class UpdateProjectDto extends IntersectionType(@ApiProperty({required: false,description:- 'CAPTCHA difficulty mode. Manual uses captchaDifficulty directly; auto raises it dynamically when risk signals increase.',+ 'CAPTCHA difficulty mode. Manual uses captchaDifficulty directly; auto selects difficulty dynamically from risk signals.',enum: ['manual', 'auto'],default: 'manual',})diff --git a/backend/apps/community/src/captcha/captcha.service.ts b/backend/apps/community/src/captcha/captcha.service.tsindex 52442a777..a726f5eb9 100644--- a/backend/apps/community/src/captcha/captcha.service.ts+++ b/backend/apps/community/src/captcha/captcha.service.ts@@ -576,11 +576,10 @@ export class CaptchaService {: await this.projectService.getRedisProject(pid)const mode = (project?.captchaDifficultyMode ||'manual') as CaptchaDifficultyMode- const baseDifficulty = clampDifficulty(project?.captchaDifficulty)if (mode !== 'auto' || isDummyPID(pid)) {return {- difficulty: baseDifficulty,+ difficulty: clampDifficulty(project?.captchaDifficulty),mode: 'manual',reasons: ['manual'],score: 0,@@ -639,23 +638,24 @@ export class CaptchaService {}addRisk(isHosting, 'hosting_ip')- addRisk(hasHeadlessUserAgent(headers), 'headless_browser')+ addRisk(hasHeadlessUserAgent(headers), 'headless_browser', 2)addRisk(hasSuspiciousHeaders(headers), 'suspicious_headers')- addRisk(projectGenerate1m >= 50, 'project_spike')+ addRisk(projectGenerate1m >= 50, 'project_spike', 2)addRisk(countryGenerate5m >= 50, 'country_spike')- addRisk(ipGenerate1m >= 8, 'ip_pressure')- addRisk(projectGenerate5m >= 30 && passRatio < 0.25, 'low_pass_ratio')- addRisk(verifyAttempts >= 20 && failRatio > 0.35, 'verify_failures')- addRisk(projectValidationFail5m >= 5, 'validation_failures')- addRisk(projectReplay5m >= 2 || ipReplay5m >= 1, 'replay_attempts')- addRisk(ipFail5m >= 3, 'ip_verify_failures')+ addRisk(ipGenerate1m >= 8, 'ip_pressure', 2)+ addRisk(projectGenerate5m >= 30 && passRatio < 0.25, 'low_pass_ratio', 2)+ addRisk(verifyAttempts >= 20 && failRatio > 0.35, 'verify_failures', 2)+ addRisk(projectValidationFail5m >= 5, 'validation_failures', 2)+ addRisk(projectReplay5m >= 2 || ipReplay5m >= 1, 'replay_attempts', 2)+ addRisk(ipFail5m >= 3, 'ip_verify_failures', 2)- const adjustment = score >= 5 ? 2 : score >= 2 ? 1 : 0+ const difficulty =+ score >= 8 ? 6 : score >= 5 ? 5 : score >= 2 ? 4 : score >= 1 ? 3 : 2return {- difficulty: clampDifficulty(baseDifficulty + adjustment),+ difficulty,mode: 'auto',- reasons: adjustment > 0 ? reasons.slice(0, 4) : ['baseline'],+ reasons: difficulty > 2 ? reasons.slice(0, 4) : ['baseline'],score,}}diff --git a/backend/apps/community/src/project/dto/update-project.dto.ts b/backend/apps/community/src/project/dto/update-project.dto.tsindex 87f5a791c..74ef95ecd 100644--- a/backend/apps/community/src/project/dto/update-project.dto.ts+++ b/backend/apps/community/src/project/dto/update-project.dto.ts@@ -35,7 +35,7 @@ export class UpdateProjectDto extends IntersectionType(@ApiProperty({required: false,description:- 'CAPTCHA difficulty mode. Manual uses captchaDifficulty directly; auto raises it dynamically when risk signals increase.',+ 'CAPTCHA difficulty mode. Manual uses captchaDifficulty directly; auto selects difficulty dynamically from risk signals.',enum: ['manual', 'auto'],default: 'manual',})diff --git a/docs/content/docs/analytics-dashboard/captcha.mdx b/docs/content/docs/analytics-dashboard/captcha.mdxindex 9276b35a5..a5903072e 100644--- a/docs/content/docs/analytics-dashboard/captcha.mdx+++ b/docs/content/docs/analytics-dashboard/captcha.mdx@@ -36,7 +36,7 @@ If Auto difficulty is enabled, the dashboard shows the selected difficulty distr### Solve time-Solve-time panels and summary values show how long successful challenges took from generation to verification. This helps you spot when a configured fallback difficulty is too aggressive for legitimate users.+Solve-time panels and summary values show how long successful challenges took from generation to verification. This helps you spot when challenge difficulty is too aggressive for legitimate users.## Detailed Breakdowndiff --git a/docs/content/docs/captcha/introduction.mdx b/docs/content/docs/captcha/introduction.mdxindex 10175bd29..4f1cc12f7 100644--- a/docs/content/docs/captcha/introduction.mdx+++ b/docs/content/docs/captcha/introduction.mdx@@ -32,7 +32,7 @@ This approach provides a seamless user experience (no more "select all traffic lCAPTCHA projects can use either **Manual** or **Auto** difficulty.- **Manual** always uses the configured Proof of Work difficulty.-- **Auto** starts from the configured fallback difficulty and raises the challenge difficulty when privacy-safe risk signals increase, such as short-lived project traffic spikes, country-level spikes, replay attempts, validation failures, hosting IPs, suspicious headers, or low pass ratios.+- **Auto** selects the challenge difficulty dynamically from privacy-safe risk signals, such as short-lived project traffic spikes, country-level spikes, replay attempts, validation failures, hosting IPs, suspicious headers, or low pass ratios.Auto difficulty uses bounded Redis counters with short TTLs and stores only coarse analytics metadata such as the selected difficulty and the reason category that caused a raise. It does not store raw IP addresses in analytics.diff --git a/web/app/pages/Project/Settings/ProjectSettings.tsx b/web/app/pages/Project/Settings/ProjectSettings.tsxindex ad0961b4c..fef894d6d 100644--- a/web/app/pages/Project/Settings/ProjectSettings.tsx+++ b/web/app/pages/Project/Settings/ProjectSettings.tsx@@ -1506,10 +1506,12 @@ const ProjectSettings = () => {onClick={() => {const formData = new FormData()formData.set('intent', 'update-project')- formData.set(- 'captchaDifficulty',- captchaDifficulty.toString(),- )+ if (captchaDifficultyMode === 'manual') {+ formData.set(+ 'captchaDifficulty',+ captchaDifficulty.toString(),+ )+ }formData.set('captchaDifficultyMode',captchaDifficultyMode,