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!

remove regex

Blue Mouse9403f890a506
diff --git a/backend/apps/cloud/src/goal/dto/goal.dto.ts b/backend/apps/cloud/src/goal/dto/goal.dto.ts
index 852511446..94498e4bc 100644
--- a/backend/apps/cloud/src/goal/dto/goal.dto.ts
+++ b/backend/apps/cloud/src/goal/dto/goal.dto.ts
@@ -8,65 +8,13 @@ import {
MaxLength,
IsBoolean,
IsNotEmpty,
- ValidatorConstraint,
- ValidatorConstraintInterface,
- ValidationArguments,
- Validate,
+ IsIn,
} from 'class-validator'
import { Type } from 'class-transformer'
import { GoalType, GoalMatchType, MetadataFilter } from '../entity/goal.entity'
-// Maximum regex length to prevent ReDoS attacks
-const MAX_REGEX_LENGTH = 200
-
-// Patterns that could cause catastrophic backtracking (ReDoS)
-const DANGEROUS_REGEX_PATTERNS = [
- /(\+|\*|\?)\1{2,}/, // Nested quantifiers like +++, ***, ???
- /\(\?[^)]*\)\+/, // Possessive quantifiers (not supported, but flag anyway)
- /\([^)]*\)\{\d+,\}.*\1/, // Backreferences with quantifiers
- /(\.\*){3,}/, // Multiple consecutive .* patterns
- /\([^)]*\|[^)]*\)\+/, // Alternation with + quantifier
-]
-
-@ValidatorConstraint({ name: 'safeRegex', async: false })
-export class SafeRegexConstraint implements ValidatorConstraintInterface {
- validate(value: string, args: ValidationArguments): boolean {
- const obj = args.object as any
-
- // Only validate if matchType is regex
- if (obj.matchType !== GoalMatchType.REGEX) {
- return true
- }
-
- if (!value) {
- return true
- }
-
- // Check length
- if (value.length > MAX_REGEX_LENGTH) {
- return false
- }
-
- // Check for dangerous patterns
- for (const pattern of DANGEROUS_REGEX_PATTERNS) {
- if (pattern.test(value)) {
- return false
- }
- }
-
- // Try to compile the regex to ensure it's valid
- try {
- new RegExp(value)
- return true
- } catch {
- return false
- }
- }
-
- defaultMessage(_args: ValidationArguments): string {
- return `Invalid regex pattern. Ensure the pattern is valid, not longer than ${MAX_REGEX_LENGTH} characters, and doesn't contain potentially dangerous constructs.`
- }
-}
+// Allowed match types for API (regex is disabled for now)
+const ALLOWED_MATCH_TYPES = [GoalMatchType.EXACT, GoalMatchType.CONTAINS]
export class MetadataFilterDto implements MetadataFilter {
@ApiProperty()
@@ -96,15 +44,19 @@ export class CreateGoalDto {
@IsEnum(GoalType)
type: GoalType
- @ApiProperty({ enum: GoalMatchType, description: 'How to match the value' })
- @IsEnum(GoalMatchType)
+ @ApiProperty({
+ enum: [GoalMatchType.EXACT, GoalMatchType.CONTAINS],
+ description: 'How to match the value',
+ })
+ @IsIn(ALLOWED_MATCH_TYPES, {
+ message: 'matchType must be either "exact" or "contains"',
+ })
matchType: GoalMatchType
@ApiPropertyOptional({ description: 'Page path or event name to match' })
@IsString()
@MaxLength(500)
@IsOptional()
- @Validate(SafeRegexConstraint)
value?: string
@ApiPropertyOptional({
@@ -131,10 +83,12 @@ export class UpdateGoalDto {
type?: GoalType
@ApiPropertyOptional({
- enum: GoalMatchType,
+ enum: [GoalMatchType.EXACT, GoalMatchType.CONTAINS],
description: 'How to match the value',
})
- @IsEnum(GoalMatchType)
+ @IsIn(ALLOWED_MATCH_TYPES, {
+ message: 'matchType must be either "exact" or "contains"',
+ })
@IsOptional()
matchType?: GoalMatchType
@@ -142,7 +96,6 @@ export class UpdateGoalDto {
@IsString()
@MaxLength(500)
@IsOptional()
- @Validate(SafeRegexConstraint)
value?: string
@ApiPropertyOptional({
diff --git a/backend/apps/cloud/src/goal/goal.controller.ts b/backend/apps/cloud/src/goal/goal.controller.ts
index cee54b458..2c8184da3 100644
--- a/backend/apps/cloud/src/goal/goal.controller.ts
+++ b/backend/apps/cloud/src/goal/goal.controller.ts
@@ -292,38 +292,26 @@ export class GoalController {
if (goal.matchType === GoalMatchType.EXACT) {
params.goalValue = goal.value || ''
return { condition: `ev = {goalValue:String}`, params }
- } else if (goal.matchType === GoalMatchType.CONTAINS) {
+ } else {
+ // Contains match
params.goalValue = goal.value || ''
return {
condition: `ev ILIKE concat('%', {goalValue:String}, '%')`,
params,
}
- } else {
- // Regex match
- if (!goal.value) {
- return { condition: '0', params }
- }
- params.goalValue = goal.value
- return { condition: `match(ev, {goalValue:String})`, params }
}
} else {
// For pageview goals, match the page path
if (goal.matchType === GoalMatchType.EXACT) {
params.goalValue = goal.value || ''
return { condition: `pg = {goalValue:String}`, params }
- } else if (goal.matchType === GoalMatchType.CONTAINS) {
+ } else {
+ // Contains match
params.goalValue = goal.value || ''
return {
condition: `pg ILIKE concat('%', {goalValue:String}, '%')`,
params,
}
- } else {
- // Regex match
- if (!goal.value) {
- return { condition: '0', params }
- }
- params.goalValue = goal.value
- return { condition: `match(pg, {goalValue:String})`, params }
}
}
}
diff --git a/backend/apps/community/src/goal/dto/goal.dto.ts b/backend/apps/community/src/goal/dto/goal.dto.ts
index b77641c5a..d5d0c66be 100644
--- a/backend/apps/community/src/goal/dto/goal.dto.ts
+++ b/backend/apps/community/src/goal/dto/goal.dto.ts
@@ -7,65 +7,13 @@ import {
MaxLength,
IsBoolean,
IsNotEmpty,
- ValidatorConstraint,
- ValidatorConstraintInterface,
- ValidationArguments,
- Validate,
+ IsIn,
} from 'class-validator'
import { Type } from 'class-transformer'
import { GoalType, GoalMatchType, MetadataFilter } from '../entity/goal.entity'
-// Maximum regex length to prevent ReDoS attacks
-const MAX_REGEX_LENGTH = 200
-
-// Patterns that could cause catastrophic backtracking (ReDoS)
-const DANGEROUS_REGEX_PATTERNS = [
- /(\+|\*|\?)\1{2,}/, // Nested quantifiers like +++, ***, ???
- /\(\?[^)]*\)\+/, // Possessive quantifiers (not supported, but flag anyway)
- /\([^)]*\)\{\d+,\}.*\1/, // Backreferences with quantifiers
- /(\.\*){3,}/, // Multiple consecutive .* patterns
- /\([^)]*\|[^)]*\)\+/, // Alternation with + quantifier
-]
-
-@ValidatorConstraint({ name: 'safeRegex', async: false })
-export class SafeRegexConstraint implements ValidatorConstraintInterface {
- validate(value: string, args: ValidationArguments): boolean {
- const obj = args.object as any
-
- // Only validate if matchType is regex
- if (obj.matchType !== GoalMatchType.REGEX) {
- return true
- }
-
- if (!value) {
- return true
- }
-
- // Check length
- if (value.length > MAX_REGEX_LENGTH) {
- return false
- }
-
- // Check for dangerous patterns
- for (const pattern of DANGEROUS_REGEX_PATTERNS) {
- if (pattern.test(value)) {
- return false
- }
- }
-
- // Try to compile the regex to ensure it's valid
- try {
- new RegExp(value)
- return true
- } catch {
- return false
- }
- }
-
- defaultMessage(_args: ValidationArguments): string {
- return `Invalid regex pattern. Ensure the pattern is valid, not longer than ${MAX_REGEX_LENGTH} characters, and doesn't contain potentially dangerous constructs.`
- }
-}
+// Allowed match types for API (regex is disabled for now)
+const ALLOWED_MATCH_TYPES = [GoalMatchType.EXACT, GoalMatchType.CONTAINS]
export class MetadataFilterDto implements MetadataFilter {
@IsString()
@@ -90,13 +38,14 @@ export class CreateGoalDto {
@IsEnum(GoalType)
type: GoalType
- @IsEnum(GoalMatchType)
+ @IsIn(ALLOWED_MATCH_TYPES, {
+ message: 'matchType must be either "exact" or "contains"',
+ })
matchType: GoalMatchType
@IsString()
@MaxLength(500)
@IsOptional()
- @Validate(SafeRegexConstraint)
value?: string
@IsArray()
@@ -116,14 +65,15 @@ export class UpdateGoalDto {
@IsOptional()
type?: GoalType
- @IsEnum(GoalMatchType)
+ @IsIn(ALLOWED_MATCH_TYPES, {
+ message: 'matchType must be either "exact" or "contains"',
+ })
@IsOptional()
matchType?: GoalMatchType
@IsString()
@MaxLength(500)
@IsOptional()
- @Validate(SafeRegexConstraint)
value?: string
@IsArray()
diff --git a/backend/apps/community/src/goal/goal.controller.ts b/backend/apps/community/src/goal/goal.controller.ts
index 598bba7b3..23e3e6834 100644
--- a/backend/apps/community/src/goal/goal.controller.ts
+++ b/backend/apps/community/src/goal/goal.controller.ts
@@ -241,38 +241,26 @@ export class GoalController {
if (goal.matchType === GoalMatchType.EXACT) {
params.goalValue = goal.value || ''
return { condition: `ev = {goalValue:String}`, params }
- } else if (goal.matchType === GoalMatchType.CONTAINS) {
+ } else {
+ // Contains match
params.goalValue = goal.value || ''
return {
condition: `ev ILIKE concat('%', {goalValue:String}, '%')`,
params,
}
- } else {
- // Regex match
- if (!goal.value) {
- return { condition: '0', params }
- }
- params.goalValue = goal.value
- return { condition: `match(ev, {goalValue:String})`, params }
}
} else {
// For pageview goals, match the page path
if (goal.matchType === GoalMatchType.EXACT) {
params.goalValue = goal.value || ''
return { condition: `pg = {goalValue:String}`, params }
- } else if (goal.matchType === GoalMatchType.CONTAINS) {
+ } else {
+ // Contains match
params.goalValue = goal.value || ''
return {
condition: `pg ILIKE concat('%', {goalValue:String}, '%')`,
params,
}
- } else {
- // Regex match
- if (!goal.value) {
- return { condition: '0', params }
- }
- params.goalValue = goal.value
- return { condition: `match(pg, {goalValue:String})`, params }
}
}
}
diff --git a/web/app/api/index.ts b/web/app/api/index.ts
index 28ea14f4c..880685ccb 100644
--- a/web/app/api/index.ts
+++ b/web/app/api/index.ts
@@ -1139,7 +1139,7 @@ export interface Goal {
id: string
name: string
type: 'pageview' | 'custom_event'
- matchType: 'exact' | 'contains' | 'regex'
+ matchType: 'exact' | 'contains'
value: string | null
metadataFilters: { key: string; value: string }[] | null
active: boolean
@@ -1200,7 +1200,7 @@ export type CreateGoal = {
pid: string
name: string
type: 'pageview' | 'custom_event'
- matchType: 'exact' | 'contains' | 'regex'
+ matchType: 'exact' | 'contains'
value?: string
metadataFilters?: { key: string; value: string }[]
}
diff --git a/web/app/lib/models/Goal.ts b/web/app/lib/models/Goal.ts
index f1c5ee966..01cd4f653 100644
--- a/web/app/lib/models/Goal.ts
+++ b/web/app/lib/models/Goal.ts
@@ -1,5 +1,5 @@
export type GoalType = 'pageview' | 'custom_event'
-export type GoalMatchType = 'exact' | 'contains' | 'regex'
+export type GoalMatchType = 'exact' | 'contains'
export interface MetadataFilter {
key: string
@@ -50,5 +50,4 @@ export const GOAL_TYPE_LABELS: Record<GoalType, string> = {
export const GOAL_MATCH_TYPE_LABELS: Record<GoalMatchType, string> = {
exact: 'Exact match',
contains: 'Contains',
- regex: 'Regex',
}
diff --git a/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx b/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
index 36bfd10fd..e6fe64a15 100644
--- a/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
+++ b/web/app/pages/Project/Goals/View/GoalSettingsModal.tsx
@@ -20,7 +20,6 @@ const GOAL_TYPES = [
const GOAL_MATCH_TYPES = [
{ value: 'exact', label: 'Exact match' },
{ value: 'contains', label: 'Contains' },
- { value: 'regex', label: 'Regular expression' },
]
interface GoalSettingsModalProps {
@@ -41,7 +40,7 @@ const GoalSettingsModal = ({ isOpen, onClose, onSuccess, projectId, goalId }: Go
// Form state
const [name, setName] = useState('')
const [type, setType] = useState<'pageview' | 'custom_event'>('pageview')
- const [matchType, setMatchType] = useState<'exact' | 'contains' | 'regex'>('exact')
+ const [matchType, setMatchType] = useState<'exact' | 'contains'>('exact')
const [value, setValue] = useState('')
const [metadataFilters, setMetadataFilters] = useState<{ key: string; value: string }[]>([])
@@ -197,7 +196,7 @@ const GoalSettingsModal = ({ isOpen, onClose, onSuccess, projectId, goalId }: Go
</label>
<Select
items={GOAL_MATCH_TYPES}
- onSelect={(item) => setMatchType(item.value as 'exact' | 'contains' | 'regex')}
+ onSelect={(item) => setMatchType(item.value as 'exact' | 'contains')}
title={GOAL_MATCH_TYPES.find((t) => t.value === matchType)?.label || ''}
labelExtractor={(item) => item.label}
keyExtractor={(item) => item.value}
@@ -214,14 +213,10 @@ const GoalSettingsModal = ({ isOpen, onClose, onSuccess, projectId, goalId }: Go
type === 'pageview'
? matchType === 'exact'
? '/pricing'
- : matchType === 'contains'
- ? 'pricing'
- : '^/blog/.*'
+ : 'pricing'
: matchType === 'exact'
? 'signup_completed'
- : matchType === 'contains'
- ? 'signup'
- : 'signup_.*'
+ : 'signup'
}
/>
diff --git a/web/app/pages/Project/Goals/View/GoalsView.tsx b/web/app/pages/Project/Goals/View/GoalsView.tsx
index 1d8c6b971..985a0bca4 100644
--- a/web/app/pages/Project/Goals/View/GoalsView.tsx
+++ b/web/app/pages/Project/Goals/View/GoalsView.tsx
@@ -260,8 +260,7 @@ const GoalRow = ({
const patternDisplay = useMemo(() => {
if (!goal.value) return null
- const matchPrefix =
- goal.matchType === 'exact' ? '= ' : goal.matchType === 'contains' ? '~ ' : goal.matchType === 'regex' ? '⁓ ' : ''
+ const matchPrefix = goal.matchType === 'exact' ? '= ' : goal.matchType === 'contains' ? '~ ' : ''
return `${matchPrefix}${goal.value}`
}, [goal.value, goal.matchType])