Repository navigation
Closed
Milestone
Description
Current Implementation
The strict-mode currently operates at a global level through the strictHeaders flag in the server configuration. This affects how all headers are validated:
Current Behavior
- When
strictHeaders: true:- Invalid headers trigger a BadRequestException
- Empty header values are rejected
- Malformed headers (e.g., invalid max-age in Strict-Transport-Security) cause request failures
- When
strictHeaders: false:- Invalid headers return null
- Validation errors are suppressed
- Applications must handle potentially invalid headers
Problems with Current Approach
- All-or-nothing configuration doesn't allow for granular control
- Can't mix strict and lenient validation for different parts of the application
- No way to override strictness for specific endpoints or header types
Proposed Changes
Add middleware for dynamic strict mode control:
Acceptance Criteria
- Provide middleware for dynamic strict mode control
- Add clear documentation for strict mode configuration
- Include migration guide for existing applications
Impact Assessment
Affected Components
- Server configuration
- Header validation system
- Request processing pipeline
- Middleware chain
Examples
Current Implementation
// Current: Global strict mode
final server = await RelicServer.create(
strictHeaders: true, // Affects all headers
);Proposed Implementation
const Pipeline().addMiddleware(strictHeadersMiddleware(
headers: [Headers.authorization],
).addHandler(handler));This refactoring will provide more flexibility while maintaining security where needed and improving developer experience by allowing precise control over header validation.
Metadata
Metadata
Assignees
Labels
No labels
Type
Projects
- StatusShow more project fieldsDone 🚀
- StatusShow more project fieldsLater 🥳
Activity
nielsenko commentedon Aug 5, 2025
This is mostly done, but the strict mode flag should die (headers are explicitly validated when accessed via typed
HeaderAccessor), and the test structure could do with overhaul.Also, we should add convenience middleware that force a subset of headers to be validated up-front..