golang-auth-api / rules
Cursor rule130 starsChanged 16 months agoMITView on GitHub
Security patterns
We split this security-patterns.mdc into the rules it gives an agent
5 rules. About 0 are common, 4 are distinctive, and 1 is very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
1
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 38
Never expose sensitive data in responses
- Distinctive: line 39
Use environment variables for secrets
- Very specific: line 58
Use go-playground/validator tags in DTOs
- Distinctive: line 92
Never log sensitive information
- Distinctive: line 123
Test input validation boundaries
≈ “Common” is an estimate: at least 1 in 5 of the 6,350 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.
Files
--- description: Security patterns globs: alwaysApply: false --- # Security Patterns and Best Practices ## Authentication Flow ### JWT Token Management - Access tokens: Short-lived (15 minutes default) - Refresh tokens: Long-lived (720 hours default) - Token rotation on refresh - Redis-based session management ### Two-Factor Authentication (2FA) - TOTP (Time-based One-Time Password) implementation - QR code generation for authenticator apps - Recovery codes for backup access - Secure secret generation and storage ### Social Authentication - OAuth2 flow with state verification - Secure provider callback handling - User account linking/creation - Scope validation ## Security Configuration ### Security Scanning Configuration in [.gosec.json](mdc:.gosec.json): - Medium severity and confidence thresholds - Excludes vendor and node_modules directories - Includes test files in scanning - JSON output format for CI/CD integration ### Environment Security - Never expose sensitive data in responses - Use environment variables for secrets - Hash passwords with bcrypt - Secure session management with Redis ## Authorization Patterns ### Middleware Protection - JWT validation in `middleware.AuthMiddleware()` - User context extraction - Route-level protection in [cmd/api/main.go](mdc:cmd/api/main.go) ### Role-Based Access Control (Future) - Admin routes prepared for role checking - Extensible middleware pattern - User role management ready ## Input Validation and Sanitization ### Request Validation - Use `go-playground/validator` tags in DTOs - Validate all user inputs before processing - Sanitize data before database operations - Parameterized queries to prevent SQL injection ### Rate Limiting (Recommended) - Implement rate limiting for authentication endpoints - Protect against brute force attacks - Monitor suspicious activity patterns ## Security Event Logging ### Activity Logging System - Log all authentication events - Track user activities with context - Include IP address, user agent, timestamps - Pagination and filtering for security analysis ### Security-Relevant Events - Login attempts (success/failure) - Password changes - 2FA enable/disable - Account modifications - Suspicious activity detection ## Data Protection ### Password Security - Bcrypt hashing with appropriate cost - Password complexity requirements - Secure password reset flow - Protection against timing attacks ### Sensitive Data Handling - Never log sensitive information - Secure token storage and transmission - Proper secret rotation procedures - Clean error messages (no information leakage) ## Network Security ### HTTPS Requirements - Enforce HTTPS in production - Secure cookie settings - CORS policy implementation - Security headers configuration ### Database Security - Connection pooling with limits - Secure connection strings - Database access control - Regular security updates ## Vulnerability Management ### Security Scanning Tools - gosec for Go-specific security issues - nancy for vulnerability scanning - Regular dependency updates - Automated security checks in CI/CD ### Security Testing - Include security test cases - Test authentication flows - Validate authorization controls - Test input validation boundaries ## Production Security Checklist ### Deployment Security - Environment variable protection - Secure container images - Network isolation - Monitoring and alerting - Regular security audits - Incident response procedures
Where files are headingNew Cursor rule files have more rules about planning and tracking tasks, and fewer about code style.
Of the Cursor rule files we read, the 3,978 first seen in the last six months, against the older ones: the kind of rule that gained most share, and the kind that lost most. About files like this in general, not this one, and an estimate, since a kind is a pattern in the words.
In this repository7 other files it gives its agents.
- AGENTS.mdAGENTS.md
- .github/copilot-instructions.mdCopilot instructions
- .cursor/rules/api-development.mdcCursor rule
- .cursor/rules/code-patterns.mdcCursor rule
- .cursor/rules/commit-messages.mdcCursor rule
- .cursor/rules/development-workflow.mdcCursor rule
- .cursor/rules/project-structure.mdcCursor rule
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
Reviews can't be read right now.
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.

