Skip to content
Back to skills

1488 Best Practices 3273e09c

ASecurity

**Always log:** - Event type and timestamp - User identifier (when available) - Success/failure status - Source IP address - Resource accessed - Action performed

  • 9 stars
  • 0 votes
  • 0 copies
  • 0 views
  • Added October 11, 2026
securityrailsgitapisecurityperformance

Works with

  • api

Security analysis

A100/100

Scanned October 11, 2026

npx -y skills add tools-only/X-Skills --skill 1488-best_practices_3273e09c --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of 1488 Best Practices 3273e09c?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for 1488 Best Practices 3273e09c
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/tools-only-1488-best-practices-3273e09c/badge)](https://www.skillsdirectory.com/skills/tools-only-1488-best-practices-3273e09c)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

SKILL.md
# Security Logging Best Practices

## What to Log

**Always log:**
- Event type and timestamp
- User identifier (when available)
- Success/failure status
- Source IP address
- Resource accessed
- Action performed

**Context to include:**
- Request ID for correlation
- Session ID (hashed)
- User agent
- Relevant business context

## What NOT to Log

**Never log:**
- Passwords (plaintext or hashed)
- Credit card numbers
- Social Security numbers
- API keys or secrets
- Session tokens (full value)
- Encryption keys
- Personal health information (PHI)

**Sanitize before logging:**
- Email addresses (consider hashing or masking)
- Phone numbers
- Full names (in some contexts)
- IP addresses (consider GDPR implications)

## Log Levels

**CRITICAL/ERROR:**
- Authentication failures after multiple attempts
- Authorization violations
- Detected attack patterns
- System security failures

**WARNING:**
- Single authentication failure
- Suspicious patterns
- Deprecated security features used
- Configuration issues

**INFO:**
- Successful authentication
- Authorization decisions
- Session lifecycle events
- Configuration changes

**DEBUG:**
- Detailed validation steps
- Internal security checks
- Performance metrics

## Structured Logging

Use structured logging (JSON) for machine parsing:

```json
{
  "timestamp": "2026-02-17T10:30:45Z",
  "event_type": "authentication_attempt",
  "user_id": "user123",
  "username": "john.doe",
  "ip_address": "192.168.1.100",
  "success": false,
  "failure_reason": "invalid_password",
  "attempt_count": 2,
  "request_id": "req-abc-123"
}
```

## Performance Considerations

- Use asynchronous logging to avoid blocking
- Implement log sampling for high-volume events
- Set appropriate log retention policies
- Consider log aggregation costs

## Compliance

**GDPR:**
- Minimize personal data in logs
- Implement log retention limits
- Support data deletion requests
- Document legitimate interest

**PCI DSS:**
- Never log full credit card numbers
- Mask PANs if logging required
- Secure log storage and transmission
- Implement access controls

**HIPAA:**
- Avoid logging PHI when possible
- Encrypt logs containing health data
- Implement audit trails
- Control access to logs

## Correlation and Context

- Use request IDs to trace requests across services
- Include session IDs for user journey tracking
- Add correlation IDs for distributed tracing
- Link related security events

## Alerting

Configure alerts for:
- Multiple failed authentication attempts
- Authorization violations
- Unusual access patterns
- Detected injection attempts
- Configuration changes
- Privilege escalations

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…

Newsletter

Get the weekly list of safe new skills, and the ones we pulled.