Skip to content

Feat/hmac signature validation#201

Open
Mosas2000 wants to merge 5 commits intoPulsefy:mainfrom
Mosas2000:feat/hmac-signature-validation
Open

Feat/hmac signature validation#201
Mosas2000 wants to merge 5 commits intoPulsefy:mainfrom
Mosas2000:feat/hmac-signature-validation

Conversation

@Mosas2000
Copy link
Copy Markdown

Adds HMAC-SHA256 signature validation to secure inter-service communication between the NestJS backend and Python AI service.

Changes
FastAPI middleware validates X-HMAC-Signature and X-HMAC-Timestamp headers
NestJS utility generates signatures for outgoing requests
Requests with missing/invalid signatures return 403 Forbidden
5-minute timestamp window prevents replay attacks
Configuration
Set HMAC_SECRET_KEY in both services (generate with openssl rand -hex 32).

Closes #158

- Add HMACAuthMiddleware to verify HMAC-SHA256 signatures on requests
- Validate timestamp to prevent replay attacks (5 minute window)
- Exclude health check and docs endpoints from auth
- Add HMAC_SECRET_KEY to config and .env.example
- Add generateHmacSignature utility function
- Include HMAC_SECRET_KEY in environment config
- Test excluded paths bypass authentication
- Test missing/invalid signature handling
- Test timestamp expiration validation
- Test valid signature acceptance
- Document signature generation algorithm
- Add NestJS integration example
- List validation rules and error responses
@drips-wave
Copy link
Copy Markdown

drips-wave bot commented Mar 25, 2026

@Mosas2000 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Cedarich
Copy link
Copy Markdown
Contributor

Please fix failing workflow

Fixes CI import error by using relative imports in package
@Mosas2000
Copy link
Copy Markdown
Author

Done, fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Secure HMAC Signature Validation for Inter-Service Calls

2 participants