<!--
title: Secure credential data handling
domain: ai-agents
topic: Security
language: TypeScript
source: n8n-io/n8n
updated: 2025-07-22
url: https://awesomereviewers.com/reviewers/n8n-secure-credential-data-handling/
-->

Always protect sensitive credential data through proper encryption, secure storage, and careful handling in code. Key requirements:

1. Never store credentials in plaintext within source code
2. Use appropriate encryption for sensitive fields
3. Preserve user-configured security settings
4. Handle credential updates safely

Example - Instead of:
```typescript
class Config {
  password: string = 'admin';  // BAD: Hardcoded credential
  
  constructor(options) {
    this.tls = {};  // BAD: Overwrites user TLS settings
  }
}
```

Use:
```typescript
class Config {
  @Env('DB_PASSWORD')  // GOOD: Environment variable
  password: string = '';
  
  constructor(options) {
    this.tls = options.tls ?? {};  // GOOD: Preserves settings
  }
}

// GOOD: Proper credential field protection
class Credentials {
  @Column({
    type: 'string',
    typeOptions: { password: true }  // Enables encryption
  })
  sslKey: string;
}
