agentleFS
MicrosoftKnown publishermicrosoft/data-formulator/.cursor/rules/log-sanitization.mdc

data-formulator / rules

Cursor rule18k starsChanged 7 months agoMITView on GitHub

Prevent sensitive data leakage in server-side log messages

Trending

Steady talk.about the whole repository

Dec 2025: 0 mentionsJan 2026: 0 mentionsFeb 2026: 1 mentionMar 2026: 0 mentionsApr 2026: 0 mentionsMay 2026: 2 mentionsJun 2026: 0 mentionsJul 2026: 1 mentionAug 2026: 1 mentionSep 2026: 0 mentionsOct 2026: 2 mentionsNov 2026: 0 mentions
Dec 2025Jun 2026Nov 2026
Mentions a month of the microsoft/data-formulator repository that our weekly crawl found. There is no adoption data for this file yet.

Who's talking about microsoft/data-formulator

The biggest 5 of 31 mentions linking to the repository that our crawl found. Each line is their own headline.

See all 31

Talked about on Bluesky, GitHub and Hacker News (31 times).

On Bluesky · 22

17 more on Bluesky

On GitHub · 7

2 more on GitHub

The file

We split this log-sanitization.mdc into the rules it gives an agent

4 rules. About 0 are common, 1 is distinctive, and 3 are very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈1

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 3

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Very specific:

    Never log full tokens or API keys: Use redact_token() if you need to identify a token in logs.

    line 38
  2. Very specific:

    Use %s-style formatting: instead of f-strings for log messages.

    line 50
  3. Very specific:

    If your module introduces a new credential key name (e.g.

    line 94
  4. Distinctive:

    When creating a new module or feature that handles credentials or external services:

    line 100

≈ “Common” is an estimate: at least 1 in 5 of the 3,030 Cursor rule files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
log-sanitization.mdc
---
description: Prevent sensitive data leakage in server-side log messages
globs: py-src/**/*.py
alwaysApply: false
---

# Log Sanitization

Server-side logs must never contain passwords, tokens, API keys, or other credentials
in plain text. This rule complements `error-response-safety.mdc` (which covers client
responses) by addressing the **logging** side.

## Architecture: Defense in Depth

Two layers protect against sensitive data in logs:

1. **Layer 1 — Explicit utilities** (call-site): developers use `sanitize_url()`,
   `sanitize_params()`, `redact_token()` from `security/log_sanitizer.py`.
2. **Layer 2 — SensitiveDataFilter** (global): a `logging.Filter` registered on all
   handlers in `configure_logging()` auto-redacts patterns that slip through.

Layer 1 is the primary defense; Layer 2 is a safety net. Both are required.

## When to Use Each Utility

| Data Type | Utility | Example |
|-----------|---------|---------|
| `dict` with password/secret/token keys | `sanitize_params(params)` | `log.info("Init: %s", sanitize_params(params))` |
| URL (may have `user:pass@host` or sensitive query params) | `sanitize_url(url)` | `logger.info("Connecting to %s", sanitize_url(url))` |
| Bearer / access token | `redact_token(token)` | `logger.debug("Token: %s", redact_token(token))` |
| Normal string (no secrets) | Nothing needed | `logger.info("Processing table %s", name)` |

## Rules

1. **Never log raw `params` / `config` dicts** that may contain `password`, `secret`,
   `api_key`, `token`, or `connection_string` keys. Always use `sanitize_params()`.

2. **Never log full tokens or API keys.** Use `redact_token()` if you need to identify
   a token in logs.

3. **Prefer `type(exc).__name__`** over `str(exc)` in warning/info logs when the
   exception may contain connection strings or upstream response bodies. Use
   `exc_info=True` for full tracebacks at ERROR level (the filter sanitizes `exc_text`).

4. **URL logging** — use `sanitize_url()` for any URL from configuration or
   environment variables (issuer URLs, JWKS URLs, database URLs, API base URLs).
   It masks embedded credentials and sensitive query parameters such as
   `password`, `client_secret`, `token`, and `api_key`.

5. **Use `%s`-style formatting** instead of f-strings for log messages. This allows
   the filter to intercept arguments before formatting and provides better
   compatibility with log aggregation tools.

## Common Mistakes

```python
# BAD — dict may contain password
log.info(f"Connecting with {params}")
log.info("Connecting with %s", params)

# GOOD
from data_formulator.security.log_sanitizer import sanitize_params
log.info("Connecting with %s", sanitize_params(params))

# BAD — URL may embed credentials
logger.warning("Failed for %s", discovery_url)

# GOOD
from data_formulator.security.log_sanitizer import sanitize_url
logger.warning("Failed for %s", sanitize_url(discovery_url))

# BAD — exception may leak connection string or upstream body
logger.warning("Error: %s", exc)

# GOOD — log type name at warning level, full traceback at error level
logger.warning("Error: %s", type(exc).__name__)
logger.error("Unexpected failure", exc_info=True)

# BAD — full token in logs
logger.debug("Using token %s", token)

# GOOD
from data_formulator.security.log_sanitizer import redact_token
logger.debug("Using token %s", redact_token(token))
```

## Disabling for Local Debug

Set `LOG_SANITIZE=false` to disable the global filter during local debugging.
This should **never** be used in production or CI.

## Adding New Sensitive Keys

If your module introduces a new credential key name (e.g. `custom_auth_token`),
add it to `SENSITIVE_KEYS` in `security/log_sanitizer.py` and add a corresponding
regex pattern to `_SENSITIVE_KEY_NAMES` if needed.

## New Module Checklist

When creating a new module or feature that handles credentials or external services:

- [ ] Audit all `logger.*()` calls — do any log connection params, URLs, or tokens?
- [ ] Use `sanitize_params()` for any dict that may contain credentials
- [ ] Use `sanitize_url()` for any URL from config/env
- [ ] Use `redact_token()` for any token/key value
- [ ] If introducing new credential key names, update `SENSITIVE_KEYS`
- [ ] Run `python -m pytest tests/backend/security/test_log_sanitizer.py` to verify

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.