Skip to content

Commit 334935b

Browse files
committed
feat(auth): implement access token blacklisting on logout
- Enhanced logout functionality to include access token blacklisting, ensuring immediate invalidation of access tokens upon user logout. - Updated logout request structure to require both refresh and access tokens. - Implemented checks to verify if access tokens are blacklisted, preventing unauthorized access to protected endpoints after logout. - Added comprehensive tests to validate the new logout behavior and token revocation logic. - Updated API documentation to reflect changes in logout request requirements and error responses.
1 parent 668cc15 commit 334935b

File tree

14 files changed

+1207
-54
lines changed

14 files changed

+1207
-54
lines changed

.cursor/rules/commit-messages.mdc

Lines changed: 242 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,242 @@
1+
---
2+
description:
3+
globs:
4+
alwaysApply: true
5+
---
6+
# Commit Message Conventions and Flow
7+
8+
## Commit Message Format
9+
10+
### Standard Format
11+
```
12+
<type>(<scope>): <description>
13+
14+
[optional body]
15+
16+
[optional footer(s)]
17+
```
18+
19+
### Type Categories
20+
21+
#### Core Types
22+
- **feat**: New feature for the user (e.g., new API endpoint, authentication method)
23+
- **fix**: Bug fix for the user (e.g., security vulnerability, broken endpoint)
24+
- **docs**: Documentation changes (README, API docs, comments)
25+
- **style**: Code style changes (formatting, missing semicolons, no logic changes)
26+
- **refactor**: Code refactoring (no new features or bug fixes)
27+
- **test**: Adding or updating tests
28+
- **chore**: Maintenance tasks (dependency updates, build scripts)
29+
30+
#### Security-Specific Types
31+
- **security**: Security patches, vulnerability fixes, security improvements
32+
- **deps**: Dependency updates (especially security-related)
33+
34+
### Scope Guidelines
35+
36+
#### Feature-Based Scopes
37+
- **auth**: Authentication-related changes ([internal/auth/](mdc:internal/auth))
38+
- **user**: User management functionality ([internal/user/](mdc:internal/user))
39+
- **social**: Social login providers ([internal/social/](mdc:internal/social))
40+
- **twofa**: Two-factor authentication ([internal/twofa/](mdc:internal/twofa))
41+
- **email**: Email verification and notifications ([internal/email/](mdc:internal/email))
42+
- **middleware**: HTTP middleware ([internal/middleware/](mdc:internal/middleware))
43+
- **database**: Database operations and migrations ([internal/database/](mdc:internal/database))
44+
- **redis**: Redis operations and caching ([internal/redis/](mdc:internal/redis))
45+
- **log**: Activity logging system ([internal/log/](mdc:internal/log))
46+
47+
#### Technical Scopes
48+
- **api**: API endpoints and handlers
49+
- **models**: Database models ([pkg/models/](mdc:pkg/models))
50+
- **dto**: Data transfer objects ([pkg/dto/](mdc:pkg/dto))
51+
- **jwt**: JWT token handling ([pkg/jwt/](mdc:pkg/jwt))
52+
- **config**: Configuration management ([internal/config/](mdc:internal/config))
53+
- **docker**: Docker configuration ([Dockerfile](mdc:Dockerfile), [docker-compose.yml](mdc:docker-compose.yml))
54+
- **build**: Build system ([Makefile](mdc:Makefile), Go modules)
55+
- **ci**: CI/CD pipeline (.github workflows)
56+
57+
## Commit Message Examples
58+
59+
### Feature Development
60+
```
61+
feat(auth): add JWT token blacklisting for secure logout
62+
63+
- Implement Redis-based token blacklisting
64+
- Add middleware check for blacklisted tokens
65+
- Ensure immediate token invalidation on logout
66+
- Include TTL for automatic cleanup
67+
68+
Closes #123
69+
```
70+
71+
### Security Fixes
72+
```
73+
security(middleware): fix JWT token validation bypass
74+
75+
Critical security patch for authentication middleware that
76+
allows unauthorized access when malformed tokens are provided.
77+
78+
- Validate token format before parsing
79+
- Add proper error handling for invalid tokens
80+
- Include rate limiting for failed attempts
81+
82+
BREAKING CHANGE: Invalid tokens now return 401 instead of 500
83+
```
84+
85+
### API Changes
86+
```
87+
feat(user): add user profile update endpoint
88+
89+
- Add PUT /profile endpoint for user updates
90+
- Implement email change verification flow
91+
- Add validation for profile data
92+
- Update Swagger documentation
93+
94+
Refs #456
95+
```
96+
97+
### Database Changes
98+
```
99+
feat(models): add activity log model for audit tracking
100+
101+
- Create ActivityLog model with GORM tags
102+
- Add database migration for activity_logs table
103+
- Include indexing for performance optimization
104+
- Add foreign key relationships
105+
106+
Migration: 20240121_create_activity_logs.sql
107+
```
108+
109+
### Documentation Updates
110+
```
111+
docs(api): update Swagger annotations for 2FA endpoints
112+
113+
- Add comprehensive examples for TOTP setup
114+
- Document recovery code generation flow
115+
- Include error response schemas
116+
- Update authentication requirements
117+
```
118+
119+
### Testing
120+
```
121+
test(auth): add comprehensive JWT middleware tests
122+
123+
- Test token validation edge cases
124+
- Add blacklist functionality tests
125+
- Include performance benchmarks
126+
- Mock Redis for isolated testing
127+
128+
Coverage: middleware/auth.go 95% -> 98%
129+
```
130+
131+
### Dependency Updates
132+
```
133+
deps(security): update Go dependencies for security patches
134+
135+
- Update golang.org/x/crypto to v0.17.0
136+
- Patch GORM to v1.25.5 for SQL injection fix
137+
- Update Gin framework to v1.9.1
138+
139+
Addresses CVE-2023-45288, CVE-2023-45289
140+
```
141+
142+
## Breaking Changes
143+
144+
### Format for Breaking Changes
145+
```
146+
feat(auth): redesign authentication flow for enhanced security
147+
148+
BREAKING CHANGE: Login endpoint now requires email verification.
149+
All existing API clients must update to handle the new two-step
150+
authentication process.
151+
152+
Migration guide:
153+
1. Update login requests to include verification_required field
154+
2. Implement email verification step before token issuance
155+
3. Update error handling for unverified accounts
156+
157+
Closes #789
158+
```
159+
160+
## Multi-Component Changes
161+
162+
### When Changes Affect Multiple Areas
163+
```
164+
feat(auth,user,middleware): implement role-based access control
165+
166+
- Add Role model and user-role relationships
167+
- Update JWT claims to include user roles
168+
- Add middleware for role-based endpoint protection
169+
- Update user registration to assign default roles
170+
171+
Files modified:
172+
- pkg/models/user.go
173+
- pkg/models/role.go
174+
- internal/middleware/auth.go
175+
- internal/user/service.go
176+
177+
Closes #234, #235, #236
178+
```
179+
180+
## Commit Flow Integration
181+
182+
### Pre-Commit Checklist
183+
Before committing, ensure:
184+
- [ ] Run `make fmt` for code formatting
185+
- [ ] Run `make test` for test validation
186+
- [ ] Run `make security` for security scans
187+
- [ ] Update Swagger docs with `make swag-init` if API changed
188+
- [ ] Update relevant documentation in [docs/](mdc:docs)
189+
190+
### Reference Integration with Development Workflow
191+
Commit messages should align with:
192+
- Issue tracking (reference issue numbers)
193+
- Pull request descriptions (from [.github/PULL_REQUEST_TEMPLATE.md](mdc:.github/PULL_REQUEST_TEMPLATE.md))
194+
- Security policy guidelines (from [SECURITY.md](mdc:SECURITY.md))
195+
- Contributing guidelines (from [CONTRIBUTING.md](mdc:CONTRIBUTING.md))
196+
197+
### Automated Checks
198+
Consider implementing commit message validation:
199+
```bash
200+
# .git/hooks/commit-msg
201+
#!/bin/sh
202+
# Validate commit message format
203+
if ! grep -qE "^(feat|fix|docs|style|refactor|test|chore|security|deps)(\(.+\))?: .+" "$1"; then
204+
echo "Invalid commit message format!"
205+
echo "Use: <type>(<scope>): <description>"
206+
exit 1
207+
fi
208+
```
209+
210+
### Release Notes Generation
211+
Properly formatted commits enable automatic release note generation:
212+
- `feat` commits become "Features"
213+
- `fix` commits become "Bug Fixes"
214+
- `security` commits become "Security Updates"
215+
- `BREAKING CHANGE` commits get special highlighting
216+
217+
## Special Considerations for Authentication API
218+
219+
### Security-First Messaging
220+
- Always mention security implications in auth-related commits
221+
- Reference vulnerability IDs when applicable (CVE numbers)
222+
- Include impact assessment for security changes
223+
224+
### Compliance and Audit
225+
- Use descriptive commits for audit trail clarity
226+
- Reference security standards when applicable (OWASP, NIST)
227+
- Include performance impacts for auth-related changes
228+
229+
### API Versioning
230+
When API changes affect client integration:
231+
```
232+
feat(api): add v2 login endpoint with enhanced security
233+
234+
- Implement new /v2/auth/login endpoint
235+
- Maintain backward compatibility with /v1/auth/login
236+
- Add comprehensive rate limiting and CAPTCHA support
237+
- Include detailed migration documentation
238+
239+
Deprecation notice: v1 endpoint will be removed in 6 months
240+
Migration guide: docs/api-migration-v1-to-v2.md
241+
```
242+

0 commit comments

Comments
 (0)