📈 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
captcha difficulty selector
Blue Mouse573ab7f6547d
diff --git a/backend/apps/cloud/src/project/dto/update-project.dto.ts b/backend/apps/cloud/src/project/dto/update-project.dto.tsindex 1489a5880..5f34600d7 100644--- a/backend/apps/cloud/src/project/dto/update-project.dto.ts+++ b/backend/apps/cloud/src/project/dto/update-project.dto.ts@@ -1,4 +1,4 @@-import { IsBoolean, IsOptional } from 'class-validator'+import { IsBoolean, IsOptional, IsInt, Min, Max } from 'class-validator'import { IntersectionType, PartialType } from '@nestjs/mapped-types'import { ApiProperty } from '@nestjs/swagger'import { ProjectDTO } from './project.dto'@@ -31,4 +31,18 @@ export class UpdateProjectDto extends IntersectionType(@IsBoolean()@IsOptional()isArchived?: boolean++ @ApiProperty({+ required: false,+ description:+ 'CAPTCHA PoW difficulty (number of leading zeros required). Higher = harder. Range: 1-6.',+ default: 4,+ minimum: 1,+ maximum: 6,+ })+ @IsInt()+ @Min(1)+ @Max(6)+ @IsOptional()+ captchaDifficulty?: number}diff --git a/backend/apps/cloud/src/project/entity/project.entity.ts b/backend/apps/cloud/src/project/entity/project.entity.tsindex f9d8afd3a..04fc41902 100644--- a/backend/apps/cloud/src/project/entity/project.entity.ts+++ b/backend/apps/cloud/src/project/entity/project.entity.ts@@ -74,6 +74,12 @@ export class Project {@Column('varchar', { default: null, length: CAPTCHA_SECRET_KEY_LENGTH })captchaSecretKey: string+ // CAPTCHA PoW difficulty (number of leading zeros required in hash)+ // Default is 4 (~65k iterations, ~1-2 seconds on average devices)+ @ApiProperty()+ @Column('tinyint', { default: 4, unsigned: true })+ captchaDifficulty: number+@ApiProperty()@Column({type: 'enum',diff --git a/backend/apps/cloud/src/project/project.controller.ts b/backend/apps/cloud/src/project/project.controller.tsindex f482cf30c..8afca86ac 100644--- a/backend/apps/cloud/src/project/project.controller.ts+++ b/backend/apps/cloud/src/project/project.controller.ts@@ -1743,6 +1743,10 @@ export class ProjectController {project.botsProtectionLevel = projectDTO.botsProtectionLevel}+ if (projectDTO.captchaDifficulty !== undefined) {+ project.captchaDifficulty = projectDTO.captchaDifficulty+ }+if (projectDTO.name) {project.name = _trim(projectDTO.name)}diff --git a/backend/apps/cloud/src/project/project.service.ts b/backend/apps/cloud/src/project/project.service.tsindex 6c62830d2..b628c579d 100644--- a/backend/apps/cloud/src/project/project.service.ts+++ b/backend/apps/cloud/src/project/project.service.ts@@ -321,6 +321,7 @@ export class ProjectService {'project.countryBlacklist','project.botsProtectionLevel','project.captchaSecretKey',+ 'project.captchaDifficulty','project.passwordHash','project.isPasswordProtected','admin.id',diff --git a/backend/migrations/mysql/2025_12_06_captcha_difficulty.sql b/backend/migrations/mysql/2025_12_06_captcha_difficulty.sqlnew file mode 100644index 000000000..c6f2020cc--- /dev/null+++ b/backend/migrations/mysql/2025_12_06_captcha_difficulty.sql@@ -0,0 +1,6 @@+-- Add captchaDifficulty column to project table+-- This controls the PoW difficulty for CAPTCHA verification+-- Default is 4 (requires 4 leading zeros in hash, ~65k iterations, ~1-2 seconds)++ALTER TABLE project ADD COLUMN `captchaDifficulty` TINYINT UNSIGNED NOT NULL DEFAULT 4;+diff --git a/web/app/lib/models/Project.ts b/web/app/lib/models/Project.tsindex 3f1270187..a200d0ef1 100644--- a/web/app/lib/models/Project.ts+++ b/web/app/lib/models/Project.ts@@ -173,6 +173,7 @@ export interface Project {public: booleanisAnalyticsProject: booleancaptchaSecretKey: string | null+ captchaDifficulty: numbercreated: stringshare?: ShareOwnerProject[]overall: OverallObjectdiff --git a/web/app/pages/Project/Settings/ProjectSettings.tsx b/web/app/pages/Project/Settings/ProjectSettings.tsxindex f68369dd8..61e363f10 100644--- a/web/app/pages/Project/Settings/ProjectSettings.tsx+++ b/web/app/pages/Project/Settings/ProjectSettings.tsx@@ -379,7 +379,9 @@ const ProjectSettings = () => {// CAPTCHA stateconst [captchaSecretKey, setCaptchaSecretKey] = useState<string | null>(null)+ const [captchaDifficulty, setCaptchaDifficulty] = useState<number>(4)const [showRegenerateSecret, setShowRegenerateSecret] = useState(false)+ const [isSavingDifficulty, setIsSavingDifficulty] = useState(false)// for reset data via filtersconst [activeFilter, setActiveFilter] = useState<string[]>([])@@ -436,6 +438,7 @@ const ProjectSettings = () => {const result = await getProject(projectId)setProject(result)setCaptchaSecretKey(result.captchaSecretKey)+ setCaptchaDifficulty(result.captchaDifficulty || 4)setForm({...result,ipBlacklist: _isString(result.ipBlacklist) ? result.ipBlacklist : _join(result.ipBlacklist, ', '),@@ -1001,6 +1004,59 @@ const ProjectSettings = () => {value={captchaSecretKey}disabled/>++ <div className='mt-6'>+ <Select+ label={t('project.settings.captcha.difficulty')}+ hint={t('project.settings.captcha.difficultyHint')}+ className='lg:w-1/2'+ hintClassName='lg:w-2/3'+ items={[+ { value: 2, label: t('project.settings.captcha.difficultyLevels.veryEasy') },+ { value: 3, label: t('project.settings.captcha.difficultyLevels.easy') },+ { value: 4, label: t('project.settings.captcha.difficultyLevels.medium') },+ { value: 5, label: t('project.settings.captcha.difficultyLevels.hard') },+ { value: 6, label: t('project.settings.captcha.difficultyLevels.veryHard') },+ ]}+ keyExtractor={(item) => String(item.value)}+ labelExtractor={(item) => item.label}+ onSelect={(item: { value: number; label: string }) => {+ setCaptchaDifficulty(item.value)+ }}+ title={+ captchaDifficulty === 2+ ? t('project.settings.captcha.difficultyLevels.veryEasy')+ : captchaDifficulty === 3+ ? t('project.settings.captcha.difficultyLevels.easy')+ : captchaDifficulty === 4+ ? t('project.settings.captcha.difficultyLevels.medium')+ : captchaDifficulty === 5+ ? t('project.settings.captcha.difficultyLevels.hard')+ : t('project.settings.captcha.difficultyLevels.veryHard')+ }+ />+ <Button+ type='button'+ className='mt-4'+ loading={isSavingDifficulty}+ onClick={async () => {+ setIsSavingDifficulty(true)+ try {+ await updateProject(id, { captchaDifficulty })+ toast.success(t('project.settings.updated'))+ } catch (reason: any) {+ toast.error(typeof reason === 'string' ? reason : t('apiNotifications.somethingWentWrong'))+ } finally {+ setIsSavingDifficulty(false)+ }+ }}+ primary+ regular+ >+ {t('common.save')}+ </Button>+ </div>+<div className='mt-4 flex gap-2'><Button type='button' onClick={() => setShowRegenerateSecret(true)} danger regular>{t('project.settings.captcha.regenerateKey')}