Secure Request & Response Logging Middleware (ASP.NET Core)
Design and implement a custom ASP.NET Core middleware that logs incoming HTTP requests and outgoing responses while masking sensitive data to ensure security and regulatory compliance.
Key Requirements:
- Log request details, including:
- HTTP method, endpoint, headers, and payload
- Log response details, including:
- Status code, execution time, and response body
- Automatically mask or redact sensitive fields such as:
- Passwords, tokens, API keys, PII, and authorization headers
- Ensure minimal performance impact using:
- Stream buffering and async processing
- Make the middleware:
- Configurable (enable/disable logging, log levels, masked fields)
- Reusable and dependency-injection friendly
- Follow best practices for:
- Secure logging
- Clean architecture
- Compliance (GDPR, SOC 2, ISO 27001)
Expected Outcome:
- A production-ready middleware component
- Centralized, secure logging without exposing sensitive data
- Clear extensibility for enterprise-grade APIs
Ideal For:
- Enterprise ASP.NET Core APIs
- Security-conscious applications
- Technical interviews and backend architecture demonstrations
