Description: User-provided metadata (memos, descriptions) should be sanitized to prevent injection or logging issues.
- memo - Transaction memos (donation metadata)
- donor - Donor identifier (donation metadata)
- recipient - Recipient identifier (donation metadata)
- label - Wallet label (wallet metadata)
- ownerName - Wallet owner name (wallet metadata)
- Sanitization applied in donation routes before business logic
- Sanitization applied in wallet routes before business logic
- Centralized sanitization utility created
- Field-specific sanitization functions implemented
- Logging utility updated to sanitize all data
- Recursive sanitization for objects and arrays
- Control characters removed from log output
- ANSI escape codes removed from log output
- Null bytes removed from all user input
- Control characters removed from all user input
- Newlines removed to prevent log injection
- ANSI escape sequences removed
- Sanitized data stored in database
- Sanitized data logged to console
-
src/utils/sanitizer.js- Core sanitization utility -
tests/sanitizer.test.js- Unit tests -
tests/sanitization-integration.test.js- Integration tests -
docs/security/INPUT_SANITIZATION.md- Full documentation -
docs/security/SANITIZATION_QUICK_REFERENCE.md- Quick reference -
SANITIZATION_IMPLEMENTATION_SUMMARY.md- Implementation summary
-
src/utils/log.js- Added sanitization to logging -
src/utils/memoValidator.js- Uses centralized sanitization -
src/routes/wallet.js- Sanitizes label and ownerName -
src/routes/donation.js- Sanitizes donor, recipient, memo
- Log Injection - Newlines and control chars removed
- Null Byte Injection - Null bytes stripped
- ANSI Escape Code Injection - ANSI codes removed
- XSS (Partial) - Special chars removed from identifiers
- Test basic sanitization (whitespace, null bytes)
- Test control character removal
- Test ANSI escape sequence removal
- Test length truncation
- Test character restriction modes
- Test nested object/array sanitization
- Test security attack scenarios
- Test edge cases (null, undefined, non-strings)
- Test donation endpoint sanitization
- Test wallet endpoint sanitization
- Test log injection prevention
- Test XSS prevention
- Test null byte injection prevention
- Run unit tests:
npm test -- sanitizer.test.js - Run integration tests:
npm test -- sanitization-integration.test.js - Run full test suite:
npm test - Verify all tests pass
- Full implementation documentation created
- Quick reference guide created
- Code comments added to all functions
- Usage examples provided
- Security considerations documented
- Maintenance guide included
- No syntax errors (verified with getDiagnostics)
- Consistent code style
- JSDoc comments for all functions
- Error handling for edge cases
- Backward compatible
-
sanitizeText()- General text sanitization -
sanitizeMemo()- Transaction memo (28 bytes) -
sanitizeLabel()- Wallet label (100 chars) -
sanitizeName()- Owner name (100 chars) -
sanitizeIdentifier()- Donor/recipient ID (strict) -
sanitizeForLogging()- Log data (recursive) -
sanitizeRequestBody()- Batch sanitization
- POST /donations - Sanitizes memo, donor, recipient
- POST /donations/send - Sanitizes memo
- POST /wallets - Sanitizes label, ownerName
- PATCH /wallets/:id - Sanitizes label, ownerName
- All log.info() calls - Automatic sanitization
- All log.warn() calls - Automatic sanitization
- All log.error() calls - Automatic sanitization
- Null bytes (
\x00) - Control characters (
\x01-\x1F,\x7F) - ANSI escape sequences (
\x1B[...) - Leading/trailing whitespace
- Newlines (configurable)
- Special characters (configurable)
-
maxLength- Character limit -
allowNewlines- Keep or remove newlines -
allowSpecialChars- Keep or remove special chars
- Code review completed
- All tests passing
- Documentation reviewed
- Staging deployment
- Smoke testing in staging
- Production deployment
- Monitor logs for issues
- Update API documentation (if needed)
-
Test Memo Sanitization
curl -X POST http://localhost:3000/donations \ -H "Content-Type: application/json" \ -H "X-API-Key: your-key" \ -H "X-Idempotency-Key: test-123" \ -d '{"amount": 100, "recipient": "GXXX...", "memo": "test\nmemo\x00"}'
- Verify memo is sanitized in response
- Verify memo is sanitized in logs
- Verify memo is sanitized in database
-
Test Wallet Label Sanitization
curl -X POST http://localhost:3000/wallets \ -H "Content-Type: application/json" \ -d '{"address": "GXXX...", "label": "My\nWallet\x00"}'
- Verify label is sanitized in response
- Verify label is sanitized in logs
- Verify label is sanitized in database
-
Test Log Injection Prevention
# Check logs for injected content tail -f logs/app.log- Verify no fake log entries created
- Verify control characters removed
- Verify ANSI codes removed
- Run
npm test -- sanitizer.test.js - Run
npm test -- sanitization-integration.test.js - Verify 100% of sanitization tests pass
- Full Documentation:
docs/security/INPUT_SANITIZATION.md - Quick Reference:
docs/security/SANITIZATION_QUICK_REFERENCE.md - Implementation Summary:
SANITIZATION_IMPLEMENTATION_SUMMARY.md - Unit Tests:
tests/sanitizer.test.js - Integration Tests:
tests/sanitization-integration.test.js
- All user-controlled fields identified
- Sanitization implemented before processing
- Sanitization implemented before logging
- No unsafe strings stored or logged
- Comprehensive tests created
- Documentation completed
- Code quality verified
Status: COMPLETE ✅
All acceptance criteria have been met. The implementation is ready for testing and deployment.