Zum Hauptinhalt springen
Echtzeit-Radar & Feeds
Alle RSS Feeds ➔
👥 Community & Social
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Windows Tipps & SecurityGrafikkarte vor Überhitzung schützen: So geht’s(25.09.2026 um 08:00 Uhr)
••••••••••
Intelligence View
⚡ tsecurity.de Intelligence

class-validator Cheatsheet: Useful Decorators and NestJS Validation Patterns (2025)

This is your complete reference for all major class-validator decorators, their usage, value types, and integration patterns. Bookmark this if you’re working with DTOs in NestJS or doing input validation in any TypeScript project. …

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

This is your complete reference for all major class-validator decorators, their usage, value types, and integration patterns. Bookmark this if you’re working with DTOs in NestJS or doing input validation in any TypeScript project.










🚀 Install First






npm install class-validator class-transformer












✅ Basic Usage Pattern






import { IsEmail, MinLength, validate } from 'class-validator';

class LoginDto {
@IsEmail()
email: string;

@MinLength(6)
password: string;
}

const login = new LoginDto();
login.email = 'invalid';
login.password = '123';

const errors = await validate(login);












🧾 Core Decorators Reference


























































Decorator Purpose Accepted Type(s)
@IsString() Must be a string string
@IsBoolean() Must be boolean boolean
@IsInt() Must be an integer number
@IsNumber() Any number (int or float) number
@IsEmail() Valid email address string
@IsDate() Must be a Date instance Date
@IsOptional() Skip validation if undefined/null any
@IsNotEmpty() Not empty (works with string, array)
string, array
@IsDefined() Value must be present (not undefined) any








🔢 Number Validations




























Decorator Description
@Min(value) Minimum number allowed
@Max(value) Maximum number allowed
@IsPositive() Must be positive
@IsNegative() Must be negative








🔠 String Validations








































Decorator Description
@MinLength(n) Minimum string length
@MaxLength(n) Maximum string length
@Matches(regex) Must match regex pattern
@IsAlpha() Only letters
@IsAlphanumeric() Letters and numbers only
@IsPhoneNumber() Must be a valid phone number
@IsUrl() Must be a valid URL








🔁 Array Validations
































Decorator Description
@IsArray() Must be an array
@ArrayMinSize(n) Minimum length of array
@ArrayMaxSize(n) Maximum length of array
@ArrayNotEmpty() Must not be empty
@IsInt({ each: true }) Validates each element (works with many)








🔘 Enum & Object Validations






enum Role { USER = 'user', ADMIN = 'admin' }

@IsEnum(Role)
role: Role;









@ValidateNested()
@Type(() => Profile)
profile: Profile;








  • @ValidateNested() is required for nested objects

  • Must be combined with @Type(() => ClassName) from class-transformer









⚖️ Conditional Validation






@ValidateIf(o => o.isAdult)
@IsString()
licenseNumber: string;






Use @ValidateIf() to apply a rule conditionally based on other values.









🛠 Custom Validators






@ValidatorConstraint({ name: 'IsStrongPassword', async: false })
class IsStrongPassword implements ValidatorConstraintInterface {
validate(value: string) {
return typeof value === 'string' && value.length >= 8 && /[A-Z]/.test(value);
}

defaultMessage() {
return 'Password must be at least 8 chars and include an uppercase letter.';
}
}






Use it like this:




@Validate(IsStrongPassword)
password: string;












⚙️ NestJS Global Integration






// main.ts
app.useGlobalPipes(new ValidationPipe({
whitelist: true,
forbidNonWhitelisted: true,
transform: true,
transformOptions: { enableImplicitConversion: true }
}));












🧠 Common Mistakes to Avoid




  • ❌ Forgetting @Type(): Nested validation won’t work without it

  • ❌ Validating plain objects: Use plainToInstance() from class-transformer

  • ❌ Wrong order of decorators: Execution is bottom-to-top, so arrange carefully









📦 Pro Tips




  • Combine @IsOptional() with other validators to skip when empty

  • Use { each: true } to apply decorators to every array element

  • Custom validators = reusable logic for business rules

  • Enable stopAtFirstError in ValidationPipe to fail fast









🔗 Resources








✅ Use this cheatsheet in every TypeScript API project using DTOs. Fast, reliable, and easy to maintain.

1. Sofort-Triage & Abwehrmaßnahmen

SOC Incident Playbook: Remote Code Execution (RCE) Defense
Syntax validiert (0 Fehler)
title: Detect Exploitation - class-validator Cheatsheet: Useful Decorators and NestJS Validation Patterns (2025)
id: 7426d3cb-20fa-4a93-92f3-1d83d64ead6a
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-26
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
Syntax validiert (0 Fehler)
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-26"
        description = "YARA Signature for "
    strings:
        $str = "class-validator Cheatsheet: Us" ascii wide
    condition:
        any of them
}
Syntax validiert (0 Fehler)
index=security sourcetype IN ("cisco:asa", "pan:traffic", "zeek_conn", "suricata", "WinEventLog:Security")
("class-validator Cheatsheet Useful Decora")
| stats count earliest(_time) as first_seen latest(_time) as last_seen by src_ip, dest_ip, dest_host, signature
| eval first_seen=strftime(first_seen, "%Y-%m-%d %H:%M:%S"), last_seen=strftime(last_seen, "%Y-%m-%d %H:%M:%S")
| sort - count
Syntax validiert (0 Fehler)
message: "*class-validator Cheatsheet Useful Decora*"
Syntax validiert (0 Fehler)
CommonSecurityLog
| where Message has "class-validator Cheatsheet Useful Decora"
| summarize EventCount = count(), FirstSeen = min(TimeGenerated), LastSeen = max(TimeGenerated) by SourceIP, DestinationIP, DestinationPort, Activity
| extend DetectionRule = "iShareStuff-CTI-Compiled"
| sort by EventCount desc

2. Cyber Threat Intelligence & Forensik

🎯
MITRE ATT&CK Matrix Navigator 14 Taktiken
Reconnaissance
-
Resource Development
-
Initial Access
Execution
Persistence
-
Privilege Escalation
Defense Evasion
Credential Access
-
Discovery
-
Lateral Movement
-
Collection
-
Command and Control
Exfiltration
-
Impact
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich class-validator Cheatsheet: Useful Decor.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

⚡ Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten class-validator Cheatsheet: Useful Decorators and NestJS Validation Patterns (2025)

Thematisch verwandte Begriffe: classvalidator, Cheatsheet, Useful, Decorators · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-88003 | InvoicePlane is a self-hosted open source application for managing invoi…
Advisory →
tsecurity.de Icon
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag