---
title: Avoid logging sensitive data in cleartext
description: Datadog, the leading service for cloud-scale monitoring.
breadcrumbs: >-
  Docs > Datadog Security > Code Security > Static Code Analysis (SAST) > SAST
  Rules > Avoid logging sensitive data in cleartext
---

> For the complete documentation index, see [llms.txt](https://docs.datadoghq.com/llms.txt).

# Avoid logging sensitive data in cleartext

{% callout %}
# Important note for users on the following Datadog sites: app.ddog-gov.com, us2.ddog-gov.com

{% alert level="danger" %}
This product is not supported for your selected [Datadog site](https://docs.datadoghq.com/getting_started/site.md). ({% placeholder "user-datadog-site-name" /%}).
{% /alert %}

{% /callout %}

## Metadata{% #metadata %}

**ID:** `dart-security/clear-text-logging`

**Language:** Dart

**Severity:** Warning

**Category:** Security

**CWE**: [200](https://cwe.mitre.org/data/definitions/200.html)

## Description{% #description %}

Passing variables named `password`, `token`, `secret`, or `key` to `print()`, `log()`, or `debugPrint()` can expose sensitive values in device logs, crash reports, and monitoring pipelines.

Replace logging of sensitive data with redacted summaries or structured log entries that omit the raw value.

## Non-Compliant Code Examples{% #non-compliant-code-examples %}

```dart
void login(String password) {
  print(password);
}
```

```dart
void store(String apiToken) {
  debugPrint(apiToken);
}
```

```dart
void cache(String secret) {
  log(secret);
}
```

```dart
void debug(String token) {
  print('Current token: $token');
}
```

```dart
void debug(String password) {
  log('Attempting login with: $password');
}
```

## Compliant Code Examples{% #compliant-code-examples %}

```dart
void main() {
  final username = 'alice';
  print(username);
}
```

```dart
void main() {
  print('Login successful');
  log('Server started');
}
```

```dart
void main() {
  final username = 'alice';
  print('Welcome, $username');
}
```
  Seamless integrations. Try Datadog Code SecurityDatadog Code Security 
{% icon name="icon-external-link" /%}
 