security-logging

Log security events with PII sanitization using a centralized Convex security logger.

Updated Aug 8, 2026
One-click install
npx skills add https://github.com/harperaa/testa2 --skill security-logging-harperaa
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: security-logging
Source: https://github.com/harperaa/testa2/tree/main/.claude/skills/security/security-logging
Command: npx skills add https://github.com/harperaa/testa2 --skill security-logging-harperaa

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve? Security violations like XSS attempts, CSRF failures, and rate limit abuse often go unrecorded or are logged inconsistently with unsanitized PII, making incident response and compliance auditing difficult. ## Core Features & Use Cases - Centralized Security Logger: Use the logSecurity function in convex/lib/securityLogger.ts to record events with automatic PII sanitization of emails, names, and IDs. - Typed Event Taxonomy: Classify events with 19 predefined SecurityEventType values (xss_attempt, csrf_validation_failed, rate_limit_exceeded, prompt_injection_attempt) and four severity levels. - Attack Detection Patterns: Apply built-in regex patterns for XSS, SQL injection, and prompt injection detection before logging violations. - Use Case: When a user submits content containing a script tag, detect the XSS pattern, log a critical xss_attempt event with a truncated payload, and surface it on the admin security dashboard at /dashboard/security. ## Quick Start Add security event logging to my Convex mutation so XSS attempts are detected, sanitized, and recorded to the securityEvents table.

Frequently Asked Questions about security-logging

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I log security events in a Convex mutation?

Import logSecurity from convex/lib/securityLogger and call it inside your mutation handler with the context, user ID, event type, severity, and metadata object. The logger sanitizes PII and inserts the event directly into the securityEvents table.

How do I log security events from a Next.js API route?

Create a ConvexHttpClient, set the Clerk auth token, and call the logSecurityEventForCurrentUser mutation with the event type, severity, and metadata. This routes the event through the authenticated user's context for proper attribution.

What security event types does the logger support?

The SecurityEventType union includes 19 types such as xss_attempt, csrf_validation_failed, rate_limit_exceeded, jwt_validation_failed, prompt_injection_attempt, and tenant_isolation_attack. Severity levels are low, medium, high, and critical.

Does the security logger sanitize PII automatically?

Yes, the securityLogger library hashes or masks emails, names, and user IDs before storage. You should still truncate request payloads to 200 characters and avoid logging full request bodies.

How do I test that security events are being logged?

Run the dev server and execute node scripts/test-rate-limit.js, which sends 10 rapid requests to trigger rate_limit_exceeded events. The events then appear on the admin dashboard at /dashboard/security.

Why are my regex-based attack detectors giving inconsistent results?

Global regex patterns retain state between test calls. Reset pattern.lastIndex to 0 before each test, as shown in the detectXSS implementation, to avoid false negatives on repeated checks.